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

Function _read_morph_map

mne/morph_map.py:115–146  ·  view source on GitHub ↗

Read a morph map from disk.

(fname, subject_from, subject_to)

Source from the content-addressed store, hash-verified

113
114
115def _read_morph_map(fname, subject_from, subject_to):
116 """Read a morph map from disk."""
117 f, tree, _ = fiff_open(fname)
118 with f as fid:
119 # Locate all maps
120 maps = dir_tree_find(tree, FIFF.FIFFB_MNE_MORPH_MAP)
121 if len(maps) == 0:
122 raise ValueError("Morphing map data not found")
123
124 # Find the correct ones
125 left_map = None
126 right_map = None
127 for m in maps:
128 tag = find_tag(fid, m, FIFF.FIFF_MNE_MORPH_MAP_FROM)
129 if tag.data == subject_from:
130 tag = find_tag(fid, m, FIFF.FIFF_MNE_MORPH_MAP_TO)
131 if tag.data == subject_to:
132 # Names match: which hemishere is this?
133 tag = find_tag(fid, m, FIFF.FIFF_MNE_HEMI)
134 if tag.data == FIFF.FIFFV_MNE_SURF_LEFT_HEMI:
135 tag = find_tag(fid, m, FIFF.FIFF_MNE_MORPH_MAP)
136 left_map = tag.data
137 logger.info(" Left-hemisphere map read.")
138 elif tag.data == FIFF.FIFFV_MNE_SURF_RIGHT_HEMI:
139 tag = find_tag(fid, m, FIFF.FIFF_MNE_MORPH_MAP)
140 right_map = tag.data
141 logger.info(" Right-hemisphere map read.")
142
143 if left_map is None or right_map is None:
144 raise ValueError(f"Could not find both hemispheres in {fname}")
145
146 return left_map, right_map
147
148
149def _write_morph_map(fname, subject_from, subject_to, mmap_1, mmap_2):

Callers 1

read_morph_mapFunction · 0.85

Calls 4

fiff_openFunction · 0.85
dir_tree_findFunction · 0.85
find_tagFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected