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,
)
| 2953 | |
| 2954 | @verbose |
| 2955 | def 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. |