pybemobil.preproc.compute_ica#
- pybemobil.preproc.compute_ica(raw, filter_bands_ica=(1.75, 100.0), downsample_ica=250, thresh=-1, rng_seed=None, exclude_labels=None, include_labels=None, ica_method='jamica', jamica_kwargs=None, reject_by_annotation=True)[source]#
Fit ICA on a filtered copy of raw and label components with ICLabel.
- Parameters:
- raw
mne.io.Raw Continuous EEG recording (must contain EEG channels).
- filter_bands_ica
tupleoffloat (l_freq, h_freq)for the ICA-specific bandpass filter. The default(1.75, 100.0)uses BeMoBIL’s 1.75 Hz AMICA high-pass and the 100 Hz low-pass ICLabel expects.EEGPreprocessoruses(1.75, None)because its data is already low-passed at 100 Hz.- downsample_ica
float Target sampling rate for ICA fitting (anti-aliasing applied automatically). Skipped when the recording is already at or below this rate.
- thresh
float ICLabel decision rule.
-1(default) is popularity-vote mode, as in BeMoBIL (iclabel_threshold=-1): each IC is assigned to the class with the highest probability and excluded if that class is not kept. A value in[0, 1]is probability-threshold mode: an IC is excluded only when its winning class is one to remove and that class’s probability is at leastthresh; uncertain ICs are kept.- rng_seed
int|None Random seed passed to
mne.preprocessing.ICAfor reproducibility.- exclude_labels
listofstr|None ICLabel classes to exclude (e.g.
["eye blink", "muscle artifact"]). Mutually exclusive with include_labels.- include_labels
listofstr|None ICLabel classes to keep; all other classes are excluded (e.g.
["brain", "other"]). If neither this nor exclude_labels is given, all classes except"eye blink"are kept, as inEEGPreprocessorand BeMoBIL. Valid names are"brain","muscle artifact","eye blink","heart beat","line noise","channel noise"and"other". Mutually exclusive with exclude_labels.- ica_method
str ICA algorithm to use.
"jamica"(default) uses jamica, a JAX-accelerated reimplementation of Adaptive Mixture ICA (AMICA), viajamica.fit_ica().fit_icareplicates MNE’s whitening/PCA pipeline internally and returns a standardmne.preprocessing.ICAobject directly. Any other string is passed directly as themethodargument tomne.preprocessing.ICA(e.g."picard","fastica"). If"jamica"is requested but thejamicapackage is not installed, the method falls back to"picard"with an extended-infomax fit and a warning.- jamica_kwargs
dict|None Extra keyword arguments forwarded to
jamica.fit_ica()whenica_method="jamica"(e.g.{"max_iter": 2000, "num_mix": 3}). AMICA’s likelihood-based sample rejection is on by default, matching the MATLAB BeMoBIL pipeline:fit_paramsdefaults topybemobil.preproc.utils.DEFAULT_JAMICA_FIT_PARAMS({"do_reject": True, "rejsig": 3.0, "numrej": 10}) and anyfit_paramsyou pass are merged over it key by key. Pass{"fit_params": {"do_reject": False}}to disable rejection. Ignored when a non-jamica method is used.- reject_by_annotationbool
If
True(default), 1 s epochs that overlapBAD_*annotations are left out of the ICA fit and of ICLabel.
- raw
- Returns:
- ica
mne.preprocessing.ICA Fitted ICA object with
ica.excludepopulated according to the label criteria.ica.pybemobil_fit_info_describes the fit that actually ran (method,requested_method,n_components,rng_seed, fit parameters, number of epochs and FASTER-dropped epochs);EEGPreprocessorrecords it in the provenance descriptor.- ic_labels
dict Output of
mne_icalabel.label_components()containing"labels"and"y_pred_proba"keys.
- ica
- Raises:
ValueErrorIf both exclude_labels and include_labels are provided.