def check_cloned_neuron(nrn1, nrn2): # check if two neurons are identical # somata nt.assert_true(isinstance(nrn2.soma, type(nrn1.soma))) nt.eq_(nrn1.soma.radius, nrn2.soma.radius) for v1, v2 in izip(nrn1.soma.iter(), nrn2.soma.iter()): nt.assert_true(np.allclose(v1, v2)) # neurites for neu1, neu2 in izip(nrn1.neurites, nrn2.neurites): nt.assert_true(isinstance(neu2, type(neu1))) for v1, v2 in izip(val_iter(neu1.ipreorder()), val_iter(neu2.ipreorder())): nt.assert_true(np.allclose(v1, v2)) # check if the ids are different # somata nt.assert_true(nrn1.soma is not nrn2.soma) # neurites for neu1, neu2 in izip(nrn1.neurites, nrn2.neurites): nt.assert_true(neu1 is not neu2) # check if changes are propagated between neurons nrn2.soma.radius = 10.0 nt.ok_(nrn1.soma.radius != nrn2.soma.radius) # neurites for neu1, neu2 in izip(nrn1.neurites, nrn2.neurites): for v1, v2 in izip(val_iter(neu1.ipreorder()), val_iter(neu2.ipreorder())): v2 = np.array([-1000.0, -1000.0, -1000.0, 1000.0, -100.0, -100.0, -100.0]) nt.assert_false(any(v1 == v2))
def compare_trees(tree1, tree2): ''' Comparison between all the nodes and their respective radii between two trees. Ids are do not have to be identical between the trees, and swapping is allowed Returns: False if the trees are not identical. True otherwise. ''' leaves1 = list(tr.ileaf(tree1)) leaves2 = list(tr.ileaf(tree2)) if len(leaves1) != len(leaves2): return False else: nleaves = len(leaves1) for leaf1, leaf2 in product(leaves1, leaves2): is_equal = True for node1, node2 in izip(val_iter(tr.iupstream(leaf1)), val_iter(tr.iupstream(leaf2))): if any(node1[0:5] != node2[0:5]): is_equal = False continue if is_equal: nleaves -= 1 return nleaves == 0
def get_bounding_box(tree): """ Returns: The boundaries of the tree in three dimensions: [[xmin, ymin, zmin], [xmax, ymax, zmax]] """ min_xyz, max_xyz = (np.array([np.inf, np.inf, np.inf]), np.array([np.NINF, np.NINF, np.NINF])) for p in val_iter(tree.ipreorder()): min_xyz = np.minimum(p[:COLS.R], min_xyz) max_xyz = np.maximum(p[:COLS.R], max_xyz) return np.array([min_xyz, max_xyz])
def test_branch_order(): branch_order_map = { (0, 11): 1, (11, 111, 1111): 2, (1111, 11111): 3, (1111, 11112): 3, (1111, 11113): 3, (11, 112): 2, (0, 12): 1, (12, 121, 1211): 2, (1211, 12111): 3, (1211, 12112): 3, (12, 122): 2 } for sec in ptr.isection(MOCK_TREE): nt.assert_equal(mtr.branch_order(sec), branch_order_map[tuple(p for p in ptr.val_iter(sec))])