channels.detect_bad_channels#
- autoclean.functions.artifacts.channels.detect_bad_channels(data, correlation_thresh=0.35, deviation_thresh=2.5, ransac_sample_prop=0.35, ransac_corr_thresh=0.65, ransac_frac_bad=0.25, ransac_channel_wise=False, random_state=1337, exclude_channels=None, return_by_method=False, verbose=None)[source]#
Detect bad channels using multiple statistical methods.
This function uses the PyPREP NoisyChannels implementation to detect bad channels through correlation, deviation, and RANSAC-based methods. These methods are based on established preprocessing pipelines and provide robust detection of various types of channel artifacts.
The function implements multiple complementary detection approaches: - Correlation-based: Identifies channels poorly correlated with neighbors - Deviation-based: Finds channels with excessive amplitude deviations - RANSAC-based: Uses robust regression to detect outlier channels
- Parameters:
- data
mne.io.BaseRaw
The continuous EEG data to analyze for bad channels.
- correlation_thresh
float
,default
0.35 Threshold for correlation-based bad channel detection. Channels with correlation below this value with their neighbors are marked as bad. Lower values are more stringent.
- deviation_thresh
float
,default
2.5 Threshold for deviation-based detection in standard deviations. Channels exceeding this many SDs from the mean are marked as bad.
- ransac_sample_prop
float
,default
0.35 Proportion of samples to use for RANSAC detection (0.0-1.0). Higher values use more data but are computationally more expensive.
- ransac_corr_thresh
float
,default
0.65 Correlation threshold for RANSAC-based detection. Set to 0 to disable RANSAC detection entirely.
- ransac_frac_bad
float
,default
0.25 Expected fraction of bad channels for RANSAC algorithm (0.0-1.0). Should reflect prior knowledge about data quality.
- ransac_channel_wisebool,
default
False
Whether to perform RANSAC detection channel-wise rather than globally. Channel-wise detection can be more sensitive but slower.
- random_state
int
,default
1337 Random seed for reproducible RANSAC results.
- exclude_channels
list
ofstr
orNone
,default
None
Channel names to exclude from bad channel detection (e.g., reference channels). These channels will never be marked as bad.
- return_by_methodbool,
default
False
If True, returns a dictionary with bad channels separated by detection method. If False, returns a combined list of all bad channels.
- verbosebool or
None
,default
None
Control verbosity of output during detection.
- data
- Returns:
See also
pyprep.find_noisy_channels.NoisyChannels
Underlying detection implementation
mne.io.Raw.info
Access channel information and bad channel lists
Autoreject
Automated artifact rejection for MEG and EEG data. NeuroImage, 159, 417-429.
Examples
>>> bad_channels = detect_bad_channels(raw) >>> bad_channels = detect_bad_channels(raw, correlation_thresh=0.4, return_by_method=True)