https://github.com/mne-tools/mne-denoise
mne-denoise provides narrow-band artefact removal tailored to MNE-Python workflows. It wraps harmonic regression techniques to suppress power-line noise and other oscillatory contaminants while preserving signal rank and interpretability.
https://github.com/mne-tools/mne-denoise
bci brain-computer-interface datacleaning dss eeg neuroscience noiseremoval python
Last synced: 6 days ago
JSON representation
mne-denoise provides narrow-band artefact removal tailored to MNE-Python workflows. It wraps harmonic regression techniques to suppress power-line noise and other oscillatory contaminants while preserving signal rank and interpretability.
- Host: GitHub
- URL: https://github.com/mne-tools/mne-denoise
- Owner: mne-tools
- License: bsd-3-clause
- Created: 2024-07-11T21:13:13.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2026-06-05T19:04:15.000Z (15 days ago)
- Last Synced: 2026-06-05T20:22:06.512Z (15 days ago)
- Topics: bci, brain-computer-interface, datacleaning, dss, eeg, neuroscience, noiseremoval, python
- Language: Python
- Homepage:
- Size: 119 MB
- Stars: 27
- Watchers: 6
- Forks: 8
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# mne-denoise
[](https://github.com/mne-tools/mne-denoise/actions/workflows/ci.yml)
[](https://codecov.io/gh/mne-tools/mne-denoise)
[](https://pypi.org/project/mne-denoise/)
[](https://pypi.org/project/mne-denoise/)
[](https://opensource.org/licenses/BSD-3-Clause)
[](https://github.com/astral-sh/ruff)
[](https://mne.tools/mne-denoise/)
[](https://pepy.tech/project/mne-denoise)
**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)
```bash
pip install mne-denoise
```
### From source (development)
```bash
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:
```python
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):
```python
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:
```python
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/mne-denoise](https://mne.tools/mne-denoise/)**.
- [Getting Started Guide](https://mne.tools/mne-denoise/getting-started.html)
- [API Reference](https://mne.tools/mne-denoise/api.html)
- [Example Gallery](https://mne.tools/mne-denoise/auto_examples/index.html)
## ποΈ 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
```bash
# Run tests
pytest
# With coverage
pytest --cov=mne_denoise --cov-report=html
```
## Contributing
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
```bash
# Development setup
git clone https://github.com//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](LICENSE) for details.