Note
Go to the end to download the full example code.
Resampling#
This example demonstrates how to resample a 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.crop(0, 30)
raw.pick("eeg")
raw.set_eeg_reference("average")
/home/docs/checkouts/readthedocs.org/user_builds/pycrostates/checkouts/latest/tutorials/preprocessing/10_resampling.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/10_resampling.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)
The resample() function
draws n_resamples of n_samples from a recording where n_samples
defines the number of samples contained in each epoch and n_resamples
defines the number of epochs to draw.
[< ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >]
The coverage parameter can be used to automatically compute one of
the two previous parameters based on the amount of original data to
cover. For example, by setting n_resamples and coverage:
[< ChData | 1250 samples >, < ChData | 1250 samples >, < ChData | 1250 samples >]
or by setting n_samples and coverage:
[< ChData | 1000 samples >, < ChData | 1000 samples >, < ChData | 1000 samples >]
Finally, this function can be used to resample Epochs.
[< ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >, < ChData | 150 samples >]
Total running time of the script: (0 minutes 1.152 seconds)
Estimated memory usage: 215 MB