gastropy.select_best_channel#
- gastropy.select_best_channel(data, sfreq, band=None, fmin=0.0, fmax=0.1)[source]#
Select the EGG channel with the strongest gastric rhythm.
Ranks channels by peak power in the target frequency band (default: normogastria, 2-4 cpm) computed from the unfiltered low-frequency PSD. Uses
scipy.signal.find_peaksfor robust local-maximum detection, following Wolpert et al. (2020).- Parameters:
data (array_like) – Multi-channel EGG data, shape
(n_channels, n_samples). For single-channel data, pass shape(1, n_samples).sfreq (float) – Sampling frequency in Hz.
band (GastricBand, optional) – Frequency band to search for the peak. Default is
NORMOGASTRIA(0.033-0.067 Hz / 2-4 cpm).fmin (float, optional) – Minimum frequency for PSD computation. Default is 0.0.
fmax (float, optional) – Maximum frequency for PSD computation. Default is 0.1.
- Returns:
best_idx (int) – Index of the best channel.
peak_freq_hz (float) – Peak frequency (Hz) in the target band for the best channel.
freqs (np.ndarray) – Frequency values from the PSD of the best channel.
psd (np.ndarray) – PSD values for the best channel.
Examples
>>> import numpy as np >>> from gastropy.egg import select_best_channel >>> data = np.random.randn(4, 3000) # 4 channels, 300s at 10 Hz >>> best_idx, peak_freq, freqs, psd = select_best_channel(data, sfreq=10.0)