ica.IcaMixin#

class autoclean.mixins.signal_processing.ica.IcaMixin[source]#

Mixin for ICA processing.

run_ica(eog_channel=None, use_epochs=False, stage_name='post_ica', **kwargs)[source]#

Run ICA on the raw data.

This method will fit an ICA object to the raw data and save it to a FIF file. ICA object is stored in self.final_ica. Uses optional kwargs from the autoclean_config file to fit the mne ICA object.

Parameters:
eog_channelstr, optional

The EOG channel to use for ICA. If None, no EOG detection will be performed.

use_epochsbool, optional

If True, epoch data stored in self.epochs will be used.

stage_namestr, optional

Name of the processing stage for export. Default is “post_ica”.

exportbool, optional

If True, exports the processed data to the stage directory. Default is False.

Returns:
final_icamne.preprocessing.ICA

The fitted ICA object.

See also

classify_ica_components

Classify ICA components with ICLabel or ICVision.

Examples

>>> self.run_ica()
>>> self.run_ica(eog_channel="E27", export=True)
classify_ica_components(method='iclabel', reject=True, stage_name='post_ica', export=False)[source]#

Classify ICA components and optionally reject artifact components.

This method classifies ICA components using either ICLabel or ICVision methods and can automatically reject components identified as artifacts.

Parameters:
methodstr, default “iclabel”

Classification method to use. Options: “iclabel”, “icvision”.

rejectbool, default True

If True, automatically reject components identified as artifacts.

stage_namestr, optional

Name of the processing stage for export. Default is “post_component_removal”.

exportbool, optional

If True, exports the processed data to the stage directory. Default is False.

Returns:
ica_flagspandas.DataFrame or None

A pandas DataFrame containing the classification results, or None if the step fails.

Notes

This method will modify the self.final_ica attribute in place by adding labels. If reject=True, it will also apply component rejection.

Examples

>>> # Classify with ICLabel and auto-reject
>>> self.classify_ica_components(method="iclabel", reject=True)
>>> # Classify with ICVision without rejection
>>> self.classify_ica_components(method="icvision", reject=False)
apply_ica_component_rejection(data_to_clean=None)[source]#

Apply ICA component rejection based on component classifications and configuration.

This method uses the labels assigned by classify_ica_components and the rejection criteria specified in the ‘ICLabel’ section of the pipeline configuration (e.g., ic_flags_to_reject, ic_rejection_threshold) to mark components for rejection. It then applies the ICA to remove these components from the data.

It updates self.final_ica.exclude and modifies the data object (e.g., self.raw) in-place. The updated ICA object is also saved.

Parameters:
data_to_cleanmne.io.Raw | mne.Epochs, optional

The data to apply the ICA to. If None, defaults to self.raw. This should ideally be the same data object that classification was performed on, or is compatible with self.final_ica.

Returns:
None

Modifies self.final_ica and the input data object in-place.

Raises:
RuntimeError

If self.final_ica or self.ica_flags are not available (i.e., run_ica and classify_ica_components have not been run successfully).