def test_section_iteration(): REF_SECTIONS = ((0, 11), (11, 111, 1111), (1111, 11111), (1111, 11112), (1111, 11113), (11, 112), (0, 12), (12, 121, 1211), (1211, 12111), (1211, 12112), (12, 122)) for i, s in enumerate(isection(REF_TREE2)): nt.assert_equal(REF_SECTIONS[i], tuple(tt.value for tt in s))
def trunk_section_length(tree): '''Length of the initial tree section Returns: Length of first section of tree or 0 if single point tree ''' try: _it = tr.imap_val(mm.section_length, tr.isection(tree)) return _it.next() except StopIteration: return 0.0
def nonzero_section_lengths(neuron, threshold=0.0): '''Check presence of neuron sections with length not above threshold Arguments: neuron: Neuron object whose segments will be tested threshold: value above which a section length is considered to be non-zero Return: list of ids of first point in bad sections ''' l = [[s for s in val_iter(isection(t)) if section_length(s) <= threshold] for t in neuron.neurites] return [i[0][COLS.ID] for i in chain(*l)]
def test_section_upstream_iteration(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [[(1111, 11111), (11, 111, 1111), (0, 11)], [(1111, 11112), (11, 111, 1111), (0, 11)], [(1111, 11113), (11, 111, 1111), (0, 11)], [(11, 112), (0, 11)], [(1211, 12111), (12, 121, 1211), (0, 12)], [(1211, 12112), (12, 121, 1211), (0, 12)], [(12, 122), (0, 12)]] for l, ref in zip(leaves, ref_paths): nt.assert_equal([s for s in val_iter(isection(l, iupstream))], ref)
def i_section_path_length(tree, use_start_point=False): '''Return an iterator of path lengths of tree sections Path lengths are measured to the tree's root. Parameters: tree: tree object use_start_point: If true, calculate path length from section start point,\ else from end-point (default, False) ''' sec_idx = 0 if use_start_point else -1 return imap(lambda s: path_length(s[sec_idx]), tr.isection(tree))
def test_section_upstream_iteration(): leaves = [l for l in ileaf(REF_TREE2)] ref_paths = [ [(1111, 11111), (11, 111, 1111), (0, 11)], [(1111, 11112), (11, 111, 1111), (0, 11)], [(1111, 11113), (11, 111, 1111), (0, 11)], [(11, 112), (0, 11)], [(1211, 12111), (12, 121, 1211), (0, 12)], [(1211, 12112), (12, 121, 1211), (0, 12)], [(12, 122), (0, 12)]] for l, ref in zip(leaves, ref_paths): nt.assert_equal([s for s in val_iter(isection(l, iupstream))], ref)
def test_branch_order(): branch_order_map = { (0, 11): 0, (11, 111, 1111): 1, (1111, 11111): 2, (1111, 11112): 2, (1111, 11113): 2, (11, 112): 1, (0, 12): 0, (12, 121, 1211): 1, (1211, 12111): 2, (1211, 12112): 2, (12, 122): 1 } for sec in tr.isection(MOCK_TREE): nt.assert_equal(branch_order(sec), branch_order_map[tuple(p for p in tr.val_iter(sec))])
def i_section_radial_dist(tree, pos=None, use_start_point=False): '''Return an iterator of radial distances of tree sections to a given point The radial distance is the euclidian distance between the either the end-point or rhe start point of the section and the point in question. Parameters: tree: tree object pos: origin to which distances are measured. It must have at least 3\ components. The first 3 components are (x, y, z).\ (default tree origin) use_start_point: If true, calculate distance from section start point,\ else from end-point (default, False) ''' pos = tree.value if pos is None else pos sec_idx = 0 if use_start_point else -1 return tr.imap_val(lambda s: mm.point_dist(s[sec_idx], pos), tr.isection(tree))
# Number of bifurcation points. # This uses the more generic iter_neurites method, in which # we can decide the type of iteration. Here we iterate over # bifurcation points. print('Number of bifurcation points:', sum(1 for _ in nrn.iter_neurites(ibifurcation_point))) # Number of bifurcation points for apical dendrites print( 'Number of bifurcation points (apical dendrites):', sum(1 for _ in nrn.iter_neurites( ibifurcation_point, neurite_type=ezy.TreeType.apical_dendrite))) # Maximum branch order # This is complicated and will be factored into a helper function. # We iterate over sections, calcumating the branch order for each one. # The reason we cannot simply call nen.iter_sections(mt.branch_order) is # that mt.branch_order requires sections of tree nodes for navigation, but # nrn.iter_sections iterates over the sections of points. # TODO: This whole tree data business has to be refactored and simplified. print( 'Maximum branch order:', np.max([ bo for bo in nrn.iter_neurites( lambda t: imap(mt.branch_order, isection(t))) ])) # Neuron's bounding box print('Bounding box ((min x, y, z), (max x, y, z))', nrn.bounding_box())
def sections(self): '''Returns sections iterator ''' return isection(self._tree)
def i_section_length(tree): """ Return an iterator of tree section lengths """ return tr.imap_val(mm.section_length, tr.isection(tree))
def n_sections(tree): """ Return number of sections in tree """ return sum(1 for _ in tr.isection(tree))
'''Build sections from a tree Sections are defined as points between forking points, between the root node and forking points, or between forking points and end-points ''' from neurom.core import tree REF_TREE = tree.Tree(0) REF_TREE.add_child(tree.Tree(11)) REF_TREE.add_child(tree.Tree(12)) REF_TREE.children[0].add_child(tree.Tree(111)) REF_TREE.children[0].add_child(tree.Tree(112)) REF_TREE.children[1].add_child(tree.Tree(121)) REF_TREE.children[1].add_child(tree.Tree(122)) REF_TREE.children[1].children[0].add_child(tree.Tree(1211)) REF_TREE.children[1].children[0].children[0].add_child(tree.Tree(12111)) REF_TREE.children[1].children[0].children[0].add_child(tree.Tree(12112)) REF_TREE.children[0].children[0].add_child(tree.Tree(1111)) REF_TREE.children[0].children[0].children[0].add_child(tree.Tree(11111)) REF_TREE.children[0].children[0].children[0].add_child(tree.Tree(11112)) if __name__ == '__main__': for s in tree.isection(REF_TREE): print [tt.value for tt in s]
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '''Build sections from a tree Sections are defined as points between forking points, between the root node and forking points, or between forking points and end-points ''' from neurom.core import tree REF_TREE = tree.Tree(0) REF_TREE.add_child(tree.Tree(11)) REF_TREE.add_child(tree.Tree(12)) REF_TREE.children[0].add_child(tree.Tree(111)) REF_TREE.children[0].add_child(tree.Tree(112)) REF_TREE.children[1].add_child(tree.Tree(121)) REF_TREE.children[1].add_child(tree.Tree(122)) REF_TREE.children[1].children[0].add_child(tree.Tree(1211)) REF_TREE.children[1].children[0].children[0].add_child(tree.Tree(12111)) REF_TREE.children[1].children[0].children[0].add_child(tree.Tree(12112)) REF_TREE.children[0].children[0].add_child(tree.Tree(1111)) REF_TREE.children[0].children[0].children[0].add_child(tree.Tree(11111)) REF_TREE.children[0].children[0].children[0].add_child(tree.Tree(11112)) if __name__ == '__main__': for s in tree.isection(REF_TREE): print[tt.value for tt in s]
", max=", np.max(seg_taper_rate), sep="", ) # Number of bifurcation points. # This uses the more generic iter_neurites method, in which # we can decide the type of iteration. Here we iterate over # bifurcation points. print("Number of bifurcation points:", sum(1 for _ in nrn.iter_neurites(ibifurcation_point))) # Number of bifurcation points for apical dendrites print( "Number of bifurcation points (apical dendrites):", sum(1 for _ in nrn.iter_neurites(ibifurcation_point, neurite_type=ezy.TreeType.apical_dendrite)), ) # Maximum branch order # This is complicated and will be factored into a helper function. # We iterate over sections, calcumating the branch order for each one. # The reason we cannot simply call nen.iter_sections(mt.branch_order) is # that mt.branch_order requires sections of tree nodes for navigation, but # nrn.iter_sections iterates over the sections of points. # TODO: This whole tree data business has to be refactored and simplified. print( "Maximum branch order:", np.max([bo for bo in nrn.iter_neurites(lambda t: imap(mt.branch_order, isection(t)))]) ) # Neuron's bounding box print("Bounding box ((min x, y, z), (max x, y, z))", nrn.bounding_box())