MCPcopy
hub / github.com/mne-tools/mne-python / morph_source_spaces

Function morph_source_spaces

mne/source_space/_source_space.py:2955–3040  ·  view source on GitHub ↗

Morph an existing source space to a different subject. .. warning:: This can be used in place of morphing source estimates for multiple subjects, but there may be consequences in terms of dipole topology. Parameters ---------- src_from : instance o

(
    src_from,
    subject_to,
    surf="white",
    subject_from=None,
    subjects_dir=None,
    verbose=None,
)

Source from the content-addressed store, hash-verified

2953
2954@verbose
2955def morph_source_spaces(
2956 src_from,
2957 subject_to,
2958 surf="white",
2959 subject_from=None,
2960 subjects_dir=None,
2961 verbose=None,
2962):
2963 """Morph an existing source space to a different subject.
2964
2965 .. warning:: This can be used in place of morphing source estimates for
2966 multiple subjects, but there may be consequences in terms
2967 of dipole topology.
2968
2969 Parameters
2970 ----------
2971 src_from : instance of SourceSpaces
2972 Surface source spaces to morph.
2973 subject_to : str
2974 The destination subject.
2975 surf : str
2976 The brain surface to use for the new source space.
2977 subject_from : str | None
2978 The "from" subject. For most source spaces this shouldn't need
2979 to be provided, since it is stored in the source space itself.
2980 subjects_dir : path-like | None
2981 Path to ``SUBJECTS_DIR`` if it is not set in the environment.
2982 %(verbose)s
2983
2984 Returns
2985 -------
2986 src : instance of SourceSpaces
2987 The morphed source spaces.
2988
2989 Notes
2990 -----
2991 .. versionadded:: 0.10.0
2992 """
2993 # adapted from mne_make_source_space.c
2994 src_from = _ensure_src(src_from)
2995 subject_from = _ensure_src_subject(src_from, subject_from)
2996 subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
2997 src_out = list()
2998 for fro in src_from:
2999 hemi, idx, id_ = _get_hemi(fro)
3000 to = subjects_dir / subject_to / "surf" / f"{hemi}.{surf}"
3001 logger.info(f"Reading destination surface {to}")
3002 to = read_surface(to, return_dict=True, verbose=False)[-1]
3003 complete_surface_info(to, copy=False)
3004 # Now we morph the vertices to the destination
3005 # The C code does something like this, but with a nearest-neighbor
3006 # mapping instead of the weighted one::
3007 #
3008 # >>> mm = read_morph_map(subject_from, subject_to, subjects_dir)
3009 #
3010 # Here we use a direct NN calculation, since picking the max from the
3011 # existing morph map (which naively one might expect to be equivalent)
3012 # differs for ~3% of vertices.

Callers 2

test_morph_source_spacesFunction · 0.90

Calls 12

_ensure_srcFunction · 0.85
_ensure_src_subjectFunction · 0.85
get_subjects_dirFunction · 0.85
_get_hemiFunction · 0.85
read_surfaceFunction · 0.85
complete_surface_infoFunction · 0.85
_get_vertex_map_nnFunction · 0.85
_get_call_lineFunction · 0.85
SourceSpacesClass · 0.85
infoMethod · 0.80
updateMethod · 0.45
appendMethod · 0.45

Tested by 2

test_morph_source_spacesFunction · 0.72