def test_find_indexes_pos_node(self, tissues, pos, sphere_surf, r): index, mapping = opt_struct._find_indexes(sphere_surf, 'node', positions=pos, radius=r, tissues=tissues) if tissues is None: nodes_with_tag = sphere_surf.nodes.node_number else: nodes_with_tag = sphere_surf.elm.nodes_with_tag(tissues) nodes = sphere_surf.nodes[nodes_with_tag] roi = [] mp = [] pos = np.atleast_2d(pos) for i, p in enumerate(pos): dist = np.linalg.norm(p - nodes, axis=1) idx_nearest = nodes_with_tag[np.argmin(dist)] if r > 0: center = nodes[np.argmin(dist)] dist_center = np.linalg.norm(center - nodes, axis=1) n_roi = np.sum(dist_center <= r) roi.extend(nodes_with_tag[dist_center <= r]) else: n_roi = 1 roi.append(idx_nearest) mp.extend(n_roi * (i, )) assert np.all(np.sort(index) == np.sort(roi)) assert np.all(np.sort(mapping) == np.sort(mp))
def test_find_indexes_pos_elm(self, tissues, pos, sphere_surf, r): index, mapping = opt_struct._find_indexes(sphere_surf, 'element', positions=pos, radius=r, tissues=tissues) if tissues is None: elm_with_tag = sphere_surf.elm.elm_number else: elm_with_tag = sphere_surf.elm.elm_number[np.isin( sphere_surf.elm.tag1, tissues)] elms = sphere_surf.elements_baricenters()[elm_with_tag] roi = [] mp = [] pos = np.atleast_2d(pos) for i, p in enumerate(pos): dist = np.linalg.norm(p - elms, axis=1) idx_nearest = elm_with_tag[np.argmin(dist)] if r > 0: center = elms[np.argmin(dist)] dist_center = np.linalg.norm(center - elms, axis=1) n_roi = np.sum(dist_center <= r) roi.extend(elm_with_tag[dist_center <= r]) else: n_roi = 1 roi.append(idx_nearest) mp.extend(n_roi * (i, )) assert np.all(np.sort(index) == np.sort(roi)) assert np.all(np.sort(mapping) == np.sort(mp))
def test_find_indexes_idx_element(self, indexes, sphere_surf): idx, mapping = opt_struct._find_indexes(sphere_surf, 'element', indexes=indexes) assert np.all(np.atleast_1d(idx) == indexes) assert np.all(mapping == np.arange(len(idx)))