eelbrain.morph_source_space
- eelbrain.morph_source_space(data, subject_to=None, vertices_to=None, morph_mat=None, copy=False, parc=True, xhemi=False, mask=None)
Morph source estimate to a different MRI subject
- Parameters
data (Union[NDVar, SourceSpace]) – NDVar with SourceSpace dimension.
subject_to (str) – Name of the subject on which to morph (by default this is the same as the current subject for
xhemi
morphing).vertices_to (list of array of int | 'lh' | 'rh') – The vertices on the destination subject’s brain. If
data
contains a whole source space, vertices_to can be automatically loaded, although providing them as argument can speed up processing by a second or two. Use ‘lh’ or ‘rh’ to target vertices from only one hemisphere.morph_mat (spmatrix) – The morphing matrix. If
data
contains a whole source space, the morph matrix can be automatically loaded, although providing a cached matrix can speed up processing by a second or two.copy (bool) – Make sure that the data of
morphed_ndvar
is separate fromdata
(default False).parc (Union[bool, str]) – Parcellation for target source space. The default is to keep the parcellation from
data
. Set toFalse
to load no parcellation. If the annotation files are missing for the target subject an IOError is raised.xhemi (bool) – Mirror hemispheres (i.e., project data from the left hemisphere to the right hemisphere and vice versa).
mask (bool) – Restrict output to known sources. If the parcellation of
data
is retained keep only sources with labels contained indata
, otherwise remove only sourves with”unknown-*”
label (default is True unlessvertices_to
is specified).
- Returns
morphed_ndvar – NDVar morphed to the destination subject.
- Return type
See also
xhemi
morph data from both hemisphere to one for comparing hemispheres
Notes
This function is used to make sure a number of different NDVars are defined on the same MRI subject and handles scaled MRIs efficiently. If the MRI subject on which
data
is defined is a scaled copy ofsubject_to
, by default a shallow copy ofdata
is returned. That means that it is not safe to assume thatmorphed_ndvar
can be modified in place without alteringdata
. To make sure the date of the output is independent from the data of the input, set the argumentcopy=True
.Examples
Generate a symmetric ROI based on a test result (
res
):# Generate a mask based on significance mask = res.p.min('time') <= 0.05 # store the vertices for which we want the end result fsa_vertices = mask.source.vertices # morphing is easier with a complete source space mask = complete_source_space(mask) # Use a parcellation that is available for the ``fsaverage_sym`` brain mask = set_parc(mask, 'aparc') # morph both hemispheres to the left hemisphere mask_from_lh, mask_from_rh = xhemi(mask) # take the union; morphing interpolates, so re-cast values to booleans mask_lh = (mask_from_lh > 0) | (mask_from_rh > 0) # morph the new ROI to the right hemisphere mask_rh = morph_source_space(mask_lh, vertices_to=[[], mask_lh.source.vertices[0]], xhemi=True) # cast back to boolean mask_rh = mask_rh > 0 # combine the two hemispheres mask_sym = concatenate([mask_lh, mask_rh], 'source') # morph the result back to the source brain (fsaverage) mask = morph_source_space(mask_sym, 'fsaverage', fsa_vertices) # convert to boolean mask (morphing involves interpolation, so the output is in floats) mask = round(mask).astype(bool)