pybemobil.preproc.get_bad_chs#

pybemobil.preproc.get_bad_chs(raw, pyprep_kwargs=None, notch_lines='europe', notch_width=1.0, line_noise_crit=None, deviation_threshold=3.5, ransac=None, highpass=1.0, max_bad_fraction=0.2)[source]#

Detect bad EEG channels using PyPREP, FASTER and optionally line noise.

Works on a copy of raw: high-passes it (PyPREP’s noisy-channel criteria expect high-passed data, and slow drifts would otherwise inflate FASTER’s variance criterion), applies an average reference, optionally runs a per-channel line-noise z-score criterion, then notch-filters and runs PyPREP’s NoisyChannels (NaN/flat, deviation, HF-noise, correlation, and optionally RANSAC) and FASTER’s channel-level correlation and variance on 1 s fixed-length epochs. Returns a dictionary containing the union of all identified bad channels and per-method breakdowns. raw itself is not modified.

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. Defaults to "europe". 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.

highpassfloat | None

High-pass cutoff (Hz) applied to the working copy before detection. Default 1.0, as PyPREP’s PREP pipeline does. None skips it.

max_bad_fractionfloat | None

Warn when more than this fraction of the EEG channels is flagged (default 0.2, BeMoBIL’s num_chan_rej_max_target = 1/5). Many bad channels usually mean a recording problem or too strict criteria, and interpolating them leaves little independent data for ICA. None disables the warning.

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.