We first define a set of Epochs from events and a raw file. Then we estimate the noise covariance of prestimulus data, a.k.a. baseline.
# Author: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
#
# License: BSD (3-clause)
import mne
from mne import io
from mne.datasets import sample
print(__doc__)
data_path = sample.data_path()
fname = data_path + '/MEG/sample/sample_audvis_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
raw = io.Raw(fname)
Set parameters
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
# Setup for reading the raw data
raw = io.Raw(raw_fname)
events = mne.read_events(event_fname)
# Set up pick list: EEG + STI 014 - bad channels (modify to your needs)
include = [] # or stim channels ['STI 014']
raw.info['bads'] += ['EEG 053'] # bads + 1 more
# pick EEG channels
picks = mne.pick_types(raw.info, meg=True, eeg=True, stim=False, eog=True,
include=include, exclude='bads')
# Read epochs, with proj off by default so we can plot either way later
reject = dict(grad=4000e-13, mag=4e-12, eeg=80e-6, eog=150e-6)
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject, proj=False)
# Compute the covariance on baseline
cov = mne.compute_covariance(epochs, tmin=None, tmax=0)
print(cov)
Out:
Too few samples (required : 1825 got : 1550), covariance estimate may be unreliable
<Covariance | size : 364 x 364, n_samples : 1550, data : [[ 2.17049386e-23 4.70340456e-24 3.87826687e-25 ..., 1.02882600e-17
7.56134018e-18 1.27495888e-17]
[ 4.70340456e-24 5.62172415e-24 1.82036107e-25 ..., 2.98237933e-18
2.32035507e-18 4.82006907e-18]
[ 3.87826687e-25 1.82036107e-25 7.61915421e-26 ..., -1.06502799e-19
-1.18416466e-19 9.10651465e-20]
...,
[ 1.02882600e-17 2.98237933e-18 -1.06502799e-19 ..., 4.10264374e-11
3.89758876e-11 3.34306668e-11]
[ 7.56134018e-18 2.32035507e-18 -1.18416466e-19 ..., 3.89758876e-11
4.09615144e-11 3.11633167e-11]
[ 1.27495888e-17 4.82006907e-18 9.10651465e-20 ..., 3.34306668e-11
3.11633167e-11 3.24035358e-11]]>
Show covariance
mne.viz.plot_cov(cov, raw.info, colorbar=True, proj=True)
# try setting proj to False to see the effect
Total running time of the script: (0 minutes 3.727 seconds)
plot_estimate_covariance_matrix_baseline.py
plot_estimate_covariance_matrix_baseline.ipynb