meeg_utils.steps.ICA#

class meeg_utils.steps.ICA(n_components=0.99, *, picks='auto', method='infomax', fit_params=None, fit_l_freq=1.0, fit_h_freq=100.0, labeler='auto', threshold=0.8, exclude_labels=None, max_iter='auto', random_state=42, reject_by_annotation=True, decim=None)[source]#

Decompose the data with ICA, label components and remove artifacts.

ICA is fitted on a high-pass filtered copy of the data (1 Hz by default, which stabilises the decomposition) and the selected components are then removed from the data as they are, so the step does not change the data’s own filtering.

Components are excluded only when the labeler’s predicted probability for an artifact class reaches threshold; the arg-max label alone is not enough. Use relabel() after fitting to apply manual labels.

Parameters:
  • n_components (int | float) – Number of components, or the fraction of variance to keep (default 0.99). An integer above the data rank (reduced by average referencing and interpolated channels) is lowered to the rank.

  • picks ({"auto", "eeg", "meg"}) – Modality to decompose. "auto" uses the only modality present and raises for MEG+EEG recordings: use one ICA step per modality.

  • method (str) – ICA algorithm (default extended Infomax, which ICLabel was trained on).

  • fit_params (dict | None) – Algorithm parameters; None uses extended=True for Infomax and Picard.

  • fit_l_freq (float | None) – Band-pass applied to the copy ICA is fitted on. The default 1-100 Hz matches what ICLabel and MEGnet expect; fit_h_freq is dropped if it is not below Nyquist.

  • fit_h_freq (float | None) – Band-pass applied to the copy ICA is fitted on. The default 1-100 Hz matches what ICLabel and MEGnet expect; fit_h_freq is dropped if it is not below Nyquist.

  • labeler ({"auto", "iclabel", "megnet"} | None) – Automatic labeling via mne-icalabel; "auto" uses ICLabel for EEG and MEGnet for MEG. None labels nothing (use relabel()).

  • threshold (float) – Minimum predicted probability for excluding an artifact component.

  • exclude_labels (list of str | None) – Labels treated as artifacts; None uses ARTIFACT_LABELS for the labeler (both labelers’ artifact labels when labeler=None).

  • max_iter (int | "auto") – Maximum iterations.

  • random_state (int | None) – Seed.

  • reject_by_annotation (bool) – Ignore BAD_ annotated segments when fitting.

  • decim (int | None) – Use every decim-th sample when fitting.

ica_#

The fitted ICA; its exclude holds the excluded components.

Type:

mne.preprocessing.ICA

labels_#

Label of each component ("unlabeled" without a labeler).

Type:

list of str

proba_#

Predicted probability of each label (1.0 for manual labels).

Type:

ndarray

exclude_#

Excluded components.

Type:

list of int

qc_#

rank, n_components, excluded, label_counts and excluded_variance (fraction of the fitted data’s variance).

Type:

dict

Notes

Figures (plot()):

  • "components": component topographies titled with label and probability, excluded components in red.

  • "labels": predicted probability of each component’s label, with the exclusion threshold.

  • "properties" (needs inst): mne.preprocessing.ICA.plot_properties() of the excluded components (the first five if none are excluded); a list of figures.

  • "overlay" (needs inst): signals before and after removing the excluded components (mne.preprocessing.ICA.plot_overlay()).

__init__(n_components=0.99, *, picks='auto', method='infomax', fit_params=None, fit_l_freq=1.0, fit_h_freq=100.0, labeler='auto', threshold=0.8, exclude_labels=None, max_iter='auto', random_state=42, reject_by_annotation=True, decim=None)[source]#

Methods

__init__([n_components, picks, method, ...])

fit(inst[, y, system])

Learn the step's state from the data.

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

Fit the step on the data and transform the same data.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

plot([kind, inst])

Draw quality-control figures.

relabel(labels[, inst])

Override component labels, e.g. after visual inspection.

set_fit_request(*[, inst, system])

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

set_params(**params)

Set the parameters of this estimator.

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

kind -> whether it needs data (inst).

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'>,)#

Data types the step accepts.

plot_kinds: ClassVar[dict[str, bool]] = {'components': False, 'labels': False, 'overlay': True, 'properties': True}#

kind -> whether it needs data (inst). Each kind is drawn by a _plot_<kind>(inst, **kwargs) method.

Type:

Figures the object can draw once fitted

relabel(labels, inst=None)[source]#

Override component labels, e.g. after visual inspection.

Manually labeled components get probability 1.0, so they are excluded if (and only if) their label is an artifact label.

Parameters:
  • labels (dict of int to str) – Component index mapped to its label.

  • inst (Raw | None) – Data to recompute qc_["excluded_variance"] on; without it the metric is cleared, as it no longer matches the excluded components.

Returns:

self – The step, with labels_, proba_ and exclude_ updated.

Return type:

ICA