The Evoked data structure: evoked/averaged data

The Evoked data structure is mainly used for storing averaged data over trials. In MNE the evoked objects are usually created by averaging epochs data with mne.Epochs.average().

# sphinx_gallery_thumbnail_number = 2

import os.path as op

import matplotlib.pyplot as plt
import mne

Here for convenience we read the evoked dataset from a file.

data_path = mne.datasets.sample.data_path()
fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave.fif')
evokeds = mne.read_evokeds(fname, baseline=(None, 0), proj=True)
print(evokeds)

Out:

Reading /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-ave.fif ...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Found the data of interest:
        t =    -199.80 ...     499.49 ms (Left Auditory)
        0 CTF compensation matrices available
        nave = 55 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
Applying baseline correction (mode: mean)
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Found the data of interest:
        t =    -199.80 ...     499.49 ms (Right Auditory)
        0 CTF compensation matrices available
        nave = 61 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
Applying baseline correction (mode: mean)
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Found the data of interest:
        t =    -199.80 ...     499.49 ms (Left visual)
        0 CTF compensation matrices available
        nave = 67 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
Applying baseline correction (mode: mean)
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Found the data of interest:
        t =    -199.80 ...     499.49 ms (Right visual)
        0 CTF compensation matrices available
        nave = 58 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
Applying baseline correction (mode: mean)
[<Evoked  |  'Left Auditory' (mean, N=55), [-0.1998, 0.49949] sec, 376 ch, ~4.9 MB>, <Evoked  |  'Right Auditory' (mean, N=61), [-0.1998, 0.49949] sec, 376 ch, ~4.9 MB>, <Evoked  |  'Left visual' (mean, N=67), [-0.1998, 0.49949] sec, 376 ch, ~4.9 MB>, <Evoked  |  'Right visual' (mean, N=58), [-0.1998, 0.49949] sec, 376 ch, ~4.9 MB>]

Notice that the reader function returned a list of evoked instances. This is because you can store multiple categories into a single file. Here we have categories of ['Left Auditory', 'Right Auditory', 'Left Visual', 'Right Visual']. We can also use condition parameter to read in only one category.

evoked = mne.read_evokeds(fname, condition='Left Auditory')
evoked.apply_baseline((None, 0)).apply_proj()
print(evoked)

Out:

Reading /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-ave.fif ...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Found the data of interest:
        t =    -199.80 ...     499.49 ms (Left Auditory)
        0 CTF compensation matrices available
        nave = 55 - aspect type = 100
Projections have already been applied. Setting proj attribute to True.
No baseline correction applied
Applying baseline correction (mode: mean)
Projections have already been applied. Setting proj attribute to True.
<Evoked  |  'Left Auditory' (mean, N=55), [-0.1998, 0.49949] sec, 376 ch, ~4.9 MB>

If you’re gone through the tutorials of raw and epochs datasets, you’re probably already familiar with the Info attribute. There is nothing new or special with the evoked.info. All the relevant info is still there.

print(evoked.info)
print(evoked.times)

Out:

<Info | 20 non-empty fields
    bads : list | MEG 2443, EEG 053
    ch_names : list | MEG 0113, MEG 0112, MEG 0111, MEG 0122, MEG 0123, ...
    chs : list | 376 items (GRAD: 204, MAG: 102, STIM: 9, EEG: 60, EOG: 1)
    comps : list | 0 items
    custom_ref_applied : bool | False
    dev_head_t : Transform | 3 items
    dig : list | 146 items (3 Cardinal, 4 HPI, 61 EEG, 78 Extra)
    events : list | 0 items
    file_id : dict | 4 items
    highpass : float | 0.10000000149011612 Hz
    hpi_meas : list | 1 items
    hpi_results : list | 1 items
    lowpass : float | 40.0 Hz
    maxshield : bool | False
    meas_date : tuple | 2002-12-03 19:01:10 GMT
    meas_id : dict | 4 items
    nchan : int | 376
    proc_history : list | 0 items
    projs : list | PCA-v1: on, PCA-v2: on, PCA-v3: on, ...
    sfreq : float | 600.614990234375 Hz
    acq_pars : NoneType
    acq_stim : NoneType
    ctf_head_t : NoneType
    description : NoneType
    dev_ctf_t : NoneType
    experimenter : NoneType
    gantry_angle : NoneType
    hpi_subsystem : NoneType
    kit_system_id : NoneType
    line_freq : NoneType
    proj_id : NoneType
    proj_name : NoneType
    subject_info : NoneType
    xplotter_layout : NoneType
