tnmf.utils.signals

Provides functionality to generate certain 1-D and 2-D test signals.

Module Contents

Functions

generate_pulse(shape: str, length: int = 20) → numpy.ndarray

Generates a short signal pulse of specified shape and length.

generate_pulse_train(symbols: Optional[List[str]] = None, pulse_length: int = 20, n_pulses: int = 5) → Tuple[numpy.ndarray, numpy.ndarray]

Generates a signal composed of a random sequence of multi-channel pulses.

generate_patch(pattern: str, size: int = 10, color: Optional[str] = None) → numpy.ndarray

Generates a square image patch showing a certain pattern of specified size and color.

generate_block_image(symbols: Optional[List[str]] = None, symbol_size: int = 10, n_symbols: int = 10) → Tuple[numpy.ndarray, numpy.ndarray]

Generates a block-structured image composed of several image patches, each containing a single random pattern.

tnmf.utils.signals.generate_pulse(shape: str, length: int = 20)numpy.ndarray

Generates a short signal pulse of specified shape and length.

Parameters
  • shape ('n' | '-' | '^' | 'v' | '_') – Shape of the pulse.

  • length (int) – Length of the pulse.

Returns

pulse – The signal pulse as a 1-D array.

Return type

np.ndarray

tnmf.utils.signals.generate_pulse_train(symbols: Optional[List[str]] = None, pulse_length: int = 20, n_pulses: int = 5)Tuple[numpy.ndarray, numpy.ndarray]

Generates a signal composed of a random sequence of multi-channel pulses.

Parameters
  • symbols (List[str], optional) – A list of symbols (= multi-channel pulse shapes) specified via strings that are used as a dictionary to generate the signal. If ‘None’, the following three-channel symbols are used: [‘nnn’, ‘—’, ‘^^^’, ‘vvv’, ‘___’]. See generate_pulse for an overview of all available pulse shapes.

  • pulse_length (int) – The length of each individual pulse.

  • n_pulses (int) – The total number of pulses to be sequenced.

Returns

  • signal (np.ndarray) – A 2-D array of shape (n_channels, n_pulses * pulse_length) containing the signal.

  • W (np.ndarray) – A 3-D array of shape (n_symbols, n_channels, pulse_length) representing the pulse shape dictionary.

tnmf.utils.signals.generate_patch(pattern: str, size: int = 10, color: Optional[str] = None)numpy.ndarray

Generates a square image patch showing a certain pattern of specified size and color.

Parameters
  • pattern ('x' | '+' | 's') – Pattern shown in the image patch.

  • size (int) – Size of both dimensions of the image patch.

  • color ('r' | 'g' | 'b' | 'y' | 'm' | 'c' | 'w' , optional) – Color of the pattern. If ‘None’, the generated image patch will be grayscale.

Returns

patch – The image patch as a 3-D array, where the first dimension indexes the color channel.

Return type

np.ndarray

tnmf.utils.signals.generate_block_image(symbols: Optional[List[str]] = None, symbol_size: int = 10, n_symbols: int = 10)Tuple[numpy.ndarray, numpy.ndarray]

Generates a block-structured image composed of several image patches, each containing a single random pattern.

Parameters
  • symbols (List[str], optional) – A list of symbols used as a dictionary to generate the image. Each symbol is either a one-character or two-character string, where the first character specifies the symbol shape and the optional second character specifies the symbol color. For example: ‘x’ creates a grayscale cross-shaped patch while ‘sr’ creates a red square- shaped patch. If ‘None’, a certain default set of colored patches will be used as dictionary. See generate_patch for an overview of all available patch shapes and color options.

  • symbol_size (int) – The size of both dimensions of each individual image patch.

  • n_symbols (int) – The number of image patches to be stacked both horizontally and vertically.

Returns

  • image (np.ndarray) – A 3-D array of shape (3, n_symbols * symbol_size, n_symbols * symbol_size) containing the image.

  • W (np.ndarray) – A 3-D array of shape (3, symbols_size, symbol_size) containing the image patch dictionary.