dense_oscillatory.detect_dense_oscillatory_artifacts#

autoclean.functions.segment_rejection.dense_oscillatory.detect_dense_oscillatory_artifacts(raw, window_size_ms=100, channel_threshold_uv=45, min_channels=75, padding_ms=500, annotation_label='BAD_REF_AF', verbose=None)[source]#

Detect smaller, dense oscillatory multichannel artifacts.

This function identifies oscillatory artifacts that affect multiple channels simultaneously, while excluding large single deflections. It uses a sliding window approach to detect periods where many channels simultaneously show high peak-to-peak amplitudes.

Parameters:
rawmne.io.Raw

The raw EEG data to analyze for oscillatory artifacts.

window_size_msint, default 100

Window size in milliseconds for artifact detection.

channel_threshold_uvfloat, default 45

Threshold for peak-to-peak amplitude in microvolts.

min_channelsint, default 75

Minimum number of channels that must exhibit oscillations.

padding_msfloat, default 500

Amount of padding in milliseconds to add before and after each detected artifact.

annotation_labelstr, default “BAD_REF_AF”

Label to use for the annotations.

verbosebool or None, default None

Control verbosity of output.

Returns:
raw_annotatedmne.io.Raw

Copy of the input Raw object with added annotations for detected oscillatory artifacts.

Raises:
TypeError

If raw is not an MNE Raw object.

ValueError

If parameters are outside valid ranges.

RuntimeError

If processing fails due to insufficient data or other errors.

See also

annotate_noisy_segments

General segment-level noise detection

annotate_uncorrelated_segments

Correlation-based segment rejection

mne.Annotations

MNE annotations system

Notes

Detection Algorithm: 1. Uses a sliding window across the continuous data 2. For each window, calculates peak-to-peak amplitude for each channel 3. Counts channels exceeding the amplitude threshold 4. Marks windows where channel count exceeds min_channels threshold 5. Adds padding around detected artifacts to ensure complete removal

Parameter Guidelines: - window_size_ms: 50-200ms typical. Shorter for transient artifacts - channel_threshold_uv: 30-60µV typical. Depends on preprocessing - min_channels: 50-100 typical. Should be ~50-75% of total channels - padding_ms: 200-1000ms typical. Ensures artifact boundaries captured

Performance Considerations: - Processing time scales with data length and window overlap - Memory usage depends on number of channels and sampling rate - Larger windows are more computationally efficient but less precise

References

This implementation is designed to detect reference artifacts and other dense oscillatory patterns that affect multiple channels simultaneously.

Examples

Basic oscillatory artifact detection:

>>> from autoclean.functions.segment_rejection import detect_dense_oscillatory_artifacts
>>> raw_clean = detect_dense_oscillatory_artifacts(raw)
>>> artifacts = [ann for ann in raw_clean.annotations
...              if 'REF_AF' in ann['description']]
>>> print(f"Found {len(artifacts)} oscillatory artifacts")

Conservative detection for clean data:

>>> raw_clean = detect_dense_oscillatory_artifacts(
...     raw,
...     window_size_ms=150,
...     channel_threshold_uv=60,
...     min_channels=100,
...     padding_ms=1000
... )

Sensitive detection for noisy data:

>>> raw_clean = detect_dense_oscillatory_artifacts(
...     raw,
...     window_size_ms=75,
...     channel_threshold_uv=30,
...     min_channels=50,
...     annotation_label="BAD_oscillatory"
... )