mne_denoise.asr.compute_clean_window_mask#

mne_denoise.asr.compute_clean_window_mask(X: ndarray, sfreq: float, *, max_bad_channels: float | int = 0.2, zthresholds: tuple[float, float] = (-3.5, 5.0), window_length: float = 1.0, window_overlap: float = 0.66, max_dropout_fraction: float = 0.1, min_clean_fraction: float = 0.25, fit_quantiles: tuple[float, float] = (0.022, 0.6), beta_grid: ndarray | None = None) tuple[ndarray, dict[str, Any]][source]#

Compute a statistical retained-sample mask for continuous data.

Parameters:
  • X (ndarray, shape (n_channels, n_times)) – Continuous data.

  • sfreq (float) – Sampling frequency in Hz.

  • max_bad_channels (float | int) – Maximum tolerated number or fraction of bad channels per retained window.

  • zthresholds (tuple of float) – Lower and upper robust z-score thresholds for channel RMS values.

  • window_length (float) – Window length in seconds.

  • window_overlap (float) – Overlap fraction between successive windows.

  • max_dropout_fraction (float) – Maximum low-tail dropout fraction for robust RMS fitting.

  • min_clean_fraction (float) – Minimum clean fraction for robust RMS fitting.

  • fit_quantiles (tuple of float) – Lower and upper quantiles for the truncated generalized-Gaussian fit.

  • beta_grid (ndarray | None) – Optional generalized-Gaussian beta grid.

Returns:

  • sample_mask (ndarray, shape (n_times,)) – Boolean retained-sample mask. False entries indicate windows that would be removed by clean_windows-style rejection.

  • diagnostics (dict) – Window-level RMS, z-score, and retained/removed mask diagnostics.

Examples

Compute a clean sample mask for a NumPy array:

>>> import numpy as np
>>> from mne_denoise.asr import compute_clean_window_mask
>>> sfreq = 250.0
>>> data = np.random.randn(5, 1000)  # 5 channels, 4 seconds of data
>>> # Inject a burst into channel 0 between samples 400 and 600
>>> data[0, 400:600] *= 25.0
>>> mask, info = compute_clean_window_mask(data, sfreq)
>>> print(f"Mask length: {len(mask)}")
Mask length: 1000
>>> # True denotes clean samples, False denotes bad samples
>>> print(f"Found {mask.sum()} clean samples.")
Found ... clean samples.