Exemple #1
0
def has_no_fat_ends(neuron, multiple_of_mean=2.0, final_point_count=5):
    '''Check if leaf points are too large

    Arguments:
        neuron(Neuron): The neuron object to test
        multiple_of_mean(float): how many times larger the final radius
        has to be compared to the mean of the final points
        final_point_count(int): how many points to include in the mean

    Returns:
        CheckResult with result list of ids of bad sections

    Note:
        A fat end is defined as a leaf segment whose last point is larger
        by a factor of `multiple_of_mean` than the mean of the points in
        `final_point_count`
    '''
    bad_ids = []
    for leaf in _nf.iter_sections(neuron.neurites, iterator_type=Tree.ileaf):
        mean_radius = np.mean(leaf.points[1:][-final_point_count:, COLS.R])

        if mean_radius * multiple_of_mean <= leaf.points[-1, COLS.R]:
            bad_ids.append((leaf.id, leaf.points[-1:]))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #2
0
def has_no_fat_ends(neuron, multiple_of_mean=2.0, final_point_count=5):
    '''Check if leaf points are too large

    Arguments:
        neuron(Neuron): The neuron object to test
        multiple_of_mean(float): how many times larger the final radius
        has to be compared to the mean of the final points
        final_point_count(int): how many points to include in the mean

    Returns:
        CheckResult with result list of ids of bad sections

    Note:
        A fat end is defined as a leaf segment whose last point is larger
        by a factor of `multiple_of_mean` than the mean of the points in
        `final_point_count`
    '''
    bad_ids = []
    for leaf in _nf.iter_sections(neuron.neurites, iterator_type=Tree.ileaf):
        mean_radius = np.mean(leaf.points[1:][-final_point_count:, COLS.R])

        if mean_radius * multiple_of_mean <= leaf.points[-1, COLS.R]:
            bad_ids.append((leaf.id, leaf.points[-1:]))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #3
0
def test_section_tortuosity():
    sec_a = load_neuron(StringIO(u"""
	((CellBody) (0 0 0 2))
	((Dendrite)
    (0 0 0 2)
    (1 0 0 2)
    (2 0 0 2)
    (3 0 0 2))"""),
                        reader='asc').sections[1]

    sec_b = load_neuron(StringIO(u"""
    ((CellBody) (0 0 0 2))
    ((Dendrite)
    (0 0 0 2)
    (1 0 0 2)
    (1 2 0 2)
    (0 2 0 2))"""),
                        reader='asc').sections[1]

    nt.eq_(_sf.section_tortuosity(sec_a), 1.0)
    nt.eq_(_sf.section_tortuosity(sec_b), 4.0 / 2.0)

    for s in _nf.iter_sections(NRN):
        nt.eq_(
            _sf.section_tortuosity(s),
            mmth.section_length(s.points) /
            mmth.point_dist(s.points[0], s.points[-1]))
def test_neuron_sections():
    all_nodes = set(NRN.sections)
    neurite_nodes = set(_nf.iter_sections(NRN.neurites))

    # check no duplicates
    nt.assert_true(len(all_nodes) == len(NRN.sections))

    # check all neurite tree nodes are
    # in sections attribute
    nt.assert_true(len(set(NRN.sections) - neurite_nodes) > 0)
Exemple #5
0
def test_neuron_sections():
    all_nodes = set(NRN.sections)
    neurite_nodes = set(_nf.iter_sections(NRN.neurites))

    # check no duplicates
    nt.assert_true(len(all_nodes) == len(NRN.sections))

    # check all neurite tree nodes are
    # in sections attribute
    nt.assert_true(len(set(NRN.sections) - neurite_nodes) > 0)
def test_section_tortuosity():

    sec_a = Section([(0, 0, 0), (1, 0, 0), (2, 0, 0), (3, 0, 0)])

    sec_b = Section([(0, 0, 0), (1, 0, 0), (1, 2, 0), (0, 2, 0)])

    nt.eq_(_sf.section_tortuosity(sec_a), 1.0)
    nt.eq_(_sf.section_tortuosity(sec_b), 4.0 / 2.0)

    for s in _nf.iter_sections(NRN):
        nt.eq_(_sf.section_tortuosity(s), mmth.section_length(s.points) / mmth.point_dist(s.points[0], s.points[-1]))
