meeg_utils.Pipeline#
- class meeg_utils.Pipeline(steps, *, copy=True)[source]#
A sequence of named processing steps.
Follows scikit-learn conventions:
fit(),transform()andfit_transform(); nested parameters (pipe.set_params(ica__threshold=0.9));sklearn.base.clone(); slicing (pipe[:3]).Unlike
sklearn.pipeline.Pipeline, every step is fitted and transformed in sequence (each step learns from the output of the previous one), steps may change the data type (e.g. Raw -> Epochs), and side outputs are collected on the fitted pipeline.- Parameters:
- provenance_#
Software versions, detected system and, for each step, its class, parameters, run time and the warnings it raised.
- Type:
Methods
__init__(steps, *[, copy])fit(inst[, y])Fit every step in sequence.
fit_transform(inst[, y])Fit every step in sequence and return the fully processed data.
from_dict(config)Build a pipeline from
to_dict()output.from_yaml(fname)Read a pipeline configuration from a YAML file.
get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters, including those of each step as
<step>__<param>.insert_after(after, name, step)Insert a step after the step called
after.insert_before(before, name, step)Insert a step before the step called
before.plot(*[, inst])Draw the quality-control figures of every fitted step.
preset(name, **kwargs)Build a ready-made pipeline, see
meeg_utils.presets.remove(name)Remove the step called
name.replace(name, step)Replace the step called
name.set_fit_request(*[, inst])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set parameters;
<step>=new_stepreplaces a step.set_transform_request(*[, inst])Configure whether metadata should be requested to be passed to the
transformmethod.to_dict()Return the pipeline configuration as plain, YAML-safe data.
to_yaml(fname)Write the pipeline configuration to a YAML file.
transform(inst)Apply every fitted step in sequence, without refitting.
Attributes
The steps, keyed by name.
- fit(inst, y=None)[source]#
Fit every step in sequence.
Each step except the last is fitted and then transforms the data passed to the next step; the last step is only fitted.
- Parameters:
inst (Raw | Epochs | Evoked | str | Path | BIDSPath) – The data, or a recording to read with
meeg_utils.io.read().y (None) – Ignored; present for scikit-learn API compatibility.
- Returns:
self – The fitted pipeline.
- Return type:
- fit_transform(inst, y=None)[source]#
Fit every step in sequence and return the fully processed data.
- Parameters:
inst (Raw | Epochs | Evoked | str | Path | BIDSPath) – The data, or a recording to read with
meeg_utils.io.read().y (None) – Ignored; present for scikit-learn API compatibility.
- Returns:
The processed data.
- Return type:
Raw | Epochs | Evoked
- transform(inst)[source]#
Apply every fitted step in sequence, without refitting.
- Parameters:
inst (Raw | Epochs | Evoked | str | Path | BIDSPath) – The data, or a recording to read with
meeg_utils.io.read(). Must come from the same acquisition system as the data the pipeline was fitted on.- Returns:
The processed data.
- Return type:
Raw | Epochs | Evoked
- plot(*, inst=None)[source]#
Draw the quality-control figures of every fitted step.
- Parameters:
inst (Raw | Epochs | Evoked | str | Path | BIDSPath | None) – Data for the figures that need it. It is run through the fitted steps (
transform, no refitting), so each step plots the data as that step received it. Without it, only figures that need no data are drawn, from what the steps recorded when they last transformed data (afterfit, the last step has not).- Returns:
Step name mapped to that step’s
{kind: Figure}; steps without figures are left out.- Return type:
- __getitem__(key)[source]#
Return a step by position or name, or a sub-pipeline for a slice.
A sub-pipeline shares its step objects (and their fitted state) with this pipeline.
- to_dict()[source]#
Return the pipeline configuration as plain, YAML-safe data.
- Returns:
The configuration; see
from_dict().- Return type:
- classmethod preset(name, **kwargs)[source]#
Build a ready-made pipeline, see
meeg_utils.presets.- Parameters:
name (str) – Preset name (e.g.
"had-meeg");meeg_utils.presets.available()lists them.**kwargs (Any) – Preset options, e.g.
datatype="meg".
- Returns:
A new, unfitted pipeline; change parameters with
set_params.- Return type:
Examples
>>> pipe = Pipeline.preset("had-meeg", datatype="eeg") >>> pipe.set_params(ica__threshold=0.9) Pipeline(...)
- classmethod from_dict(config)[source]#
Build a pipeline from
to_dict()output.Loading a configuration imports the modules that define its steps, so only load configurations you trust.