meeg_utils.steps.LineNoise#

class meeg_utils.steps.LineNoise(method='zapline-plus', *, fline=None, n_remove='auto', n_harmonics=None, nfft=1024, adaptive_params=None)[source]#

Remove power-line noise.

ZapLine methods come from mne-denoise. Each data channel type (mag, grad, eeg) is processed separately, because their units differ, and the cleaned data are written back in place, so all other channels, annotations and timing are preserved. Channels marked bad are neither used nor cleaned.

Parameters:
  • method ({"zapline-plus", "zapline", "notch"}) –

    • "zapline-plus" (default): adaptive ZapLine-plus (Klug & Kloosterman, 2022). It detects the noise around fline, segments the recording and chooses the number of components per segment. It adapts to whatever data it transforms, so transform re-estimates on new data.

    • "zapline": standard ZapLine (de Cheveigné, 2020). Spatial filters are learned in fit and reused by transform.

    • "notch": notch filters at fline and its harmonics (mne.io.Raw.notch_filter()).

  • fline (float | None) – Line frequency in Hz. None (default) uses info["line_freq"], which mne-bids reads from the BIDS sidecar; fitting fails if neither is set rather than assuming 50 or 60 Hz.

  • n_remove (int | "auto") – "zapline" only: number of components to remove, or "auto" (outlier-based selection, capped by mne-denoise at 20% of the components). Fixed counts should stay small: ZapLine’s residual contains broadband activity above roughly fline / 2 as well as the line noise, so removing many components distorts it.

  • n_harmonics (int | None) – Number of harmonics to target; None uses all below Nyquist.

  • nfft (int) – FFT length used by ZapLine.

  • adaptive_params (dict | None) – "zapline-plus" only: options passed to mne-denoise’s adaptive mode.

fline_#

Line frequency used.

Type:

float

qc_#

Per channel type: suppression_db (power reduction at fline), distortion_db (mean absolute log-power change 1-45 Hz outside the line harmonics), distortion_db_broadband (same up to 90% of Nyquist), variance_removed_pct, overclean_fraction and underclean_fraction (fractions of channels with the noise floor around fline lowered by more than 3 dB, or with a residual peak above twice the surrounding power), n_flat_skipped (flat channels left out of these metrics) and, for ZapLine, n_removed.

Type:

dict

psd_#

Per channel type, PSDs before and after the last transform.

Type:

dict

Notes

Figures (plot()): "psd", spectra before and after cleaning with the line frequency and its harmonics marked.

__init__(method='zapline-plus', *, fline=None, n_remove='auto', n_harmonics=None, nfft=1024, adaptive_params=None)[source]#

Methods

__init__([method, fline, n_remove, ...])

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.

plot_kinds: ClassVar[dict[str, bool]] = {'psd': 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