Created
August 30, 2016 06:30
-
-
Save wmvanvliet/d77450d3dfe2607e9d317612f10e7d25 to your computer and use it in GitHub Desktop.
Example on how to compute the size of a label on the cortex with MNE
This file contains 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
from __future__ import print_function | |
import mne | |
data_path = mne.datasets.sample.data_path() | |
subjects_dir = data_path + '/subjects' | |
subject = 'sample' | |
fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif' | |
# Read the source space. Normally, you would use mne.read_source_spaces for | |
# this, but the sample data does not include a '-src.fif' file. Therefore, in | |
# this example, we take it from the inverse operator. | |
inverse_operator = mne.minimum_norm.read_inverse_operator(fname_inv) | |
src = inverse_operator['src'] # get the source space | |
# Read a label | |
aparc_label_name = 'bankssts-lh' | |
label = mne.read_labels_from_annot(subject, parc='aparc', | |
subjects_dir=subjects_dir, | |
regexp=aparc_label_name)[0] | |
# The source space contains a distance matrix that measures the distance (in | |
# meters) from each vertex to each other vertex. | |
hemi = 0 # Left hemisphere | |
dist = src[hemi]['dist'] | |
# Reduce the distance matrix to only the vertices present in the label | |
label_dist = dist[label.vertices, :][:, label.vertices] | |
# How big is the label? Here, defined as the maximum distance between two | |
# vertices in the label. | |
print('Size of the label:', label_dist.max(), 'm') | |
# Or in milimeters | |
print('Size of the label:', label_dist.max() * 1000, 'mm') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment