autoreject_epochs.AutoRejectEpochsMixin#
- class autoclean.mixins.signal_processing.autoreject_epochs.AutoRejectEpochsMixin[source]#
Mixin class providing functionality to clean epochs using AutoReject.
This mixin provides methods for cleaning epochs using AutoReject, a machine learning-based method for automatic artifact rejection in EEG data. AutoReject automatically identifies and removes bad epochs and interpolates bad channels within epochs.
The cleaning process involves training a model to identify bad channels and epochs based on statistical properties of the data, and then applying this model to clean the data. The mixin provides configurable parameters for controlling the behavior of the AutoReject algorithm, such as the number of channels to interpolate and the consensus threshold.
The mixin respects configuration settings from the autoclean_config.yaml file, allowing users to customize the AutoReject parameters and enable/disable the step.
- apply_autoreject(epochs=None, n_interpolate=None, consensus=None, n_jobs=1, stage_name='apply_autoreject')[source]#
Apply AutoReject to clean epochs by removing artifacts and interpolating bad channels.
This method applies the AutoReject algorithm to clean epochs by identifying and removing bad epochs and interpolating bad channels within epochs. AutoReject is a machine learning-based method that automatically determines optimal thresholds for artifact rejection, reducing the need for manual inspection.
The method uses a cross-validation approach to determine the optimal parameters for artifact rejection, including the number of channels to interpolate and the consensus threshold. These parameters can be customized through the method arguments or the configuration file.
The method requires the autoreject package to be installed. If it’s not installed, an ImportError will be raised with instructions for installation.
- Args:
epochs: Optional MNE Epochs object. If None, uses self.epochs n_interpolate: List of number of channels to interpolate. If None, uses default values consensus: List of consensus percentages. If None, uses default values n_jobs: Number of parallel jobs to run (default: 1) stage_name: Name for saving and metadata tracking
- Returns:
mne.Epochs: The cleaned epochs object with bad epochs removed and bad channels interpolated
- Raises:
AttributeError: If self.epochs doesn’t exist when needed TypeError: If epochs is not an Epochs object RuntimeError: If AutoReject fails
- Example:
```python # Apply AutoReject with default parameters clean_epochs = task.apply_autoreject()
# Apply AutoReject with custom parameters clean_epochs = task.apply_autoreject(
n_interpolate=[1, 4, 8], consensus=[0.1, 0.25, 0.5, 0.75, 0.9], n_jobs=4