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. Userelabel()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;
Noneusesextended=Truefor 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_freqis 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_freqis 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.Nonelabels nothing (userelabel()).threshold (float) – Minimum predicted probability for excluding an artifact component.
exclude_labels (list of str | None) – Labels treated as artifacts;
NoneusesARTIFACT_LABELSfor the labeler (both labelers’ artifact labels whenlabeler=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
excludeholds the excluded components.- Type:
- proba_#
Predicted probability of each label (1.0 for manual labels).
- Type:
ndarray
- qc_#
rank,n_components,excluded,label_countsandexcluded_variance(fraction of the fitted data’s variance).- Type:
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"(needsinst):mne.preprocessing.ICA.plot_properties()of the excluded components (the first five if none are excluded); a list of figures."overlay"(needsinst): 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
fitmethod.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
transformmethod.transform(inst, *[, copy])Apply the fitted step to the data.
Attributes
Data types the step accepts.
adds_annotationsWhether the step may add
BAD_annotations (existing ones are kept).changes_channelsWhether the step may add, drop or reorder channels.
changes_timesWhether the step may change the time axis (e.g. resampling, cropping).
drops_epochsWhether the step may drop epochs (e.g. artifact rejection).
kind -> whether it needs data (
inst).returnsData type the step returns;
Nonemeans the same type as its input.systemsAcquisition systems the step applies to;
Nonemeans 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_andexclude_updated.- Return type: