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

Function _make_morph_map_hemi

mne/morph_map.py:207–247  ·  view source on GitHub ↗

Construct morph map for one hemisphere.

(subject_from, subject_to, subjects_dir, reg_from, reg_to)

Source from the content-addressed store, hash-verified

205
206
207def _make_morph_map_hemi(subject_from, subject_to, subjects_dir, reg_from, reg_to):
208 """Construct morph map for one hemisphere."""
209 # add speedy short-circuit for self-maps
210 if subject_from == subject_to and reg_from == reg_to:
211 fname = subjects_dir / subject_from / "surf" / reg_from
212 n_pts = len(read_surface(fname, verbose=False)[0])
213 return _eye_array(n_pts, format="csr")
214
215 # load surfaces and normalize points to be on unit sphere
216 fname = subjects_dir / subject_from / "surf" / reg_from
217 from_rr, from_tri = read_surface(fname, verbose=False)
218 fname = subjects_dir / subject_to / "surf" / reg_to
219 to_rr = read_surface(fname, verbose=False)[0]
220 _normalize_vectors(from_rr)
221 _normalize_vectors(to_rr)
222
223 # from surface: get nearest neighbors, find triangles for each vertex
224 nn_pts_idx = _compute_nearest(from_rr, to_rr, method="KDTree")
225 from_pt_tris = _triangle_neighbors(from_tri, len(from_rr))
226 from_pt_tris = [from_pt_tris[pt_idx].astype(int) for pt_idx in nn_pts_idx]
227 from_pt_lens = np.cumsum([0] + [len(x) for x in from_pt_tris])
228 from_pt_tris = np.concatenate(from_pt_tris)
229 assert from_pt_tris.ndim == 1
230 assert from_pt_lens[-1] == len(from_pt_tris)
231
232 # find triangle in which point lies and assoc. weights
233 tri_inds = []
234 weights = []
235 tri_geom = _get_tri_supp_geom(dict(rr=from_rr, tris=from_tri))
236 weights, tri_inds = _find_nearest_tri_pts(
237 to_rr, from_pt_tris, from_pt_lens, run_all=False, reproject=False, **tri_geom
238 )
239
240 nn_idx = from_tri[tri_inds]
241 weights = np.array(weights)
242
243 row_ind = np.repeat(np.arange(len(to_rr)), 3)
244 this_map = csr_array(
245 (weights.ravel(), (row_ind, nn_idx.ravel())), shape=(len(to_rr), len(from_rr))
246 )
247 return this_map

Callers 2

_make_morph_mapFunction · 0.85

Calls 7

read_surfaceFunction · 0.85
_eye_arrayFunction · 0.85
_normalize_vectorsFunction · 0.85
_compute_nearestFunction · 0.85
_triangle_neighborsFunction · 0.85
_get_tri_supp_geomFunction · 0.85
_find_nearest_tri_ptsFunction · 0.85

Tested by 1