Get nearest vertices from one subject to another.
(vertices_from, subject_from, subject_to, subjects_dir=None)
| 323 | |
| 324 | |
| 325 | def _compute_sparse_morph(vertices_from, subject_from, subject_to, subjects_dir=None): |
| 326 | """Get nearest vertices from one subject to another.""" |
| 327 | from scipy import sparse |
| 328 | |
| 329 | maps = read_morph_map(subject_to, subject_from, subjects_dir) |
| 330 | cnt = 0 |
| 331 | vertices = list() |
| 332 | cols = list() |
| 333 | for verts, map_hemi in zip(vertices_from, maps): |
| 334 | vertno_h = _sparse_argmax_nnz_row(map_hemi[verts]) |
| 335 | order = np.argsort(vertno_h) |
| 336 | cols.append(cnt + order) |
| 337 | vertices.append(vertno_h[order]) |
| 338 | cnt += len(vertno_h) |
| 339 | cols = np.concatenate(cols) |
| 340 | rows = np.arange(len(cols)) |
| 341 | data = np.ones(len(cols)) |
| 342 | morph_mat = sparse.coo_array( |
| 343 | (data, (rows, cols)), shape=(len(cols), len(cols)) |
| 344 | ).tocsr() |
| 345 | return vertices, morph_mat |
| 346 | |
| 347 | |
| 348 | _SOURCE_MORPH_ATTRIBUTES = [ # used in writing |
no test coverage detected