Created
July 23, 2017 17:58
-
-
Save wmvanvliet/a96a9b883cf492bed807559d51abe310 to your computer and use it in GitHub Desktop.
Testing PySurfer vector data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
============================== | |
Plotting the full MNE solution | |
============================== | |
The source space that is used for the inverse computation defines a set of | |
dipoles, distributed across the cortex. When visualizing a source estimate, it | |
is sometimes useful to show the dipole directions, as well as their estimated | |
magnitude. | |
""" | |
# Author: Marijn van Vliet <[email protected]> | |
# | |
# License: BSD (3-clause) | |
import mne | |
from mne.datasets import sample | |
from mne.minimum_norm import read_inverse_operator, apply_inverse | |
import surfer | |
import numpy as np | |
print(__doc__) | |
data_path = sample.data_path() | |
subjects_dir = data_path + '/subjects' | |
# Read evoked data | |
fname_evoked = data_path + '/MEG/sample/sample_audvis-ave.fif' | |
evoked = mne.read_evokeds(fname_evoked, condition=0, baseline=(None, 0)) | |
# Read inverse solution | |
fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif' | |
inv = read_inverse_operator(fname_inv) | |
# Apply inverse solution, set pick_ori='vector' to obtain a | |
# :class:`mne.VectorSourceEstimate` object | |
snr = 3.0 | |
lambda2 = 1.0 / snr ** 2 | |
stc = apply_inverse(evoked, inv, lambda2, 'dSPM', pick_ori='vector') | |
# Use peak getter to move vizualization to the time point of the peak magnitude | |
_, peak_time = stc.magnitude().get_peak(hemi='lh') | |
# Plot the source estimate | |
# brain = stc.plot(initial_time=peak_time, hemi='lh', subjects_dir=subjects_dir) | |
subject_id, surf = 'sample', 'white' | |
hemi = 'lh' | |
brain = surfer.Brain( | |
subject_id, hemi, surf, size=(800, 800), interaction='terrain', | |
cortex='0.5', alpha=0.5, show_toolbar=True, subjects_dir=subjects_dir | |
) | |
data = stc.lh_data | |
vertices = stc.lh_vertno | |
time = np.linspace(stc.tmin, stc.tmin + data.shape[2] * stc.tstep, | |
data.shape[2], endpoint=False) | |
brain.add_data(data, colormap='hot', vertices=vertices, alpha=0.5, | |
smoothing_steps=5, time=time, hemi=hemi, initial_time=peak_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment