Skip to main content

Denoising Source Separation (DSS) and ZapLine algorithms for MNE-Python.

Project description

mne-denoise

CI codecov PyPI version Python versions License Code style: ruff Documentation Downloads

Advanced denoising algorithms for M/EEG data in MNE-Python.

mne-denoise provides powerful signal denoising techniques for the MNE-Python ecosystem, including Denoising Source Separation (DSS) and ZapLine algorithms. These methods excel at extracting signals of interest by exploiting data structure rather than just variance.

Features

DSS Module

  • Linear DSS: Extract components based on reproducibility across trials or characteristic frequencies
  • Iterative DSS: Powerful nonlinear separation for complex non-Gaussian sources
  • 20+ Pluggable Denoisers: Spectral, temporal, periodic, and ICA-style bias functions
  • Specialized Variants: TSR, SSVEP enhancement, narrowband oscillation extraction

ZapLine Module

  • ZapLine: Efficient removal of power line noise (50/60 Hz) and harmonics
  • ZapLine-plus: Fully adaptive mode with automatic frequency detection
  • Per-chunk Processing: Handles non-stationary noise characteristics
  • Quality Assurance: Built-in spectral checks to prevent over-cleaning

Integration

  • MNE-Python: Works directly with Raw, Epochs, and Evoked objects or numpy arrays.
  • Scikit-Learn API: Standard fit(), transform(), fit_transform() interface
  • Visualization: Built-in plotting for components and cleaning results

Installation

From PyPI (recommended)

pip install mne-denoise

From source (development)

git clone https://github.com/mne-tools/mne-denoise.git
cd mne-denoise
pip install -e ".[dev]"

Quick Start

DSS: Enhancing Evoked Responses

DSS finds spatial filters that maximize the ratio of reproducible (evoked) to total power:

import mne
from mne_denoise.dss import DSS, AverageBias

# Load your epoched data
epochs = mne.read_epochs("sample-epo.fif")

# Create DSS with trial-average bias
dss = DSS(bias=AverageBias(), n_components=5)
dss.fit(epochs)

# Option 1: Extract source time courses
sources = dss.transform(epochs)

# Option 2: Reconstruct denoised sensor data
cleaned_epochs = dss.transform(epochs, return_type="epochs")

DSS: Extracting Oscillations

Isolate specific frequency bands (e.g., alpha rhythm):

from mne_denoise.dss import DSS, BandpassBias

# Create bandpass bias for alpha (8-12 Hz)
bias = BandpassBias(sfreq=epochs.info["sfreq"], freq=10, bandwidth=4)

dss = DSS(bias=bias, n_components=3)
alpha_sources = dss.fit_transform(epochs)

ZapLine: Removing Line Noise

Remove 50/60 Hz power line artifacts:

import mne
from mne_denoise.zapline import ZapLine

# Load continuous data
raw = mne.io.read_raw_fif("sample-raw.fif", preload=True)

# Standard mode: specify line frequency
zapline = ZapLine(sfreq=raw.info["sfreq"], line_freq=50.0)
cleaned_data = zapline.fit_transform(raw)

# Adaptive mode: automatic detection and per-chunk processing
zapline_plus = ZapLine(
    sfreq=raw.info["sfreq"],
    line_freq=None,  # Auto-detect
    adaptive=True,
)
cleaned = zapline_plus.fit_transform(raw)
print(f"Detected line frequency: {zapline_plus.detected_freq_} Hz")

Documentation

Full documentation is available at mne-tools.github.io/mne-denoise.

🏗️ Architecture

mne_denoise/
├── dss/                    # Denoising Source Separation
│   ├── linear.py           # Core DSS algorithm, DSS estimator
│   ├── nonlinear.py        # Iterative DSS, IterativeDSS estimator
│   ├── denoisers/          # 20+ pluggable bias functions
│   │   ├── spectral.py     # BandpassBias, LineNoiseBias
│   │   ├── temporal.py     # TimeShiftBias, SmoothingBias
│   │   ├── periodic.py     # CombFilterBias, PeakFilterBias
│   │   └── ...
│   └── variants/           # Pre-built applications
│       ├── tsr.py          # Time-Shift Repeatability
│       ├── ssvep.py        # SSVEP enhancement
│       └── narrowband.py   # Oscillation extraction
├── zapline/                # Line noise removal
│   ├── core.py             # ZapLine estimator
│   └── adaptive.py         # ZapLine-plus utilities
└── viz/                    # Visualization tools

Testing

# Run tests
pytest

# With coverage
pytest --cov=mne_denoise --cov-report=html

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

# Development setup
git clone https://github.com/<your-username>/mne-denoise.git
cd mne-denoise
pip install -e ".[dev,docs]"
pre-commit install

References

DSS

Särelä, J., & Valpola, H. (2005). Denoising source separation. Journal of Machine Learning Research, 6, 233-272.

de Cheveigné, A., & Simon, J. Z. (2008). Denoising based on spatial filtering. Journal of Neuroscience Methods, 171(2), 331-339.

ZapLine

de Cheveigné, A. (2020). ZapLine: A simple and effective method to remove power line artifacts. NeuroImage, 207, 116356.

Klug, M., & Kloosterman, N. A. (2022). Zapline-plus: A completely automatic and highly effective method for removing power line noise. Human Brain Mapping, 43(9), 2743-2758.

License

BSD 3-Clause License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mne_denoise-0.0.1.tar.gz (406.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mne_denoise-0.0.1-py3-none-any.whl (483.7 kB view details)

Uploaded Python 3

File details

Details for the file mne_denoise-0.0.1.tar.gz.

File metadata

  • Download URL: mne_denoise-0.0.1.tar.gz
  • Upload date:
  • Size: 406.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mne_denoise-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e889979cf832b278d4fd34bcb52fc4d2852e4bc6a770bebe8d008747429e2dfe
MD5 96fbb260101ade0b717132ca06f186d3
BLAKE2b-256 d5011b249391cfd1b072f260eacd12cdac977912fdbad51b3c39fe36148183bd

See more details on using hashes here.

File details

Details for the file mne_denoise-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mne_denoise-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 483.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mne_denoise-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dac94ffd483598431af41fc2e8ade1990f4512439855f2d87a67df570e0d04f4
MD5 0583c5ecb99dd17dc276eb782d8672f0
BLAKE2b-256 f1a25da3db38c20d31a6af346d64dda78fef3106b95d72c2f9fe4810d4eb20b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page