One-Call EGG Pipeline#

egg_process runs the full analysis pipeline in a single call: bandpass filtering, Hilbert phase/amplitude extraction, cycle detection, and metric computation. It returns a DataFrame of processed signals and a dictionary of metrics.

import gastropy as gp

# Load sample data and select best channel
egg = gp.load_egg()
best_idx, _, _, _ = gp.select_best_channel(egg["signal"], egg["sfreq"])
best_signal = egg["signal"][best_idx]
print(f"Best channel: {list(egg['ch_names'])[best_idx]}")
Best channel: EGG6
# Run the full pipeline
signals_df, info = gp.egg_process(best_signal, egg["sfreq"])

print("DataFrame:")
print(signals_df.head())
print(f"\nShape: {signals_df.shape}")
DataFrame:
        raw  filtered     phase  amplitude
0 -0.004300 -0.000099 -2.745813   0.000108
1 -0.004382 -0.000131  2.625427   0.000150
2 -0.004381 -0.000162  2.531939   0.000197
3 -0.004379 -0.000193  2.434850   0.000253
4 -0.004385 -0.000223  2.435935   0.000293

Shape: (7580, 4)
# Key metrics from the info dict
print(f"Peak frequency:          {info['peak_freq_hz']:.4f} Hz ({info['peak_freq_hz'] * 60:.2f} cpm)")
print(f"Cycles detected:         {info['cycle_stats']['n_cycles']}")
print(f"Mean cycle duration:     {info['cycle_stats']['mean_cycle_dur_s']:.2f} s")
print(f"Instability coefficient: {info['instability_coefficient']:.4f}")
print(f"Proportion normogastric: {info['proportion_normogastric']:.0%}")
print(f"Band power proportion:   {info['band_power']['prop_power']:.1%}")
Peak frequency:          0.0530 Hz (3.18 cpm)
Cycles detected:         37
Mean cycle duration:     20.29 s
Instability coefficient: 0.1759
Proportion normogastric: 95%
Band power proportion:   80.3%

Processing a Different Band#

Pass a band parameter to target a different frequency range.

# Process targeting the tachygastric band instead
tachy_signals, tachy_info = gp.egg_process(best_signal, egg["sfreq"], band=gp.TACHYGASTRIA)

print(f"Tachy peak: {tachy_info['peak_freq_hz']:.4f} Hz ({tachy_info['peak_freq_hz'] * 60:.2f} cpm)")
print(f"Tachy cycles: {tachy_info['cycle_stats']['n_cycles']}")
print(f"Tachy power:  {tachy_info['band_power']['prop_power']:.1%}")
Tachy peak: 0.0960 Hz (5.76 cpm)
Tachy cycles: 75
Tachy power:  2.7%

Alternative Cleaning Pipeline#

egg_clean accepts a method parameter to choose the cleaning strategy. method="dalmaijer2025" chains Hampel spike removal → LMMSE movement filtering → IIR Butterworth bandpass — suitable for ambulatory recordings with motion artifacts (Dalmaijer, 2025).

# --- Alternative cleaning: Dalmaijer 2025 pipeline ---
cleaned_d25, info_d25 = gp.egg_clean(best_signal, egg["sfreq"], method="dalmaijer2025")
print(f"Cleaning method   : {info_d25['cleaning_method']}")
print(f"Butterworth order : {info_d25['butter_order']}")

See also: EGG Overview Plot, Bandpass Filtering, EGG Processing Tutorial