Reading epochs from a raw FIF fileΒΆ

This script shows how to read the epochs from a raw file given a list of events. For illustration, we compute the evoked responses for both MEG and EEG data by averaging all the epochs.

# Authors: Alexandre Gramfort <>
#          Matti Hamalainen <>
# License: BSD (3-clause)

import mne
from mne import io
from mne.datasets import sample


data_path = sample.data_path()

Set parameters

raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
event_id, tmin, tmax = 1, -0.2, 0.5

# Setup for reading the raw data
raw = io.Raw(raw_fname)
events = mne.read_events(event_fname)

# Set up pick list: EEG + MEG - bad channels (modify to your needs)['bads'] += ['MEG 2443', 'EEG 053']  # bads + 2 more
picks = mne.pick_types(, meg=True, eeg=False, stim=True, eog=True,

# Read epochs
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
                    picks=picks, baseline=(None, 0), preload=True,
                    reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))

evoked = epochs.average()  # average epochs to get the evoked response

Show result


Total running time of the script: (0 minutes 1.515 seconds)

Download Python source code: