meeg_utils.steps.ByChannelType#

class meeg_utils.steps.ByChannelType(branches, *, on_missing='raise')[source]#

Process channel types with separate steps, like scikit-learn’s ColumnTransformer.

Each branch selects some channel types and runs its own steps on a copy holding only those channels; the results are written back, so all channels stay in place. Typical use: MEG and EEG recorded together, with a different ICA or bad-channel method for each.

Parameters:
  • branches (dict) – Channel group ("meg", "mag", "grad", "eeg", "eog", …) mapped to a step or a list of (name, step). Groups must not overlap. "meg" includes CTF reference sensors.

  • on_missing ({"raise", "ignore"}) – What to do when the data have no channels of a branch.

pipelines_#

Group mapped to the fitted Pipeline of the branch (it shares its step objects with branches).

Type:

dict

qc_#

Group mapped to the qc_ of its pipeline ({step: metrics}).

Type:

dict

Notes

Steps in a branch must keep the channels and the time axis (no resampling, epoching or epoch rejection). What the branch changes is carried back: the data, new annotations (e.g. from BadSegments), info["bads"] and the channel descriptions of its channels (e.g. CTF compensation), projectors added or removed, the EEG reference flag, and, from a MEG branch, the device-to-head transform and the Maxwell-filtering history. info["highpass"] / info["lowpass"] describe all channels and are left unchanged, as MNE does when filtering a subset of channels.

Parameters of branch steps are <group>__<param> (a single step) or <group>__<step>__<param>, e.g. pipe.set_params(by_type__eeg__ica__n_components=15).

Figures (plot()) are those of the branch steps, named "<group>/<step>/<kind>".

Examples

>>> from meeg_utils import steps as S
>>> step = S.ByChannelType({
...     "meg": [("ica", S.ICA(picks="meg", labeler="megnet"))],
...     "eeg": [("bads", S.BadChannels("prep")), ("ica", S.ICA(picks="eeg"))],
... })
__init__(branches, *, on_missing='raise')[source]#

Methods

__init__(branches, *[, on_missing])

fit(inst[, y, system])

Learn the step's state from the data.

fit_transform(inst[, y, system, copy])

Fit every branch and return the processed data, running each branch once.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters, including those of the branch steps.

plot([kind, inst])

Draw the figures of the branch steps.

set_fit_request(*[, inst, system])

Configure whether metadata should be requested to be passed to the fit method.

set_params(**params)

Set parameters, including <group>__[<step>__]<param> of branch steps.

set_transform_request(*[, copy, inst])

Configure whether metadata should be requested to be passed to the transform method.

transform(inst, *[, copy])

Apply the fitted step to the data.

Attributes

accepts

Data types the step accepts.

adds_annotations

Whether the step may add BAD_ annotations (existing ones are kept).

changes_channels

Whether the step may add, drop or reorder channels.

changes_times

Whether the step may change the time axis (e.g. resampling, cropping).

drops_epochs

Whether the step may drop epochs (e.g. artifact rejection).

plot_kinds

Figures of the branch steps, as "<group>/<step>/<kind>".

returns

Data type the step returns; None means the same type as its input.

systems

Acquisition systems the step applies to; None means all systems.

accepts: ClassVar[tuple[type, ...]] = (<class 'mne.io.base.BaseRaw'>, <class 'mne.epochs.BaseEpochs'>)#

Data types the step accepts.

adds_annotations: ClassVar[bool] = True#

Whether the step may add BAD_ annotations (existing ones are kept).

fit_transform(inst, y=None, *, system=None, copy=True)[source]#

Fit every branch and return the processed data, running each branch once.

Parameters:
  • inst (Raw | Epochs) – The data.

  • y (None) – Ignored; present for scikit-learn API compatibility.

  • system (str | None) – Acquisition system of the data; detected if None.

  • copy (bool) – Whether to leave inst untouched.

Returns:

The processed data.

Return type:

Raw | Epochs

get_params(deep=True)[source]#

Get parameters, including those of the branch steps.

Parameters:

deep (bool) – If True, also return <group>__<param> (single step) or <group>__<step>__<param>.

Returns:

Parameter names mapped to their values.

Return type:

dict

set_params(**params)[source]#

Set parameters, including <group>__[<step>__]<param> of branch steps.

Parameters:

**params (Any) – branches, on_missing or nested branch parameters.

Returns:

self – The step.

Return type:

ByChannelType

__sklearn_clone__()[source]#

Return an unfitted copy with cloned branch steps.

property plot_kinds: dict[str, bool]#

Figures of the branch steps, as "<group>/<step>/<kind>".

plot(kind=None, *, inst=None, **kwargs)[source]#

Draw the figures of the branch steps.

Parameters:
  • kind (str | None) – "<group>/<step>/<kind>", or None for every figure the inputs allow.

  • inst (Raw | Epochs | None) – Data for the figures that need it; each branch replays its steps on its own channels, so every step plots the data it received.

  • **kwargs (Any) – Passed to the plotting method of kind.

Returns:

Kind mapped to its figure.

Return type:

dict