API Reference#
GastroPy exposes a flat namespace: most functions are accessible directly
from import gastropy as gp. The reference below is organized by
submodule.
EGG — Core Pipeline#
High-level functions for EGG signal processing.
Process an EGG signal through the full analysis pipeline. |
|
Clean an EGG signal by applying a bandpass filter. |
|
Process a multi-channel EGG recording. |
|
Select the EGG channel with the strongest gastric rhythm. |
|
Find the peak frequency in the gastric band from a single channel. |
Signal — DSP Utilities#
Low-level signal processing building blocks.
Compute power spectral density using Welch's method. |
|
Design a FIR bandpass filter with adaptive tap count. |
|
Apply a zero-phase bandpass filter to a signal. |
|
Compute instantaneous phase via the Hilbert transform. |
|
Detect complete cycles from phase and return their durations. |
|
Compute mean phase angle within each time window. |
|
Resample a signal to a new sampling frequency. |
|
Detect artifact cycles in an EGG phase time series. |
|
Detect cycle boundaries from a wrapped phase time series. |
Signal — Preprocessing & Artifact Removal#
Time-domain preprocessing functions for artifact removal before
bandpass filtering. All accept 1D or 2D (n_channels, n_samples)
arrays.
Remove spike artifacts using the Hampel median identifier. |
|
Remove outliers using a global median absolute deviation filter. |
|
Attenuate movement artifacts using an LMMSE Wiener filter. |
|
Denoise multi-channel EGG using Independent Component Analysis. |
|
Fit a sine wave to an EGG signal using least-squares optimisation. |
|
Evaluate a sine wave. |
Metrics — Rhythm Quantification#
Gastric rhythm metrics and quality assessment.
Compute power metrics for a specific frequency band. |
|
Compute the instability coefficient (IC) of gastric rhythm. |
|
Compute summary statistics for cycle durations. |
|
Compute the proportion of cycles in the normogastric range. |
|
Assess EGG recording quality based on standard criteria. |
|
A named gastric frequency band. |
|
A named gastric frequency band. |
|
A named gastric frequency band. |
|
A named gastric frequency band. |
|
Built-in mutable sequence. |
Time-Frequency — Per-Band Decomposition#
Decompose signals across gastric frequency bands.
Decompose a signal within a single gastric frequency band. |
|
Run per-band decomposition across multiple gastric frequency bands. |
|
Compute time-frequency power using Morlet wavelet convolution. |
Coupling — Phase Coupling Analysis#
Phase-locking value (PLV), surrogate testing, and circular statistics for gastric-brain coupling analyses.
Compute the phase-locking value between two phase time series. |
|
Compute the complex phase-locking value. |
|
Compute surrogate PLV via circular time-shifting. |
|
Compute z-scored coupling strength (empirical vs. surrogate). |
|
Compute the circular (directional) mean of phase values. |
|
Compute the mean resultant length of phase values. |
|
Rayleigh test for non-uniformity of circular data. |
IO — BIDS Physio I/O#
Read and write BIDS-formatted peripheral physiology recordings,
and convert from common acquisition formats. For MATLAB users, see
examples/matlab/egg_to_bids.m.
Read a BIDS |
|
Write signal data as BIDS |
|
Parse BIDS key-value entities from a filename. |
|
Convert a BrainVision EGG recording to BIDS physio format. |
Data — Sample Datasets#
Load bundled example EGG recordings for tutorials and testing.
Sample data is stored in BIDS physio format.
fetch_fmri_bold downloads preprocessed fMRI data from a GitHub Release.
Load a sample fMRI-EGG recording. |
|
Load a sample standalone EGG recording. |
|
List available sample datasets. |
|
Download preprocessed fMRI BOLD data for coupling analysis. |
Viz — Visualization#
Plotting functions for EGG signals and gastric rhythm analysis.
Plot power spectral density with gastric band shading. |
|
Plot a 4-panel EGG overview: raw, filtered, phase, amplitude. |
|
Plot histogram of gastric cycle durations. |
|
Plot phase time series with artifact regions highlighted. |
|
Plot per-volume mean phase from fMRI-EGG coupling. |
|
Create a comprehensive multi-panel EGG analysis figure. |
|
Plot a time-frequency representation as a heatmap. |
|
Plot a volumetric coupling map as an anatomical overlay. |
|
Plot a coupling map as a transparent glass brain. |
Neuro — Neuroimaging Utilities#
Functions specific to gastric-brain coupling with fMRI, EEG, and MEG.
Access via gastropy.neuro.fmri.
Extract fMRI scanner trigger onset times from MNE annotations. |
|
Create volume window index pairs from trigger onsets. |
|
Extract mean phase angle for each fMRI volume. |
|
Remove transient volumes from the start and end of a time series. |
|
Remove confound signals from BOLD data via GLM regression. |
|
Extract instantaneous phase at the gastric frequency for each voxel. |
|
Compute a voxelwise PLV map between EGG and BOLD phases. |
|
Compute a surrogate PLV map via circular time-shifting. |
|
Load fMRIPrep BOLD and brain mask as a masked 2D array. |
|
Align BOLD volumes to EGG trigger count. |
|
Convert a 3D numpy array to a nibabel NIfTI image. |