Exemple #7
0
def test_section_tortuosity():
    sec_a = Section([(0, 0, 0), (1, 0, 0), (2, 0, 0), (3, 0, 0)])

    sec_b = Section([(0, 0, 0), (1, 0, 0), (1, 2, 0), (0, 2, 0)])

    nt.eq_(_sf.section_tortuosity(sec_a), 1.0)
    nt.eq_(_sf.section_tortuosity(sec_b), 4.0 / 2.0)

    for s in _nf.iter_sections(NRN):
        nt.eq_(
            _sf.section_tortuosity(s),
            mmth.section_length(s.points) /
            mmth.point_dist(s.points[0], s.points[-1]))
Exemple #8
0
def has_all_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:
        status and list of ids bad sections
    '''
    bad_ids = [s.id for s in _nf.iter_sections(neuron.neurites)
               if section_length(s.points) <= threshold]

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #9
0
def has_all_nonzero_section_lengths(neuron, threshold=0.0):
    '''Check presence of neuron sections with length not above threshold

    Arguments:
        neuron(Neuron): The neuron object to test
        threshold(float): value above which a section length is considered
        to be non-zero

    Returns:
        CheckResult with result including list of ids of bad sections
    '''
    bad_ids = [s.id for s in _nf.iter_sections(neuron.neurites)
               if section_length(s.points) <= threshold]

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #10
0
def has_all_nonzero_section_lengths(neuron, threshold=0.0):
    '''Check presence of neuron sections with length not above threshold

    Arguments:
        neuron(Neuron): The neuron object to test
        threshold(float): value above which a section length is considered
        to be non-zero

    Returns:
        CheckResult with result including list of ids bad sections
    '''
    bad_ids = [s.id for s in _nf.iter_sections(neuron.neurites)
               if section_length(s.points) <= threshold]

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #11
0
def has_no_fat_ends(neuron, multiple_of_mean=2.0, final_point_count=5):
    '''Check if leaf points are too large

    Arguments:
        neuron: Neuron object whose soma will be tested
        multiple_of_mean(float): how many times larger the final radius
        has to be compared to the mean of the final points
        final_point_count(int): how many points to include in the mean
    '''
    bad_ids = []
    for leaf in _nf.iter_sections(neuron.neurites, iterator_type=Tree.ileaf):
        mean_radius = np.mean(leaf.points[-final_point_count:, COLS.R])
        if mean_radius * multiple_of_mean < leaf.points[-1, COLS.R]:
            bad_ids.append((leaf.id, len(leaf.points)))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #12
0
def has_all_nonzero_segment_lengths(neuron, threshold=0.0):
    '''Check presence of neuron segments with length not above threshold

    Arguments:
        neuron: Neuron object whose segments will be tested
        threshold: value above which a segment length is considered to be non-zero

    Return:
        status and list of (section_id, segment_id) of zero length segments
    '''
    bad_ids = []
    for sec in _nf.iter_sections(neuron):
        p = sec.points
        for i, s in enumerate(izip(p[:-1], p[1:])):
            if segment_length(s) <= threshold:
                bad_ids.append((sec.id, i))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #13
0
def has_all_nonzero_neurite_radii(neuron, threshold=0.0):
    '''Check presence of neurite points with radius not above threshold

    Arguments:
        neuron: Neuron object whose segments will be tested
        threshold: value above which a radius is considered to be non-zero
    Return:
        status and list of (section ID, point ID) pairs of zero-radius points
    '''
    bad_ids = []
    seen_ids = set()
    for s in _nf.iter_sections(neuron):
        for i, p in enumerate(s.points):
            info = (s.id, i)
            if p[COLS.R] <= threshold and info not in seen_ids:
                seen_ids.add(info)
                bad_ids.append(info)

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #14
0
def has_no_jumps(neuron, max_distance=30.0, axis='z'):
    '''Check if there are jumps (large movements in the `axis`)

    Arguments:
        neuron(Neuron): The neuron object to test
        max_z_distance(float): value above which consecutive z-values are
        considered a jump
        axis(str): one of x/y/z, which axis to check for jumps

    Returns:
        CheckResult with result list of ids bad sections
    '''
    bad_ids = []
    axis = {'x': COLS.X, 'y': COLS.Y, 'z': COLS.Z, }[axis.lower()]
    for sec in _nf.iter_sections(neuron):
        for i, (p0, p1) in enumerate(iter_segments(sec)):
            info = (sec.id, i)
            if max_distance < abs(p0[axis] - p1[axis]):
                bad_ids.append(info)
    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #15
0
def has_all_nonzero_segment_lengths(neuron, threshold=0.0):
    '''Check presence of neuron segments with length not above threshold

    Arguments:
        neuron(Neuron): The neuron object to test
        threshold(float): value above which a segment length is considered to
        be non-zero

    Returns:
        CheckResult with result including list of (section_id, segment_id)
        of zero length segments
    '''
    bad_ids = []
    for sec in _nf.iter_sections(neuron):
        p = sec.points
        for i, s in enumerate(zip(p[:-1], p[1:])):
            if segment_length(s) <= threshold:
                bad_ids.append((sec.id, i))

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #16
0
def has_all_nonzero_neurite_radii(neuron, threshold=0.0):
    '''Check presence of neurite points with radius not above threshold

    Arguments:
        neuron(Neuron): The neuron object to test
        threshold: value above which a radius is considered to be non-zero

    Returns:
        CheckResult with result including list of (section ID, point ID) pairs
        of zero-radius points
    '''
    bad_ids = []
    seen_ids = set()
    for s in _nf.iter_sections(neuron):
        for i, p in enumerate(s.points):
            info = (s.id, i)
            if p[COLS.R] <= threshold and info not in seen_ids:
                seen_ids.add(info)
                bad_ids.append(info)

    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #17
0
def has_no_jumps(neuron, max_distance=30.0, axis='z'):
    '''Check if there are jumps (large movements in the `axis`)

    Arguments:
        neuron: Neuron object whose neurites will be tested
        max_z_distance: value above which consecutive z-values are
        considered a jump
        axis(str): one of x/y/z, which axis to check for jumps


    Return:
        status and list of ids bad sections
    '''
    bad_ids = []
    axis = {'x': COLS.X, 'y': COLS.Y, 'z': COLS.Z, }[axis.lower()]
    for s in _nf.iter_sections(neuron):
        it = izip(s.points, s.points[1:])
        for i, (p0, p1) in enumerate(it):
            info = (s.id, i)
            if max_distance < abs(p0[axis] - p1[axis]):
                bad_ids.append(info)
    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #18
0
def has_no_jumps(neuron, max_distance=30.0, axis='z'):
    '''Check if there are jumps (large movements in the `axis`)

    Arguments:
        neuron(Neuron): The neuron object to test
        max_z_distance(float): value above which consecutive z-values are
        considered a jump
        axis(str): one of x/y/z, which axis to check for jumps

    Returns:
        CheckResult with result list of ids bad sections
    '''
    bad_ids = []
    axis = {
        'x': COLS.X,
        'y': COLS.Y,
        'z': COLS.Z,
    }[axis.lower()]
    for sec in _nf.iter_sections(neuron):
        for i, (p0, p1) in enumerate(iter_segments(sec)):
            info = (sec.id, i)
            if max_distance < abs(p0[axis] - p1[axis]):
                bad_ids.append(info)
    return CheckResult(len(bad_ids) == 0, bad_ids)
Exemple #19
0
def _check_fst_neurite_rotate(nrt_a, nrt_b, rot_mat):
    for sa, sb in izip(_nf.iter_sections(nrt_a),
                       _nf.iter_sections(nrt_b)):
        nt.assert_true(np.allclose(sb.points[:, 0:3],
                                   _apply_rot(sa.points[:, 0:3], rot_mat)))
Exemple #20
0
def _check_fst_neurite_translate(nrts_a, nrts_b, t):
    # neurite sections
    for sa, sb in zip(_nf.iter_sections(nrts_a),
                       _nf.iter_sections(nrts_b)):
        nt.assert_true(np.allclose((sb.points[:, 0:3] - sa.points[:, 0:3]), t))
Exemple #21
0
def _check_fst_neurite_translate(nrts_a, nrts_b, t):
    # neurite sections
    for sa, sb in izip(_nf.iter_sections(nrts_a),
                       _nf.iter_sections(nrts_b)):
        nt.assert_true(np.allclose((sb.points[:, 0:3] - sa.points[:, 0:3]), t))
Exemple #22
0
def _check_fst_neurite_rotate(nrt_a, nrt_b, rot_mat):
    for sa, sb in zip(_nf.iter_sections(nrt_a),
                       _nf.iter_sections(nrt_b)):
        nt.assert_true(np.allclose(sb.points[:, 0:3],
                                   _apply_rot(sa.points[:, 0:3], rot_mat)))