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:
rawmne.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_kwargsdict | None

Keyword arguments passed to pyprep.find_noisy_channels.NoisyChannels. If None, default settings are used. The optional key bad_by_manual (list of channel names) can be provided to include manual bad channels.

notch_linesfloat | 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. Pass None to skip notch filtering.

notch_widthfloat

Width of the notch filter in Hz.

line_noise_critfloat | 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_thresholdfloat

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. Default 3.5 (tighter than PyPREP’s built-in default of 5.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.

Returns:
bad_ch_dictdict

Dictionary with the following keys:

  • "all_bads": union of PyPREP, FASTER, line-noise, and manual bads.

  • "pyprep": dict from PyPREP’s get_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.