Compute source power using DICS beamfomer

Compute a Dynamic Imaging of Coherent Sources (DICS) [1] filter from single-trial activity to estimate source power across a frequency band.

References

[1]Gross et al. Dynamic imaging of coherent sources: Studying neural interactions in the human brain. PNAS (2001) vol. 98 (2) pp. 694-699
# Author: Marijn van Vliet <w.m.vanvliet@gmail.com>
#         Roman Goj <roman.goj@gmail.com>
#         Denis Engemann <denis.engemann@gmail.com>
#
# License: BSD (3-clause)
import numpy as np
import mne
from mne.datasets import sample
from mne.time_frequency import csd_morlet
from mne.beamformer import make_dics, apply_dics_csd

print(__doc__)

data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_raw-eve.fif'
fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif'
subjects_dir = data_path + '/subjects'

Reading the raw data:

raw = mne.io.read_raw_fif(raw_fname)
raw.info['bads'] = ['MEG 2443']  # 1 bad MEG channel

# Set picks
picks = mne.pick_types(raw.info, meg=True, eeg=False, eog=False,
                       stim=False, exclude='bads')

# Read epochs
event_id, tmin, tmax = 1, -0.2, 0.5
events = mne.read_events(event_fname)
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))
evoked = epochs.average()

# Read forward operator
forward = mne.read_forward_solution(fname_fwd)

Out:

Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
    Range : 25800 ... 192599 =     42.956 ...   320.670 secs
Ready.
Current compensation grade : 0
72 matching events found
Applying baseline correction (mode: mean)
Not setting metadata
Created an SSP operator (subspace dimension = 3)
3 projection items activated
Loading data for 72 events and 421 original time points ...
    Rejecting  epoch based on MAG : ['MEG 1711']
1 bad epochs dropped
Reading forward solution from /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif...
    Reading a source space...
    Computing patch statistics...
    Patch information added...
    Distance information added...
    [done]
    Reading a source space...
    Computing patch statistics...
    Patch information added...
    Distance information added...
    [done]
    2 source spaces read
    Desired named matrix (kind = 3523) not available
    Read MEG forward solution (7498 sources, 306 channels, free orientations)
    Desired named matrix (kind = 3523) not available
    Read EEG forward solution (7498 sources, 60 channels, free orientations)
    MEG and EEG forward solutions combined
    Source spaces transformed to the forward solution coordinate frame

Computing the cross-spectral density matrix at 4 evenly spaced frequencies from 6 to 10 Hz. We use a decim value of 20 to speed up the computation in this example at the loss of accuracy.

csd = csd_morlet(epochs, tmin=0, tmax=0.5, decim=20,
                 frequencies=np.linspace(6, 10, 4))

# Compute DICS spatial filter and estimate source power.
filters = make_dics(epochs.info, forward, csd, reg=0.5)
stc, freqs = apply_dics_csd(csd, filters)

message = 'DICS source power in the 8-12 Hz frequency band'
brain = stc.plot(surface='inflated', hemi='rh', subjects_dir=subjects_dir,
                 time_label=message)
../../_images/sphx_glr_plot_dics_source_power_001.png

Out:

Computing cross-spectral density from epochs...
    Computing CSD matrix for epoch 1
    Computing CSD matrix for epoch 2
    Computing CSD matrix for epoch 3
    Computing CSD matrix for epoch 4
    Computing CSD matrix for epoch 5
    Computing CSD matrix for epoch 6
    Computing CSD matrix for epoch 7
    Computing CSD matrix for epoch 8
    Computing CSD matrix for epoch 9
    Computing CSD matrix for epoch 10
    Computing CSD matrix for epoch 11
    Computing CSD matrix for epoch 12
    Computing CSD matrix for epoch 13
    Computing CSD matrix for epoch 14
    Computing CSD matrix for epoch 15
    Computing CSD matrix for epoch 16
    Computing CSD matrix for epoch 17
    Computing CSD matrix for epoch 18
    Computing CSD matrix for epoch 19
    Computing CSD matrix for epoch 20
    Computing CSD matrix for epoch 21
    Computing CSD matrix for epoch 22
    Computing CSD matrix for epoch 23
    Computing CSD matrix for epoch 24
    Computing CSD matrix for epoch 25
    Computing CSD matrix for epoch 26
    Computing CSD matrix for epoch 27
    Computing CSD matrix for epoch 28
    Computing CSD matrix for epoch 29
    Computing CSD matrix for epoch 30
    Computing CSD matrix for epoch 31
    Computing CSD matrix for epoch 32
    Computing CSD matrix for epoch 33
    Computing CSD matrix for epoch 34
    Computing CSD matrix for epoch 35
    Computing CSD matrix for epoch 36
    Computing CSD matrix for epoch 37
    Computing CSD matrix for epoch 38
    Computing CSD matrix for epoch 39
    Computing CSD matrix for epoch 40
    Computing CSD matrix for epoch 41
    Computing CSD matrix for epoch 42
    Computing CSD matrix for epoch 43
    Computing CSD matrix for epoch 44
    Computing CSD matrix for epoch 45
    Computing CSD matrix for epoch 46
    Computing CSD matrix for epoch 47
    Computing CSD matrix for epoch 48
    Computing CSD matrix for epoch 49
    Computing CSD matrix for epoch 50
    Computing CSD matrix for epoch 51
    Computing CSD matrix for epoch 52
    Computing CSD matrix for epoch 53
    Computing CSD matrix for epoch 54
    Computing CSD matrix for epoch 55
    Computing CSD matrix for epoch 56
    Computing CSD matrix for epoch 57
    Computing CSD matrix for epoch 58
    Computing CSD matrix for epoch 59
    Computing CSD matrix for epoch 60
    Computing CSD matrix for epoch 61
    Computing CSD matrix for epoch 62
    Computing CSD matrix for epoch 63
    Computing CSD matrix for epoch 64
    Computing CSD matrix for epoch 65
    Computing CSD matrix for epoch 66
    Computing CSD matrix for epoch 67
    Computing CSD matrix for epoch 68
    Computing CSD matrix for epoch 69
    Computing CSD matrix for epoch 70
    Computing CSD matrix for epoch 71
[done]
    305 out of 366 channels remain after picking
Computing DICS spatial filters...
    computing DICS spatial filter at 6.0Hz (1/4)
    computing DICS spatial filter at 7.333333333333333Hz (2/4)
    computing DICS spatial filter at 8.666666666666666Hz (3/4)
    computing DICS spatial filter at 10.0Hz (4/4)
Computing DICS source power...
    applying DICS spatial filter at 6.0Hz (1/4)
    applying DICS spatial filter at 7.333333333333333Hz (2/4)
    applying DICS spatial filter at 8.666666666666666Hz (3/4)
    applying DICS spatial filter at 10.0Hz (4/4)
[done]

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

Gallery generated by Sphinx-Gallery