mne_rt.tools.AdaptiveMultibandGEDAIDenoiser#
- class mne_rt.tools.AdaptiveMultibandGEDAIDenoiser(n_channels: int, sfreq: float, wavelet_level: int | str = 'auto', cycles_per_wavelet: int = 6, shrinkage: float = 0.05, filter_order: int | None = None, n_jobs: int = 1, wavelet_low_cutoff: float = 0.5, broadband_pass: bool = True, prefilter_mode: Literal['reference', 'lowcut', 'none'] = 'reference')[source]#
Bases:
objectStreaming adaptive multiband GEDAI.
- Parameters:
- n_channels
int Number of EEG channels. SENSAI calibration here uses the EEG objective only; gedai’s MEG objective is not implemented, and
fit_gedai()refuses multiband mode for MEG.- sfreq
float Sampling frequency in Hz.
- wavelet_level
int| “auto”, default “auto” Number of wavelet decomposition levels (
n_bands = wavelet_level + 1). If"auto", usesgedai.wavelet.transform.compute_wavelet_level().- cycles_per_wavelet
int, default 6 Cycles at each band’s lower frequency used to size covariance epochs. The lowest approximation uses half its upper edge, as in pyGEDAI.
- shrinkage
float, default 0.05 Reference covariance shrinkage:
(1-s) * R + s * mean(diag(R)) * I.- filter_order
int|None, defaultNone Deprecated compatibility argument. Haar kernels have no Butterworth order. Passing this argument logs a warning; it has no effect.
- n_jobs
int, default 1 Number of threads used to denoise bands in parallel (
joblib,prefer="threads"). Use-1for all cores.- wavelet_low_cutoff
float, default 0.5 Bands whose upper edge is at or below this frequency (Hz) are discarded. This is a dyadic wavelet cutoff, not a brick-wall filter. Also controls the broadband prefilter and automatic level selection.
- broadband_passbool, default
True Calibrate and apply a broadband GEDAI pass before wavelet cleaning, matching pyGEDAI’s default. The broadband covariance epoch is one second (or enough samples for the channel count).
- prefilter_mode{“reference”, “lowcut”, “none”}, default “reference”
"reference"preserves the pyGEDAI prefilter cascade."lowcut"uses only one Haar highpass atwavelet_low_cutoff, even without a broadband pass."none"skips standalone prefilters; sub-cutoff wavelet bands are still excluded. The latter modes reduce delay but change calibration and broadband cleaning, so require a newfit.
- n_channels
Notes
fitcalibrates an eigenvalue threshold in each band with pyGEDAI’s EEG SENSAI objective (up to three reference principal components, noise weight 3, frequency-dependent sensitivity bounds). The fitted sensitivity stays fixed; each local eigenvalue spectrum determines the current cutoff. Baseline and live data must use the same units and sensor reference as the supplied leadfield.The finite trailing covariance history is bounded by the pyGEDAI epoch size, not an EMA with an unbounded tail. All emitted samples lag their input timestamps by
latencyseconds, excluding computation time. This can be several seconds even though no acquisition chunks are held waiting for a processing window. Offline calibration may use future samples within the baseline, but live filtering never reads future chunks.References
Ros, T., Férat, V., Huang, Y., et al. (2025). Return of the GEDAI: Unsupervised EEG Denoising based on Leadfield Filtering. bioRxiv. https://doi.org/10.1101/2025.10.04.680449
- __init__(n_channels: int, sfreq: float, wavelet_level: int | str = 'auto', cycles_per_wavelet: int = 6, shrinkage: float = 0.05, filter_order: int | None = None, n_jobs: int = 1, wavelet_low_cutoff: float = 0.5, broadband_pass: bool = True, prefilter_mode: Literal['reference', 'lowcut', 'none'] = 'reference') None[source]#
Methods
__init__(n_channels, sfreq[, wavelet_level, ...])fit(data[, leadfield])Fit per-band spatial filters from baseline data.
update_and_denoise(data[, template_map, ...])Denoise one real-time chunk, updating per-band covariances as it goes.
Attributes
Activation patterns
Aper band, each shape (n_channels, n_channels).List of
(fmin, fmax)per band.Trailing covariance epoch durations (seconds), including ignored bands.
Most recently used per-band automatic cutoffs.
Align emitted sample
tto source samplet - delay_samples.Baseline SENSAI eigenvalue cutoffs; live cutoffs adapt to each spectrum.
Sorted eigenvalues (descending) per band.
Fixed FIR reconstruction delay in seconds; not compute time.
Number of frequency bands.
Whether each band contributes to the reconstruction.
Spatial filters
Wper band, each shape (n_channels, n_channels).- fit(data: ndarray, leadfield: ndarray | None = None) AdaptiveMultibandGEDAIDenoiser[source]#
Fit per-band spatial filters from baseline data.
- Parameters:
- data
ndarray,shape(n_channels,n_samples) Broadband baseline recording.
- leadfield
ndarray,shape(n_channels,n_sources), optional Forward/leadfield gain matrix. If given, the reference covariance is
L @ L.T(true GEDAI / leadfield mode); otherwise the broadband covariance ofdatais used (band-filter mode). For automatic selection without a leadfield, this baseline must be representative of the signal covariance to preserve.
- data
- Returns:
self
- update_and_denoise(data: ndarray, template_map: ndarray | None = None, threshold: float = 0.7, n_artifact: int | str = 'auto', update_covariance: bool = True, refit: bool = True) ndarray[source]#
Denoise one real-time chunk, updating per-band covariances as it goes.
- Parameters:
- data
ndarray,shape(n_channels,n_samples) New chunk of broadband sensor data.
- template_map
ndarray,shape(n_channels,), optional Known artifact topography (e.g. blink). If given, components whose activation pattern correlates with it above
threshold(absolute correlation) are suppressed in every band.- threshold
float, default 0.7 Absolute-correlation threshold used with
template_map.- n_artifact
int| “auto”, default “auto” When
template_mapisNone,"auto"rejects eigenvalues above each band’s current SENSAI threshold, calculated from the baseline-fitted sensitivity and the local eigenvalue spectrum. With no leadfield, the baseline broadband covariance is the signal reference instead of a theoretical brain model. An integer overrides SENSAI with a fixed count. Leadfield mode suppresses the largest eigenvalues (excess power relative to the brain model); band-filter mode suppresses the smallest (least band-specific). Zero disables component rejection, not prefiltering, output delay, or sub-cutoff band removal. A positive fixed count can remove activity from clean recordings.- update_covariancebool, default
True Whether to update each band’s trailing-epoch covariance with this chunk.
- refitbool, default
True Whether to re-solve the GED for each band after updating its covariance. Set to
Falseto only update covariances (e.g. to re-solve less often than every chunk) while still denoising with the previous spatial filters.
- data
- Returns:
- data_clean
ndarray,shape(n_channels,n_samples) Output sample
tcorresponds to input samplet - delay_samples, including delayed calibration history at startup.
- data_clean
- property band_time_constants: list[float]#
Trailing covariance epoch durations (seconds), including ignored bands.
- property eigenvalue_thresholds: list[float]#
Baseline SENSAI eigenvalue cutoffs; live cutoffs adapt to each spectrum.