artifacts.ArtifactsMixin#

class autoclean.mixins.signal_processing.artifacts.ArtifactsMixin[source]#

Mixin class providing artifact detection and rejection functionality for EEG data.

detect_dense_oscillatory_artifacts(data=None, window_size_ms=100, channel_threshold_uv=45, min_channels=75, padding_ms=500, annotation_label='BAD_REF_AF')[source]#

Detect smaller, dense oscillatory multichannel artifacts.

This method identifies oscillatory artifacts that affect multiple channels simultaneously, while excluding large single deflections.

Parameters:
datamne.io.Raw, Optional

The raw data to detect artifacts from. If None, uses self.raw.

window_size_msint, Optional

Window size in milliseconds for artifact detection, by default 100.

channel_threshold_uvfloat, Optional

Threshold for peak-to-peak amplitude in microvolts, by default 45.

min_channelsint, Optional

Minimum number of channels that must exhibit oscillations, by default 75.

padding_msfloat, Optional

Amount of padding in milliseconds to add before and after each detected artifact, by default 500.

annotation_labelstr, Optional

Label to use for the annotations, by default “BAD_REF_AF”.

stage_namestr, Optional

Name for saving and metadata, by default “detect_dense_oscillatory_artifacts”.

Returns:
result_rawinstance of mne.io.Raw

The raw data object with updated artifact annotations. Note the self.raw is updated in place. So the return value is optional.

Notes

This method is intended to find reference artifacts but may also be triggered by other artifacts.

Examples

>>> #Inside a task class that uses the autoclean framework
>>> self.detect_dense_oscillatory_artifacts()
>>> #Or with custom parameters
>>> self.detect_dense_oscillatory_artifacts(window_size_ms=200, channel_threshold_uv=50,
min_channels=100, padding_ms=1000, annotation_label="BAD_CUSTOM_ARTIFACT")
detect_muscle_beta_focus(data=None, freq_band=(20, 30), scale_factor=3.0, window_length=1.0, window_overlap=0.5, annotation_description='BAD_MOVEMENT')[source]#

Detect muscle artifacts in continuous Raw data and add annotations.

This method detects muscle artifacts in continuous EEG data by analyzing high-frequency activity in peripheral electrodes. It automatically adds annotations to the Raw object marking segments with detected artifacts.

Parameters:
datamne.io.Raw, Optional

The raw data to detect artifacts from. If None, uses self.raw.

freq_bandtuple, Optional

Frequency band for filtering (min, max), by default (20, 30).

scale_factorfloat, Optional

Scale factor for threshold calculation, by default 3.0.

window_lengthfloat, Optional

Length of sliding window in seconds, by default 1.0.

window_overlapfloat, Optional

Overlap between windows as a fraction (0-1), by default 0.5.

annotation_descriptionstr, Optional

Description for the annotations, by default “BAD_MOVEMENT”.

Returns
——-
results_rawinstance of mne.io.Raw

The raw data object with updated artifact annotations. Note the self.raw is updated in place. So the return value is optional.

Examples

>>> #Inside a task class that uses the autoclean framework
>>> self.detect_muscle_beta_focus()
>>> #Or with custom parameters
>>> self.detect_muscle_beta_focus(freq_band=(20, 30), scale_factor=4.0, window_length=2.0,
window_overlap=0.7, annotation_description="BAD_CUSTOM_ARTIFACT")
reject_bad_segments(data=None, bad_label=None, stage_name='bad_segment_rejection')[source]#

Remove all time spans annotated with a specific label or all ‘BAD’ segments.

This method removes segments marked as bad and concatenates the remaining good segments.

Parameters:
datamne.io.Raw, Optional

The raw data to detect artifacts from. If None, uses self.raw.

bad_labelstr, Optional
Specific label of annotations to reject. If None, rejects all segments

where description starts with ‘BAD’

stage_namestr, Optional

Name for saving and metadata, by default “bad_segment_rejection”.

Returns:
raw_cleanedinstance of mne.io.Raw

The raw data object with updated artifact annotations. Note the self.raw is updated in place. So the return value is optional..

Examples

>>> #Inside a task class that uses the autoclean framework
>>> self.reject_bad_segments()
>>> #Or with custom label
>>> self.reject_bad_segments(bad_label="BAD_CUSTOM_ARTIFACT")