bemobil_mne.preproc.get_bad_chs#
- bemobil_mne.preproc.get_bad_chs(raw, pyprep_kwargs=None, notch_lines=array([50, 100, 150]), notch_width=1.0, line_noise_crit=None, deviation_threshold=3.5, ransac=None)[source]#
Detect bad EEG channels using PyPREP, FASTER, flatline, and line noise.
Applies optional notch filtering and an average reference, then runs PyPREP’s NoisyChannels (nan/flat, deviation, HF-noise, correlation, and optionally RANSAC), FASTER’s channel-level correlation and variance on 1 s fixed-length epochs, and per-channel line-noise z-score detection. Returns a dictionary containing the union of all identified bad channels and per-method breakdowns.
- Parameters:
- raw
mne.io.Raw The MNE Raw object containing the EEG data. Channels listed in
raw.info['bads']are treated as manual bads and will be included in the returned manual bad list and excluded from some computations.- pyprep_kwargs
dict|None Keyword arguments passed to
pyprep.find_noisy_channels.NoisyChannels. If None, default settings are used. The optional keybad_by_manual(list of channel names) can be provided to include manual bad channels.- notch_lines
float| array_like |"europe"|"usa"|None The line frequencies for notch filtering. Strings
"europe"and"usa"expand to 50/100/150 Hz and 60/120/180 Hz respectively. PassNoneto skip notch filtering.- notch_width
float Width of the notch filter in Hz.
- line_noise_crit
float|None Z-score threshold for the per-channel line noise criterion. A channel is flagged as bad when its line-noise-to-broadband ratio exceeds this many standard deviations above the mean across channels.
None(default) disables this criterion - recommended when ZapLine has already run, as residual line noise is negligible and the criterion may produce false rejections.- deviation_threshold
float Z-score threshold for PyPREP’s amplitude-deviation criterion (
find_bad_by_deviation). Channels whose robust z-score of channel-level RMS exceeds this value are flagged as bad. Default3.5(tighter than PyPREP’s built-in default of5.0) to improve sensitivity on MoBI data where motion raises overall variance.- ransacbool |
None Whether to run PyPREP’s RANSAC bad-channel detection (
find_bad_by_ransac), which uses spherical spline interpolation to predict each channel from a random subset of neighbours and flags channels that cannot be reconstructed. Requires channel positions (i.e. a montage must be set on raw).None(default): run RANSAC automatically when a montage is present; skip silently otherwise.True: always run; raises if no montage / positions available.False: never run.
- raw
- Returns:
- bad_ch_dict
dict Dictionary with the following keys:
"all_bads": union of PyPREP, FASTER, line-noise, and manual bads."pyprep": dict from PyPREP’sget_bads(as_dict=True)."faster": dict from FASTER with a"bad_all"union key."bad_by_line_noise": channels flagged by per-channel line noise."bad_by_manual": manual bad channels.
- bad_ch_dict