gastropy.egg_clean#
- gastropy.egg_clean(data, sfreq, low_hz=None, high_hz=None, method='fir', band=None, **filter_kwargs)[source]#
Clean an EGG signal by applying a bandpass filter.
By default, filters to the normogastric band (0.033-0.067 Hz, 2-4 cpm). Custom frequency bounds can be provided.
Supports three named method variants following the neurokit2 convention of attributable, citable pipelines:
"fir"(default) — Zero-phase FIR bandpass with adaptive tap count. Suitable for most applications."iir"— Zero-phase IIR Butterworth bandpass using cascaded second-order sections (SOS). Faster for real-time or iterative use, slightly less precise roll-off."dalmaijer2025"— Full preprocessing pipeline from Dalmaijer (2025): Hampel spike removal → LMMSE movement-artifact attenuation → IIR Butterworth bandpass. Recommended when motion artifacts are present in ambulatory recordings.
- Parameters:
data (array_like) – Raw EGG signal (1D array).
sfreq (float) – Sampling frequency in Hz.
low_hz (float, optional) – Lower passband edge in Hz. If None, uses
band.f_lo.high_hz (float, optional) – Upper passband edge in Hz. If None, uses
band.f_hi.method (str, optional) – Cleaning method:
"fir"(default),"iir", or"dalmaijer2025".band (GastricBand, optional) – Gastric band for default frequency limits. Default is
NORMOGASTRIA.**filter_kwargs – Additional arguments passed to
apply_bandpasswhenmethodis"fir"or"iir"(e.g.,f_order,transition_width). For"dalmaijer2025", acceptshampel_k(int, default 3),hampel_n_sigma(float, default 3.0), andmovement_window(float, default 1.0).
- Returns:
cleaned (np.ndarray) – Cleaned EGG signal.
info (dict) – Processing metadata, including
"cleaning_method"and sub-step information for multi-stage pipelines.
See also
egg_processFull EGG processing pipeline.
hampel_filterSliding-window spike removal.
remove_movement_artifactsLMMSE movement artifact filter.
References
Dalmaijer, E. S. (2025). electrography v1.1.1. esdalmaijer/electrography
Gharibans, A. A., Smarr, B., Kunkel, D. C., Kriegsfeld, L. J., Mousa, H., & Coleman, T. P. (2018). Artifact rejection methodology enables continuous, noninvasive measurement of gastric myoelectric activity in ambulatory subjects. Scientific Reports, 8, 5019.
Examples
>>> import numpy as np >>> from gastropy.egg import egg_clean >>> sig = np.random.randn(3000) # 300s at 10 Hz >>> cleaned, info = egg_clean(sig, sfreq=10.0)
Use the Dalmaijer 2025 full preprocessing pipeline:
>>> t = np.arange(0, 300, 0.1) >>> sig = np.sin(2 * np.pi * 0.05 * t) + 0.1 * np.random.randn(len(t)) >>> cleaned, info = egg_clean(sig, sfreq=10.0, method="dalmaijer2025") >>> info["cleaning_method"] 'dalmaijer2025'