Skip to content

Instantly share code, notes, and snippets.

@larsoner
Created April 5, 2016 15:20
Show Gist options
  • Save larsoner/791883ef7095f3557bbac9d86d53d9c5 to your computer and use it in GitHub Desktop.
Save larsoner/791883ef7095f3557bbac9d86d53d9c5 to your computer and use it in GitHub Desktop.
Time averaged evoked
# -*- coding: utf-8 -*-
"""
Example for creating a time-averaged Evoked file
"""
import numpy as np
import mne
data_path = mne.datasets.sample.data_path()
fname = data_path + '/MEG/sample/sample_audvis-ave.fif'
evoked = mne.read_evokeds(fname, condition='Right Auditory')
tmin, tmax = 0.09, 0.11
evoked.crop(tmin, tmax)
data = np.mean(evoked.data, axis=1)
assert data.shape == (376,) # taking the average collapses over the dimension
data = data[:, np.newaxis] # so we need to put it back
assert data.shape == (376, 1)
# Now we can construct a new Evoked object, and do whatever we want
# (including save it to disk for use with Xfit)
comment = evoked.comment + ' ave %s-%s' % (tmin, tmax)
evoked_ave = mne.EvokedArray(data, evoked.info, tmin, comment=comment,
nave=evoked.nave)
evoked_ave.plot_topomap(times=tmin)
evoked_ave.save('test-ave.fif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment