def is_monotonic(neurite, tol): '''Check if neurite tree is monotonic If each child has smaller or equal diameters from its parent Args: neurite(Neurite): neurite to operate on tol(float): tolerance Returns: True if neurite flat ''' for node in neurite.iter_sections(): # check that points in section satisfy monotonicity sec = node.points for point_id in range(len(sec) - 1): if sec[point_id + 1][COLS.R] > sec[point_id][COLS.R] + tol: return False # Check that section boundary points satisfy monotonicity if (node.parent is not None and sec[0][COLS.R] > node.parent.points[-1][COLS.R] + tol): return False return True
def is_monotonic(neurite, tol): '''Check if neurite tree is monotonic If each child has smaller or equal diameters from its parent Args: neurite(Neurite): neurite to operate on tol(float): tolerance Returns: True if neurite flat ''' for node in neurite.iter_sections(): # check that points in section satisfy monotonicity sec = node.points for point_id in range(len(sec) - 1): if sec[point_id + 1][COLS.R] > sec[point_id][COLS.R] + tol: return False # Check that section boundary points satisfy monotonicity if(node.parent is not None and sec[0][COLS.R] > node.parent.points[-1][COLS.R] + tol): return False return True
def _make_monotonic(neuron): for neurite in neuron.neurites: for node in neurite.iter_sections(): sec = node.points if node.parent is not None: sec[0][COLS.R] = node.parent.points[-1][COLS.R] / 2. for point_id in range(len(sec) - 1): sec[point_id + 1][COLS.R] = sec[point_id][COLS.R] / 2.
def test_parent(): t = Tree() for i in range(10): t.add_child(Tree()) nt.ok_(len(t.children) == 10) for c in t.children: nt.ok_(c.parent is t)
def fake_tree(init_radius, mode): radius = init_radius sec = [] for _ in range(5): sec.append([0, 0, 0, radius, 0, 0]) radius = new_radius(radius, mode) return Section(np.array(sec))
def test_deep_iteration(): root = t = Tree() for i in range(1, sys.getrecursionlimit() + 2): child = Tree() t.add_child(child) t = child list(root.ipreorder()) list(root.ipostorder()) list(t.iupstream())
def section_meander_angles(section): '''Inter-segment opening angles in a section''' p = section.points return [ mm.angle_3points(p[i - 1], p[i - 2], p[i]) for i in range(2, len(p)) ]
def section_meander_angles(section): '''Inter-segment opening angles in a section''' p = section.points return [mm.angle_3points(p[i - 1], p[i - 2], p[i]) for i in range(2, len(p))]