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 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)
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[SECTION_ID] 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[SECTION_ID] assert _sf.section_tortuosity(sec_a) == 1.0 assert _sf.section_tortuosity(sec_b) == 4.0 / 2.0 for s in _nf.iter_sections(NRN): assert (_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)
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)
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)
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)
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)): assert np.allclose(sb.points[:, COLS.XYZ], _apply_rot(sa.points[:, COLS.XYZ], rot_mat))
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)): assert np.allclose((sb.points[:, COLS.XYZ] - sa.points[:, COLS.XYZ]), t)
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))