Note
Go to the end to download the full example code.
Global Field Power peaks#
This example demonstrates how to extract Global Field Power (GFP) peaks from an EEG recording.
Note
The lemon datasets used in this tutorial is composed of EEGLAB files. To
use the MNE reader mne.io.read_raw_eeglab(), the pymatreader
optional dependency is required. Use the following installation method
appropriate for your environment:
pip install pymatreaderconda install -c conda-forge pymatreader
Note that an environment created via the MNE installers includes
pymatreader by default.
import mne
from mne.io import read_raw_eeglab
from pycrostates.datasets import lemon
raw_fname = lemon.data_path(subject_id="010004", condition="EC")
raw = read_raw_eeglab(raw_fname, preload=True)
raw.pick("eeg")
raw.set_eeg_reference("average")
Reading /home/docs/pycrostates_data/PREPROCESSED_LEMON/sub-010004_EC.fdt
Reading 0 ... 119277 = 0.000 ... 477.108 secs...
/home/docs/checkouts/readthedocs.org/user_builds/pycrostates/checkouts/latest/tutorials/preprocessing/00_extract_gfp_peaks.py:32: RuntimeWarning: Limited 1 annotation(s) that were expanding outside the data range.
raw = read_raw_eeglab(raw_fname, preload=True)
/home/docs/checkouts/readthedocs.org/user_builds/pycrostates/checkouts/latest/tutorials/preprocessing/00_extract_gfp_peaks.py:32: RuntimeWarning: The data contains 'boundary' events, indicating data discontinuities. Be cautious of filtering and epoching around these events.
raw = read_raw_eeglab(raw_fname, preload=True)
EEG channel type selected for re-referencing
Applying average reference.
Applying a custom ('EEG',) reference.
Global Field Power (GFP) is computed as the standard
deviation of the sensors at a given timepoint. Local maxima of the
Global Field Power (GFP) are known to represent the portions
of EEG data with highest signal-to-noise ratio[1].
We can use the extract_gfp_peaks()
function to extract samples with the highest Global Field Power.
The minimum distance between consecutive peaks can be defined with the
min_peak_distance argument.
from pycrostates.preprocessing import extract_gfp_peaks
gfp_data = extract_gfp_peaks(raw, min_peak_distance=3)
gfp_data
GFP peaks can also be extracted from an Epochs object.
epochs = mne.make_fixed_length_epochs(raw, duration=2, preload=True)
gfp_data = extract_gfp_peaks(epochs, min_peak_distance=3)
gfp_data
Not setting metadata
238 matching events found
No baseline correction applied
0 projection items activated
Using data from preloaded Raw for 238 events and 500 original time points ...
0 bad epochs dropped
The extracted GFP peaks can be used in other preprocessing steps,
such as a resampling using resample():
Or they can be used to fit a clustering algorithm on the portion of EEG data with the highest signal-to-noise ratio.

<Figure size 1500x300 with 5 Axes>
References#
Total running time of the script: (0 minutes 36.921 seconds)
Estimated memory usage: 387 MB