def setup_root_new(mesh, is_soma_pt=None, soma_d=None, is_valid=None): if is_valid is not None: valid = np.copy(is_valid) else: valid = np.ones(len(mesh.vertices), np.bool) root = None # soma mode if is_soma_pt is not None: # pick the first soma as root is_valid_root = is_soma_pt & valid valid_root_inds = np.where(is_valid_root)[0] if len(valid_root_inds) > 0: min_valid_root = np.nanargmin(soma_d[valid_root_inds]) root = valid_root_inds[min_valid_root] root_ds, pred = sparse.csgraph.dijkstra(mesh.csgraph, False, root, return_predecessors=True) else: start_ind = np.where(valid)[0][0] root, target, pred, dm, root_ds = utils.find_far_points( mesh, start_ind=start_ind) valid[is_soma_pt] = False if root is None: # there is no soma close, so use far point heuristic start_ind = np.where(valid)[0][0] root, target, pred, dm, root_ds = utils.find_far_points( mesh, start_ind=start_ind) valid[root] = False assert (np.all(~np.isinf(root_ds[valid]))) return root, root_ds, pred, valid
def setup_root(mesh, soma_pt=None, soma_thresh=7500, valid_inds=None): if valid_inds is not None: valid = np.zeros(len(mesh.vertices), np.bool) valid[valid_inds] = True else: valid = np.ones(len(mesh.vertices), np.bool) root = None # soma mode if soma_pt is not None: # pick the first soma as root soma_d, soma_i = mesh.kdtree.query(soma_pt, k=len(mesh.vertices), distance_upper_bound=soma_thresh) if valid_inds is not None: soma_i, valid_soma_ind, soma_valid_ind = np.intersect1d( soma_i, valid_inds, return_indices=True) soma_d = soma_d[valid_soma_ind] if (len(soma_d) > 0): min_d = np.min(soma_d) else: min_d = np.inf if (min_d < soma_thresh): root = soma_i[np.argmin(soma_d)] root_ds, pred = sparse.csgraph.dijkstra(mesh.csgraph, False, root, return_predecessors=True) else: if valid_inds is not None: root, target, pred, dm, root_ds = utils.find_far_points( mesh, start_ind=valid_inds[0]) else: root, target, pred, dm, root_ds = utils.find_far_points(mesh) if root is None: # there is no soma close, so use far point heuristic root, target, pred, dm, root_ds = find_far_points(mesh) valid[root] = False return root, root_ds, pred, valid