ChannelSelector

class gpype.backend.flow.channel_selector.ChannelSelector[source]

Bases: IONode

Selects channels by name, by role, or by position.

Router addresses channels by position, which is what you want when wiring a pipeline and not what you want when a montage changes. This addresses them by what they are:

ChannelSelector(labels=[“C3”, “Cz”, “C4”]) ChannelSelector(roles=Constants.ChannelRoles.SIGNAL) ChannelSelector(indices=[0, 2, 4], exclude=True)

Selecting by role is the device-agnostic form: every amplifier appends different extras, and asking for the signal channels is the same request on all of them.

Every failure is raised at setup, i.e. when the pipeline starts and before a file or a socket exists. Skipping a channel that could not be found would change the channel count silently, everything downstream would accept it, and the operator would find out on analysis day that an electrode is missing from the whole recording.

ONE_OF = (('labels', 'roles', 'indices'),)

Exactly one of these must be given – the constructor refuses any other count. Declared because no per-parameter field can say it: read one at a time they all look merely optional, so a form built from the catalog would offer three optional fields and produce a document that always fails.

class Configuration[source]

Bases: Configuration

Configuration class for ChannelSelector parameters.

class Keys[source]

Bases: Keys

Configuration keys for ChannelSelector settings.

EXCLUDE = 'exclude'

Whether the selection is inverted

class OptionalKeys[source]

Bases: OptionalKeys

Optional configuration keys.

LABELS = 'labels'

Channel labels to select

ROLES = 'roles'

Channel roles to select

INDICES = 'indices'

Channel indices to select

__init__(labels=None, roles=None, indices=None, exclude=False, **kwargs)[source]

Initialize the channel selector.

Parameters:
  • labels (Optional[list]) – Channel names to select. Also reorders: the output follows the order given.

  • roles (Union[str, list, None]) – One role, or several, from Constants.ChannelRoles.

  • indices (Optional[list]) – Channel positions to select. Also reorders.

  • exclude (bool) – Invert the selection. Survivors keep input order.

  • **kwargs – Additional arguments for the parent IONode.

Raises:

ValueError – If not exactly one criterion is given, if it is empty, or if it repeats an entry.

setup(data, port_context_in)[source]

Resolve the selection and describe the output channels.

Parameters:
Return type:

dict[str, dict]

Returns:

Output port contexts.

Raises:

ValueError – If the selection resolves to no channels at all.

step(data)[source]

Emit the selected channels.

Parameters:

data (dict[str, ndarray]) – Input frame.

Return type:

dict[str, ndarray]

Returns:

The selected columns, in selection order.