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 ofwindowseconds 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), infit; 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 belowflat(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:
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".
- qc_#
Per method:
n_segments,duration_sandfraction;fraction_bad(any method, existingBADannotations included) andreject(thresholds).- Type:
Notes
Annotations are added with descriptions
BAD_amplitude,BAD_flatandBAD_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
fitmethod.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
transformmethod.transform(inst, *[, copy])Apply the fitted step to the data.
Attributes
Data types the step accepts.
Whether the step may add
BAD_annotations (existing ones are kept).changes_channelsWhether the step may add, drop or reorder channels.
changes_timesWhether the step may change the time axis (e.g. resampling, cropping).
drops_epochsWhether the step may drop epochs (e.g. artifact rejection).
kind -> whether it needs data (
inst).returnsData type the step returns;
Nonemeans the same type as its input.systemsAcquisition systems the step applies to;
Nonemeans all systems.- accepts: ClassVar[tuple[type, ...]] = (<class 'mne.io.base.BaseRaw'>,)#
Data types the step accepts.