>
[-0.199795 -0.19813  -0.196465 -0.1948   -0.193135 -0.19147  -0.189805
 -0.18814  -0.186476 -0.184811 -0.183146 -0.181481 -0.179816 -0.178151
 -0.176486 -0.174821 -0.173156 -0.171491 -0.169826 -0.168161 -0.166496
 -0.164831 -0.163166 -0.161501 -0.159836 -0.158171 -0.156506 -0.154841
 -0.153176 -0.151511 -0.149846 -0.148181 -0.146516 -0.144852 -0.143187
 -0.141522 -0.139857 -0.138192 -0.136527 -0.134862 -0.133197 -0.131532
 -0.129867 -0.128202 -0.126537 -0.124872 -0.123207 -0.121542 -0.119877
 -0.118212 -0.116547 -0.114882 -0.113217 -0.111552 -0.109887 -0.108222
 -0.106557 -0.104892 -0.103228 -0.101563 -0.099898 -0.098233 -0.096568
 -0.094903 -0.093238 -0.091573 -0.089908 -0.088243 -0.086578 -0.084913
 -0.083248 -0.081583 -0.079918 -0.078253 -0.076588 -0.074923 -0.073258
 -0.071593 -0.069928 -0.068263 -0.066598 -0.064933 -0.063268 -0.061604
 -0.059939 -0.058274 -0.056609 -0.054944 -0.053279 -0.051614 -0.049949
 -0.048284 -0.046619 -0.044954 -0.043289 -0.041624 -0.039959 -0.038294
 -0.036629 -0.034964 -0.033299 -0.031634 -0.029969 -0.028304 -0.026639
 -0.024974 -0.023309 -0.021644 -0.01998  -0.018315 -0.01665  -0.014985
 -0.01332  -0.011655 -0.00999  -0.008325 -0.00666  -0.004995 -0.00333
 -0.001665  0.        0.001665  0.00333   0.004995  0.00666   0.008325
  0.00999   0.011655  0.01332   0.014985  0.01665   0.018315  0.01998
  0.021644  0.023309  0.024974  0.026639  0.028304  0.029969  0.031634
  0.033299  0.034964  0.036629  0.038294  0.039959  0.041624  0.043289
  0.044954  0.046619  0.048284  0.049949  0.051614  0.053279  0.054944
  0.056609  0.058274  0.059939  0.061604  0.063268  0.064933  0.066598
  0.068263  0.069928  0.071593  0.073258  0.074923  0.076588  0.078253
  0.079918  0.081583  0.083248  0.084913  0.086578  0.088243  0.089908
  0.091573  0.093238  0.094903  0.096568  0.098233  0.099898  0.101563
  0.103228  0.104892  0.106557  0.108222  0.109887  0.111552  0.113217
  0.114882  0.116547  0.118212  0.119877  0.121542  0.123207  0.124872
  0.126537  0.128202  0.129867  0.131532  0.133197  0.134862  0.136527
  0.138192  0.139857  0.141522  0.143187  0.144852  0.146516  0.148181
  0.149846  0.151511  0.153176  0.154841  0.156506  0.158171  0.159836
  0.161501  0.163166  0.164831  0.166496  0.168161  0.169826  0.171491
  0.173156  0.174821  0.176486  0.178151  0.179816  0.181481  0.183146
  0.184811  0.186476  0.18814   0.189805  0.19147   0.193135  0.1948
  0.196465  0.19813   0.199795  0.20146   0.203125  0.20479   0.206455
  0.20812   0.209785  0.21145   0.213115  0.21478   0.216445  0.21811
  0.219775  0.22144   0.223105  0.22477   0.226435  0.2281    0.229764
  0.231429  0.233094  0.234759  0.236424  0.238089  0.239754  0.241419
  0.243084  0.244749  0.246414  0.248079  0.249744  0.251409  0.253074
  0.254739  0.256404  0.258069  0.259734  0.261399  0.263064  0.264729
  0.266394  0.268059  0.269724  0.271388  0.273053  0.274718  0.276383
  0.278048  0.279713  0.281378  0.283043  0.284708  0.286373  0.288038
  0.289703  0.291368  0.293033  0.294698  0.296363  0.298028  0.299693
  0.301358  0.303023  0.304688  0.306353  0.308018  0.309683  0.311348
  0.313013  0.314677  0.316342  0.318007  0.319672  0.321337  0.323002
  0.324667  0.326332  0.327997  0.329662  0.331327  0.332992  0.334657
  0.336322  0.337987  0.339652  0.341317  0.342982  0.344647  0.346312
  0.347977  0.349642  0.351307  0.352972  0.354637  0.356301  0.357966
  0.359631  0.361296  0.362961  0.364626  0.366291  0.367956  0.369621
  0.371286  0.372951  0.374616  0.376281  0.377946  0.379611  0.381276
  0.382941  0.384606  0.386271  0.387936  0.389601  0.391266  0.392931
  0.394596  0.396261  0.397925  0.39959   0.401255  0.40292   0.404585
  0.40625   0.407915  0.40958   0.411245  0.41291   0.414575  0.41624
  0.417905  0.41957   0.421235  0.4229    0.424565  0.42623   0.427895
  0.42956   0.431225  0.43289   0.434555  0.43622   0.437885  0.439549
  0.441214  0.442879  0.444544  0.446209  0.447874  0.449539  0.451204
  0.452869  0.454534  0.456199  0.457864  0.459529  0.461194  0.462859
  0.464524  0.466189  0.467854  0.469519  0.471184  0.472849  0.474514
  0.476179  0.477844  0.479509  0.481173  0.482838  0.484503  0.486168
  0.487833  0.489498  0.491163  0.492828  0.494493  0.496158  0.497823
  0.499488]

