Advanced Python library for automatic and adaptive removal of line noise from EEG data
PyZaplinePlus is a Python adaptation of the Zapline-plus library, designed to automatically remove spectral peaks like line noise from EEG data while preserving the integrity of the non-noise spectrum and maintaining the data rank.
Unlike traditional notch filters that can distort your data, PyZaplinePlus uses sophisticated spectral detection and Denoising Source Separation (DSS) to identify and remove line noise components adaptively, providing clean EEG signals without unnecessary loss of important neural information.
pip install pyzaplineplus
import numpy as np
from pyzaplineplus import zapline_plus
# Your EEG data (time Γ channels)
data = np.random.randn(10000, 64) # Example: 10s of 64-channel data at 1000 Hz
sampling_rate = 1000
# Clean the data - it's that simple!
cleaned_data = zapline_plus(data, sampling_rate)
import mne
from pyzaplineplus import zapline_plus
# Load your MNE data
raw = mne.io.read_raw_fif('your_data.fif', preload=True)
data = raw.get_data().T # Transpose to time Γ channels
sampling_rate = raw.info['sfreq']
# Clean the data
cleaned_data = zapline_plus(data, sampling_rate)
# Update your MNE object
raw._data = cleaned_data.T
Feature | Notch Filters | PyZaplinePlus |
---|---|---|
Spectral Distortion | β Can distort nearby frequencies | β Preserves non-noise spectrum |
Adaptivity | β Fixed filtering | β Adaptive to data characteristics |
Rank Preservation | β May reduce data rank | β Maintains data rank |
Multiple Frequencies | β Requires multiple filters | β Handles multiple frequencies simultaneously |
Automatic Detection | β Manual frequency specification | β Automatic noise detection |
PyZaplinePlus is based on peer-reviewed research:
We welcome contributions! See our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use PyZaplinePlus in your research, please cite:
@software{esmaeili2024pyzaplineplus,
title = {PyZaplinePlus: Advanced Python library for automatic and adaptive removal of line noise from EEG data},
author = {Esmaeili, Sina},
year = {2024},
url = {https://github.com/snesmaeili/PyZapline_plus}
}
And the original Zapline-plus paper:
@article{klug2022zapline,
title={Zapline-plus: A Zapline extension for automatic and adaptive removal of frequency-specific noise artifacts in M/EEG},
author={Klug, Marius and Kloosterman, Niels A},
journal={Human Brain Mapping},
year={2022},
doi={10.1002/hbm.25832}
}