def get_apical_point(neurite, morph, tuft_percent=27):
    '''Attempt to find the apical point in 'tufted' neurons
    Consider a neuron:
        |   /    | Tuft = 20%
        |--/     |
        |   /
        |--/
        |
    ----.-----
    All endpoints in the top 'tuft_percent' are found, then their common
    branch segment, furthest from the soma, is identified.
    Args:
        morph: neurom.fst._core.Neuron
        tuft_percent: percentage of the 'height' of the apical dendrite that
        would enclose the tuft, only leaves in this volume are considered as
        endpoints.  Note that this a spherical shell centered at the soma
    Returns:
        Section whose *end* is where the apical branching begins, or None if there
        is a problem
    '''

    apical = neurite
    max_distance2 = -float('inf')

    for leaf in apical.root_node.ileaf():
        point = leaf.points[-1, COLS.XYZ]
        max_distance2 = max(max_distance2, point_dist2(point,
                                                       morph.soma.center))

    min_distance2 = max_distance2 * (1 - tuft_percent / 100.)**2

    common_parents = set(nm.iter_sections(apical))
    #Iterator to the sections in a neurite, neuron or neuron population.
    all_parents = set([])

    for leaf in apical.root_node.ileaf():
        point = leaf.points[-1, COLS.XYZ]
        if min_distance2 <= point_dist2(point, morph.soma.center):
            parents = leaf.iupstream()
            set_parents = set(parents)
            common_parents &= set_parents
            all_parents |= set_parents

    apical_point_section = None
    for parent_section in nm.iter_sections(apical):
        if parent_section in common_parents:
            common_parents.remove(parent_section)
            if not common_parents:
                #print parent_section
                if parent_section in all_parents:
                    #return parent_section
                    apical_point_section = parent_section
                else:
                    apical_point_section = None

    #return None

    return apical_point_section
Example #2
0
    def _count_crossings(neurite, radius):
        """Used to count_crossings of segments in neurite with radius."""
        r2 = radius**2
        count = 0
        for start, end in iter_segments(neurite):
            start_dist2, end_dist2 = (morphmath.point_dist2(center, start),
                                      morphmath.point_dist2(center, end))

            count += int(start_dist2 <= r2 <= end_dist2
                         or end_dist2 <= r2 <= start_dist2)

        return count
Example #3
0
 def _seg_rd(sec, pos):
     '''list of radial distances of all segments of a section'''
     # TODO: remove this disable when pylint is fixed
     # pylint: disable=assignment-from-no-return
     mid_pts = np.divide(
         np.add(sec.points[:-1], sec.points[1:])[:, :3], 2.0)
     return np.sqrt([morphmath.point_dist2(p, pos) for p in mid_pts])
Example #4
0
 def _seg_rd(sec, pos):
     '''list of radial distances of all segments of a section'''
     mid_pts = np.divide(np.add(sec.points[:-1], sec.points[1:])[:, :3], 2.0)
     return np.sqrt([morphmath.point_dist2(p, pos) for p in mid_pts])
Example #5
0
def test_point_dist2():
    p1 = Point(3.0, 4.0, 5.0, 3.0)
    p2 = Point(4.0, 5.0, 6.0, 3.0)
    dist = mm.point_dist2(p1, p2)
    assert dist == 3
Example #6
0
def test_point_dist2():
    p1 = Point(3.0, 4.0, 5.0, 3.0, 1)
    p2 = Point(4.0, 5.0, 6.0, 3.0, 1)
    dist = mm.point_dist2(p1, p2)
    nt.eq_(dist, 3)
Example #7
0
 def _seg_rd(sec, pos):
     """list of radial distances of all segments of a section"""
     mid_pts = np.divide(np.add(sec.points[:-1], sec.points[1:])[:, :3], 2.0)
     return np.sqrt([morphmath.point_dist2(p, pos) for p in mid_pts])
Example #8
0
 def _seg_rd(sec, pos):
     '''list of radial distances of all segments of a section'''
     # TODO: remove this disable when pylint is fixed
     # pylint: disable=assignment-from-no-return
     mid_pts = np.divide(np.add(sec.points[:-1], sec.points[1:])[:, :3], 2.0)
     return np.sqrt([morphmath.point_dist2(p, pos) for p in mid_pts])