Morph surface source estimate¶
This example demonstrates how to morph an individual subject’s
mne.SourceEstimate to a common reference space. We achieve this using
mne.SourceMorph. Pre-computed data will be morphed based on
a spherical representation of the cortex computed using the spherical
registration of FreeSurfer
(https://surfer.nmr.mgh.harvard.edu/fswiki/SurfaceRegAndTemplates) 1. This
transform will be used to morph the surface vertices of the subject towards the
reference vertices. Here we will use ‘fsaverage’ as a reference space (see
The transformation will be applied to the surface source estimate. A plot
depicting the successful morph will be created for the spherical and inflated
surface representation of
'fsaverage', overlaid with the morphed surface
Greve D. N., Van der Haegen L., Cai Q., Stufflebeam S., Sabuncu M. R., Fischl B., Brysbaert M. A Surface-based Analysis of Language Lateralization and Cortical Asymmetry. Journal of Cognitive Neuroscience 25(9), 1477-1492, 2013.
For background information about morphing see Morphing and averaging source estimates.
# Author: Tommy Clausner <email@example.com> # # License: BSD (3-clause) import os import mne from mne.datasets import sample print(__doc__)
Load example data
Setting up SourceMorph for SourceEstimate¶
In MNE surface source estimates represent the source space simply as
lists of vertices (see
The SourceEstimate data structure).
This list can either be obtained from
mne.SourceSpaces (src) or from the
Since the default
spacing (resolution of surface mesh) is
subject_to is set to ‘fsaverage’,
mne.SourceMorph will use
fsaverage vertices to morph, which are the special
[np.arange(10242)] * 2.
This is not generally true for other subjects! The set of vertices
fsaverage with ico-5 spacing was designed to be
special. ico-5 spacings for other subjects (or other spacings
for fsaverage) must be calculated and will not be consecutive
If src was not defined, the morph will actually not be precomputed, because we lack the vertices from that we want to compute. Instead the morph will be set up and when applying it, the actual transformation will be computed on the fly.
Initialize SourceMorph for SourceEstimate
Apply morph to (Vector) SourceEstimate¶
The morph will be applied to the source estimate data, by giving it as the first argument to the morph we computed above.
# Define plotting parameters surfer_kwargs = dict( hemi='lh', subjects_dir=subjects_dir, clim=dict(kind='value', lims=[8, 12, 15]), views='lateral', initial_time=0.09, time_unit='s', size=(800, 800), smoothing_steps=5) # As spherical surface brain = stc_fsaverage.plot(surface='sphere', **surfer_kwargs) # Add title brain.add_text(0.1, 0.9, 'Morphed to fsaverage (spherical)', 'title', font_size=16)
As inflated surface
Reading and writing SourceMorph from and to disk¶
An instance of SourceMorph can be saved, by calling
This method allows for specification of a filename under which the
will be save in “.h5” format. If no file extension is provided, “-morph.h5”
will be appended to the respective defined filename:
Reading a saved source morph can be achieved by using
Once the environment is set up correctly, no information such as
subjects_dir must be provided, since it can be
inferred from the data and use morph to ‘fsaverage’ by default. SourceMorph
can further be used without creating an instance and assigning it to a
mne.SourceMorph.apply() can be
easily chained into a handy one-liner. Taking this together the shortest
possible way to morph data directly would be:
For more examples, check out examples using SourceMorph.apply.
Total running time of the script: ( 0 minutes 24.921 seconds)
Estimated memory usage: 17 MB