meeg_utils.steps.BadSegments#

class meeg_utils.steps.BadSegments(methods=('amplitude', 'muscle'), *, reject='auto', flat=None, window=1.0, muscle_threshold=4.0, muscle_freqs=(110.0, 140.0), random_state=42)[source]#

Mark bad stretches of a recording with BAD_* annotations.

The data are not changed. Later steps skip annotated segments: ICA fitting, epoching (reject_by_annotation) and most MNE functions.

Methods (any combination):

  • "amplitude": the recording is cut into windows of window seconds and a window is bad if the peak-to-peak amplitude of any good channel exceeds its type’s threshold. reject="auto" (default) learns one threshold per channel type from the data, as autoreject’s global threshold (Jas et al., 2017, NeuroImage 159:417), in fit; or pass thresholds, e.g. {"eeg": 150e-6}. The learned threshold also flags blinks and heartbeats; before ICA, which removes them, pass looser thresholds so that only gross artifacts are marked.

  • "flat": a window is bad if a good channel’s peak-to-peak amplitude is below flat (e.g. {"eeg": 1e-6}), e.g. amplifier saturation or disconnection.

  • "muscle": mne.preprocessing.annotate_muscle_zscore() (MNE defaults: 110-140 Hz envelope, z > 4, segments shorter than 0.1 s between bad ones also marked). Needs data up to 140 Hz.

Parameters:
  • methods (str | list of str) – Methods to apply.

  • reject ("auto" | dict) – "amplitude": thresholds per channel type (peak-to-peak, SI units).

  • flat (dict | None) – "flat": minimum peak-to-peak per channel type.

  • window (float) – Window length (s) for "amplitude" and "flat".

  • muscle_threshold (float) – "muscle": z-score threshold.

  • muscle_freqs (tuple of float) – "muscle": band of the muscle envelope.

  • random_state (int | None) – Seed for reject="auto".

reject_#

Peak-to-peak thresholds used for "amplitude".

Type:

dict

qc_#

Per method: n_segments, duration_s and fraction; fraction_bad (any method, existing BAD annotations included) and reject (thresholds).

Type:

dict

Notes

Annotations are added with descriptions BAD_amplitude, BAD_flat and BAD_muscle; existing annotations are kept. Channels that exceed the thresholds most of the time should be marked bad first (BadChannels), or they mark the whole recording.

Figures (plot()): "segments", the bad segments of each method over time with the window amplitudes and muscle z-scores.

__init__(methods=('amplitude', 'muscle'), *, reject='auto', flat=None, window=1.0, muscle_threshold=4.0, muscle_freqs=(110.0, 140.0), random_state=42)[source]#

Methods

__init__([methods, reject, flat, window, ...])

fit(inst[, y, system])

Learn the step's state from the data.

fit_transform(inst[, y, system, copy])

Fit the step on the data and transform the same data.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

plot([kind, inst])

Draw quality-control figures.

set_fit_request(*[, inst, system])

Configure whether metadata should be requested to be passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_transform_request(*[, copy, inst])

Configure whether metadata should be requested to be passed to the transform method.

transform(inst, *[, copy])

Apply the fitted step to the data.

Attributes

accepts

Data types the step accepts.

adds_annotations

Whether the step may add BAD_ annotations (existing ones are kept).

changes_channels

Whether the step may add, drop or reorder channels.

changes_times

Whether the step may change the time axis (e.g. resampling, cropping).

drops_epochs

Whether the step may drop epochs (e.g. artifact rejection).

plot_kinds

kind -> whether it needs data (inst).

returns

Data type the step returns; None means the same type as its input.

systems

Acquisition systems the step applies to; None means all systems.

accepts: ClassVar[tuple[type, ...]] = (<class 'mne.io.base.BaseRaw'>,)#

Data types the step accepts.

adds_annotations: ClassVar[bool] = True#

Whether the step may add BAD_ annotations (existing ones are kept).

plot_kinds: ClassVar[dict[str, bool]] = {'segments': False}#

kind -> whether it needs data (inst). Each kind is drawn by a _plot_<kind>(inst, **kwargs) method.

Type:

Figures the object can draw once fitted