The evoked data structure also contains some new attributes easily accessible:

print(evoked.nave)  # Number of averaged epochs.
print(evoked.first)  # First time sample.
print(evoked.last)  # Last time sample.
print(evoked.comment)  # Comment on dataset. Usually the condition.
print(evoked.kind)  # Type of data, either average or standard_error.

Out:

55
-120
300
Left Auditory
average

The data is also easily accessible. Since the evoked data arrays are usually much smaller than raw or epochs datasets, they are preloaded into the memory when the evoked object is constructed. You can access the data as a numpy array.

data = evoked.data
print(data.shape)

Out:

(376, 421)

The data is arranged in an array of shape (n_channels, n_times). Notice that unlike epochs, evoked object does not support indexing. This means that to access the data of a specific channel you must use the data array directly.

print('Data from channel {0}:'.format(evoked.ch_names[10]))
print(data[10])

Out:

Data from channel MEG 0142:
[-5.235651e-13 -4.715851e-13 -3.866832e-13 -2.832736e-13 -1.773061e-13
 -8.406112e-14 -1.619241e-14  1.773812e-14  1.407443e-14 -2.582710e-14
 -9.615224e-14 -1.877146e-13 -2.893758e-13 -3.895842e-13 -4.778133e-13
 -5.457257e-13 -5.879404e-13 -6.023490e-13 -5.899973e-13 -5.546043e-13
 -5.018257e-13 -4.383925e-13 -3.712507e-13 -3.068000e-13 -2.503103e-13
 -2.055422e-13 -1.745808e-13 -1.578496e-13 -1.542647e-13 -1.614919e-13
 -1.762511e-13 -1.946558e-13 -2.125576e-13 -2.258965e-13 -2.310463e-13
 -2.251524e-13 -2.064490e-13 -1.745199e-13 -1.304789e-13 -7.701935e-14
 -1.830082e-14  4.035216e-14  9.293888e-14  1.334294e-13  1.565096e-13
  1.583342e-13  1.371879e-13  9.394253e-14  3.222291e-14 -4.178000e-14
 -1.198599e-13 -1.926720e-13 -2.508426e-13 -2.861734e-13 -2.927839e-13
 -2.680194e-13 -2.129867e-13 -1.326117e-13 -3.518716e-14  6.855795e-14
  1.667630e-13  2.479477e-13  3.025306e-13  3.241493e-13  3.105813e-13
  2.641396e-13  1.914627e-13  1.027209e-13  1.032876e-14 -7.266278e-14
 -1.342813e-13 -1.652262e-13 -1.601163e-13 -1.182263e-13 -4.360927e-14
  5.540973e-14  1.672986e-13  2.787939e-13  3.765885e-13  4.489985e-13
  4.873959e-13  4.872191e-13  4.484436e-13  3.754612e-13  2.764153e-13
  1.620880e-13  4.451321e-14 -6.449603e-14 -1.547115e-13 -2.185706e-13
 -2.518589e-13 -2.539262e-13 -2.274493e-13 -1.778014e-13 -1.121468e-13
 -3.840018e-14  3.580084e-14  1.039774e-13  1.614459e-13  2.056498e-13
  2.361820e-13  2.545225e-13  2.635718e-13  2.670516e-13  2.688846e-13
  2.726200e-13  2.809912e-13  2.956254e-13  3.169365e-13  3.441782e-13
  3.756330e-13  4.088931e-13  4.411945e-13  4.697557e-13  4.920975e-13
  5.063139e-13  5.112829e-13  5.068072e-13  4.936819e-13  4.736819e-13
  4.494698e-13  4.244188e-13  4.023535e-13  3.872137e-13  3.826622e-13
  3.916645e-13  4.160824e-13  4.563306e-13  5.111545e-13  5.775708e-13
  6.510113e-13  7.256785e-13  7.950997e-13  8.528259e-13  8.932071e-13
  9.121417e-13  9.077029e-13  8.805343e-13  8.339446e-13  7.736663e-13
  7.072720e-13  6.433152e-13  5.902870e-13  5.555255e-13  5.442244e-13
  5.586900e-13  5.979574e-13  6.578480e-13  7.314763e-13  8.101562e-13
  8.846009e-13  9.462546e-13  9.885745e-13  1.008077e-12  1.004990e-12
  9.833974e-13  9.508402e-13  9.173986e-13  8.943729e-13  8.927162e-13
  9.214437e-13  9.862191e-13  1.088336e-12  1.224227e-12  1.385609e-12
  1.560234e-12  1.733196e-12  1.888621e-12  2.011526e-12  2.089629e-12
  2.114862e-12  2.084408e-12  2.001106e-12  1.873194e-12  1.713402e-12
  1.537518e-12  1.362597e-12  1.205041e-12  1.078781e-12  9.937751e-13
  9.550121e-13  9.621096e-13  1.009558e-12  1.087550e-12  1.183286e-12
  1.282580e-12  1.371557e-12  1.438241e-12  1.473843e-12  1.473597e-12
  1.437074e-12  1.367948e-12  1.273266e-12  1.162344e-12  1.045422e-12
  9.322741e-13  8.309415e-13  7.467411e-13  6.816708e-13  6.342679e-13
  5.999359e-13  5.716747e-13  5.411236e-13  4.997744e-13  4.402039e-13
  3.571667e-13  2.484193e-13  1.151706e-13 -3.789132e-14 -2.030009e-13
 -3.700946e-13 -5.278745e-13 -6.650310e-13 -7.714790e-13 -8.394612e-13
 -8.643969e-13 -8.453717e-13 -7.852219e-13 -6.902046e-13 -5.693010e-13
 -4.332369e-13 -2.933441e-13 -1.603935e-13 -4.354340e-14  5.048199e-14
  1.178911e-13  1.579536e-13  1.727605e-13  1.666593e-13  1.454532e-13
  1.154768e-13  8.267560e-14  5.181470e-14  2.591519e-14  5.990161e-15
 -8.896854e-15 -2.126824e-14 -3.462971e-14 -5.272331e-14 -7.875015e-14
 -1.146848e-13 -1.607838e-13 -2.153677e-13 -2.749081e-13 -3.344184e-13
 -3.880908e-13 -4.300931e-13 -4.554126e-13 -4.606248e-13 -4.444756e-13
 -4.081881e-13 -3.554462e-13 -2.920463e-13 -2.252592e-13 -1.629823e-13
 -1.127916e-13 -8.101790e-14 -7.196789e-14 -8.739457e-14 -1.262820e-13
 -1.849757e-13 -2.576357e-13 -3.369531e-13 -4.150323e-13 -4.843265e-13
 -5.384996e-13 -5.731134e-13 -5.860504e-13 -5.776324e-13 -5.504261e-13
 -5.087784e-13 -4.581506e-13 -4.043518e-13 -3.527762e-13 -3.077489e-13
 -2.720611e-13 -2.467515e-13 -2.311465e-13 -2.231432e-13 -2.196773e-13
 -2.173024e-13 -2.127853e-13 -2.036324e-13 -1.884677e-13 -1.672147e-13
 -1.410601e-13 -1.122127e-13 -8.350288e-14 -5.788675e-14 -3.793477e-14
 -2.538616e-14 -2.083349e-14 -2.358878e-14 -3.174736e-14 -4.243813e-14
 -5.222599e-14 -5.759907e-14 -5.547776e-14 -4.365928e-14 -2.114878e-14
  1.167981e-14  5.310496e-14  1.002571e-13  1.494594e-13  1.966598e-13
  2.378876e-13  2.696713e-13  2.893621e-13  2.953253e-13  2.869833e-13
  2.647209e-13  2.296845e-13  1.835217e-13  1.281101e-13  6.533603e-14
 -3.046855e-15 -7.545622e-14 -1.504142e-13 -2.264084e-13 -3.017144e-13
 -3.742339e-13 -4.414044e-13 -5.002161e-13 -5.473619e-13 -5.795196e-13
 -5.937388e-13 -5.878763e-13 -5.610204e-13 -5.138208e-13 -4.486676e-13
 -3.696579e-13 -2.823417e-13 -1.932496e-13 -1.092536e-13 -3.683499e-14
  1.864460e-14  5.357202e-14  6.651644e-14  5.840334e-14  3.239729e-14
 -6.502004e-15 -5.209404e-14 -9.776540e-14 -1.373166e-13 -1.657190e-13
 -1.796918e-13 -1.780256e-13 -1.616073e-13 -1.331519e-13 -9.668924e-14
 -5.688917e-14 -1.833179e-14  1.516021e-14  4.103029e-14  5.825789e-14
  6.736236e-14  7.014651e-14  6.923893e-14  6.751963e-14  6.754152e-14
  7.104803e-14  7.868235e-14  8.994021e-14  1.033746e-13  1.170227e-13
  1.289675e-13  1.379374e-13  1.438147e-13  1.479559e-13  1.532348e-13
  1.637826e-13  1.844356e-13  2.199681e-13  2.742232e-13  3.492756e-13
  4.447805e-13  5.576255e-13  6.819692e-13  8.096965e-13  9.312467e-13
  1.036721e-12  1.117115e-12  1.165511e-12  1.178043e-12  1.154495e-12
  1.098433e-12  1.016828e-12  9.192240e-13  8.165449e-13  7.197229e-13
  6.383235e-13  5.793692e-13  5.465296e-13  5.397858e-13  5.556147e-13
  5.876568e-13  6.277632e-13  6.672542e-13  6.982055e-13  7.145637e-13
  7.129247e-13  6.928750e-13  6.568426e-13  6.095082e-13  5.568706e-13
  5.051326e-13  4.595881e-13  4.236925e-13  3.984712e-13  3.823531e-13
  3.714608e-13  3.603082e-13  3.427871e-13  3.132883e-13  2.677695e-13
  2.045996e-13  1.250395e-13  3.327540e-14 -6.400490e-14 -1.584369e-13
 -2.410838e-13]

In the same vein, we can quickly extract (and, e.g., plot) the GFP as the standard deviation across channels, here shown just for EEG.

gfp = evoked.copy().pick_types(eeg=True, meg=False).data.std(axis=0)
fig, ax = plt.subplots(1)
ax.plot(evoked.times, gfp / 1e6)  # scale to uV
ax.set(xlabel='Time (sec)', ylabel='GFP (uV)')
fig.tight_layout()
../../_images/sphx_glr_plot_object_evoked_001.png

If you want to import evoked data from some other system and you have it in a numpy array you can use mne.EvokedArray for that. All you need is the data and some info about the evoked data. For more information, see Creating MNE’s data structures from scratch.

evoked = mne.EvokedArray(data, evoked.info, tmin=evoked.times[0])
evoked.plot(time_unit='s')
../../_images/sphx_glr_plot_object_evoked_002.png

To write an evoked dataset to a file, use the mne.Evoked.save() method. To save multiple categories to a single file, see mne.write_evokeds().

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

Estimated memory usage: 8 MB

Gallery generated by Sphinx-Gallery