def i_segment_meander_angle(tree): '''Return an iterator to a tree meander angle The meander angle is defined as the angle between to adjacent segments. Applies neurom.morphmath.angle_3points to triplets of ''' return tr.imap_val(lambda t: mm.angle_3points(t[1], t[0], t[2]), tr.itriplet(tree))
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 i_segment_radial_dist(pos, tree): '''Return an iterator of radial distances of tree segments to a given point The radial distance is the euclidian distance between the mid-point of the segment and the point in question. Parameters: pos: origin to which disrances are measured. It must have at least 3 components. The first 3 components are (x, y, z). tree: tree of raw data rows. ''' return tr.imap_val(lambda s: mm.segment_radial_dist(s, pos), tr.isegment(tree))
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))
def i_segment_area(tree): ''' return an iterator of tree segment areas ''' return tr.imap_val(mm.segment_area, tr.isegment(tree))
def i_segment_volume(tree): ''' return an iterator of tree segment volumes ''' return tr.imap_val(mm.segment_volume, tr.isegment(tree))
def i_segment_radius(tree): ''' return an iterator of tree segment radii ''' return tr.imap_val(mm.segment_radius, tr.isegment(tree))
def i_segment_length(tree): ''' return an iterator of tree segment lengths ''' return tr.imap_val(mm.segment_length, tr.isegment(tree))
def path_length(tree): '''Get the path length from a sub-tree to the root node''' return np.sum(s for s in tr.imap_val(mm.segment_length, tr.isegment(tree, tr.iupstream)))
def i_section_length(tree): """ Return an iterator of tree section lengths """ return tr.imap_val(mm.section_length, tr.isection(tree))