Router

class gpype.backend.flow.router.Router[source]

Bases: IONode

Channel routing and selection node for flexible data flow management.

Provides channel selection and routing capabilities for BCI data pipelines. Allows selecting specific channels from multiple input ports and routing them to multiple output ports. Supports both simple channel selection (index lists) and complex multi-port routing (dictionary mapping).

ALL = [-1]

Special constant for selecting all available channels

class Configuration[source]

Bases: Configuration

Configuration class for Router parameters.

class Keys[source]

Bases: Keys

Configuration key constants for the Router.

INPUT_CHANNELS = 'input_channels'

Input channels configuration key

OUTPUT_CHANNELS = 'output_channels'

Output channels configuration key

__init__(input_channels=None, output_channels=None, **kwargs)[source]

Initialize the Router node with channel selection configurations.

Parameters:
  • input_channels (Union[list, dict]) – Specification for input channel selection. Can be None (all channels), list (channel indices), or dict (port name to channel indices mapping).

  • output_channels (Union[list, dict]) – Specification for output channel selection. Same format as input_channels.

  • **kwargs – Additional configuration parameters passed to IONode.

Raises:

ValueError – If input_channels or output_channels is empty.

setup(data, port_context_in)[source]

Set up the Router node and build the internal channel mapping.

Creates the internal routing map that defines which input channels are connected to which output channels. Validates that all input ports have compatible sampling rates, frame sizes, and data types.

Parameters:
  • data (dict[str, ndarray]) – Initial data dictionary for port configuration.

  • port_context_in (dict[str, dict]) – Input port context information with channel counts, sampling rates, frame sizes, and data types.

Return type:

dict[str, dict]

Returns:

Output port context with routing information and updated channel counts for each output port.

Raises:

ValueError – If input ports have incompatible parameters.

step(data)[source]

Process one frame of data by routing channels according to mapping.

Routes channels from input ports to output ports based on the channel mapping established during setup. Each output port receives data from its configured subset of input channels.

For mixed SYNC/ASYNC inputs: - ASYNC data is buffered when it arrives - Output is only produced when SYNC data is available - Buffered ASYNC data is used when SYNC data triggers output

Parameters:

data (dict[str, ndarray]) – Dictionary containing input data arrays for each port. Keys are port names, values are arrays with shape (frame_size, channel_count).

Return type:

dict[str, ndarray]

Returns:

Dictionary containing output data arrays for each output port. Keys are output port names, values are arrays with shape (frame_size, selected_channel_count). Returns empty dict if no SYNC data is available.