Пример #1
0
def test_section_path_distances_endpoint():

    ref_sec_path_len_start = list(iter_neurites(NEURON, sec.start_point_path_length))
    ref_sec_path_len = list(iter_neurites(NEURON, sec.end_point_path_length))
    path_lengths = get_feat('section_path_distances', NEURON)
    nt.assert_true(ref_sec_path_len != ref_sec_path_len_start)
    nt.assert_equal(len(path_lengths), 84)
    nt.assert_true(np.all(path_lengths == ref_sec_path_len))
Пример #2
0
def _check_area(obj):
    sec_area = [l for l in iter_neurites(obj, sec.area)]
    seg_area = [l for l in iter_neurites(obj, seg.area)]
    sum_sec_area = sum(sec_area)
    sum_seg_area = sum(seg_area)

    # check that sum of section areas is same as sum of segment lengths
    nt.assert_almost_equal(sum_sec_area, sum_seg_area)

    nt.assert_almost_equal(sum_sec_area, 349.75070138106133)
Пример #3
0
def _check_length(obj):
    sec_len = [l for l in iter_neurites(obj, sec.length)]
    seg_len = [l for l in iter_neurites(obj, seg.length)]
    sum_sec_len = sum(sec_len)
    sum_seg_len = sum(seg_len)

    # check that sum of section lengths is same as sum of segment lengths
    nt.eq_(sum_sec_len, sum_seg_len)

    nt.assert_almost_equal(sum_sec_len, 33.0330776588)
Пример #4
0
def _check_volume(obj):
    sec_vol = [l for l in iter_neurites(obj, sec.volume)]
    seg_vol = [l for l in iter_neurites(obj, seg.volume)]
    sum_sec_vol = sum(sec_vol)
    sum_seg_vol = sum(seg_vol)

    # check that sum of section volumes is same as sum of segment lengths
    nt.assert_almost_equal(sum_sec_vol, sum_seg_vol)

    nt.assert_almost_equal(sum_sec_vol, 307.68010178856395)
Пример #5
0
def test_section_radial_distances_endpoint():
    ref_sec_rad_dist_start = []
    for t in NEURON.neurites:
        ref_sec_rad_dist_start.extend(
            ll for ll in iter_neurites(t, sec.radial_dist(t.value, use_start_point=True)))

    ref_sec_rad_dist = []
    for t in NEURON.neurites:
        ref_sec_rad_dist.extend(ll for ll in iter_neurites(t, sec.radial_dist(t.value)))

    rad_dists = get_feat('section_radial_distances', NEURON)
    nt.assert_true(ref_sec_rad_dist != ref_sec_rad_dist_start)
    nt.assert_equal(len(rad_dists), 84)
    nt.assert_true(np.all(rad_dists == ref_sec_rad_dist))
Пример #6
0
def test_segment_radial_distances_origin():
    origin = (-100, -200, -300)

    ref_segs = []
    ref_segs2 = []
    for t in NEURON.neurites:
        ref_segs.extend(ll for ll in iter_neurites(t, seg.radial_dist(t.value)))
        ref_segs2.extend(ll for ll in iter_neurites(t, seg.radial_dist(origin)))

    rad_dists = get_feat('segment_radial_distances', NEURON)
    rad_dists2 = get_feat('segment_radial_distances', NEURON, origin=origin)
    nt.assert_true(np.all(rad_dists == ref_segs))
    nt.assert_true(np.all(rad_dists2 == ref_segs2))
    nt.assert_true(np.all(rad_dists2 != ref_segs))
Пример #7
0
def test_segment_radial_distances():
    ref_segs = []
    for t in NEURON.neurites:
        ref_segs.extend(ll for ll in iter_neurites(t, seg.radial_dist(t.value)))

    rad_dists = get_feat('segment_radial_distances', NEURON)
    nt.assert_true(np.all(rad_dists == ref_segs))
Пример #8
0
def _check_section_radial_dists_end_point(obj):

    origin = [0.0, 0.0, 0.0]

    rd = [d for d in iter_neurites(obj, sec.radial_dist(origin))]

    nt.eq_(rd, [8.0, 8.0])
Пример #9
0
def _check_segment_radial_dists(obj):

    origin = [0.0, 0.0, 0.0]

    rd = [d for d in iter_neurites(SIMPLE_NEURON, seg.radial_dist(origin))]

    nt.eq_(rd, [1.0, 3.0, 5.0, 7.0, 1.0, 3.0, 5.0, 7.0])
Пример #10
0
def _check_section_radial_dists_start_point(obj):

    origin = [0.0, 0.0, 0.0]

    rd = [d for d in iter_neurites(obj, sec.radial_dist(origin, True))]

    nt.eq_(rd, [0.0, 0.0])
Пример #11
0
def get_features(object1, object2, flist=features):
    '''Computes features from module mod'''
    collect_all = []

    for feat in flist:

        feature_pop = np.array([l for l in iter_neurites(object1, feature_map[feat])])
        feature_neu = np.array([l for l in iter_neurites(object2, feature_map[feat])])

        # Standardization of data: (data - mean(data))/ std(data)
        m = np.mean(feature_pop)
        st = np.std(feature_pop)

        collect_all.append([(feature_pop - m) / st, (feature_neu - m) / st])

    return collect_all
Пример #12
0
def test_remote_bifurcation_angles():
    ref_remote_bifangles = list(iter_neurites(NEURON, bifs.remote_angle))
    remote_bifangles = get_feat('remote_bifurcation_angles', NEURON)
    nt.assert_equal(len(remote_bifangles), 40)
    nt.assert_true(np.all(remote_bifangles == ref_remote_bifangles))
    remote_bifangles = get_feat('remote_bifurcation_angles', NEURON, neurite_type=NeuriteType.all)
    nt.assert_equal(len(remote_bifangles), 40)
    nt.assert_true(np.all(remote_bifangles == ref_remote_bifangles))
Пример #13
0
def _check_points(obj):
    @bif.bifurcation_point_function(as_tree=False)
    def point(bif):
        return bif[:4]

    bif_points = [p for p in iter_neurites(obj, point)]
    nt.eq_(bif_points,
           [[0.0, 4.0, 0.0, 2.0], [0.0, 5.0, 0.0, 2.0], [0.0, 5.0, 3.0, 0.75]])
Пример #14
0
def test_load_trees_good_neuron():
    '''Check trees in good neuron are the same as trees from loaded neuron'''
    filepath = os.path.join(SWC_PATH, 'Neuron.swc')
    nrn = utils.load_neuron(filepath)
    trees = utils.load_trees(filepath)
    nt.eq_(len(nrn.neurites), 4)
    nt.eq_(len(nrn.neurites), len(trees))

    nrn2 = MockNeuron(trees)

    @pts.point_function(as_tree=False)
    def elem(point):
        return point

    # Check data are the same in tree collection and neuron's neurites
    for a, b in izip(iter_neurites(nrn, elem), iter_neurites(nrn2, elem)):
        nt.ok_(np.all(a == b))
Пример #15
0
def test_segment_lengths():
    ref_seglen = list(iter_neurites(NEURON, seg.length))
    seglen = get_feat('segment_lengths', NEURON)
    nt.assert_equal(len(seglen), 840)
    nt.assert_true(np.all(seglen == ref_seglen))

    seglen = get_feat('segment_lengths', NEURON, neurite_type=NeuriteType.all)
    nt.assert_equal(len(seglen), 840)
    nt.assert_true(np.all(seglen == ref_seglen))
Пример #16
0
def _check_segment_volumes(obj):

    sv = (l/math.pi for l in iter_neurites(obj, seg.volume))

    ref = (1.0, 1.0, 4.6666667, 4.0, 4.6666667, 0.7708333,
           0.5625, 4.6666667, 0.7708333, 0.5625)

    for a, b in izip(sv, ref):
        nt.assert_almost_equal(a, b)
Пример #17
0
def _check_segment_areas(obj):

    sa = (l/math.pi for l in iter_neurites(obj, seg.area))

    ref = (2.0, 2.0, 6.7082039, 4.0, 6.7082039, 1.8038587,
           1.5, 6.7082039, 1.8038587, 1.5)

    for a, b in izip(sa, ref):
        nt.assert_almost_equal(a, b)
Пример #18
0
def test_local_bifurcation_angles():

    ref_local_bifangles = list(iter_neurites(NEURON, bifs.local_angle))

    local_bifangles = get_feat('local_bifurcation_angles', NEURON)
    nt.assert_equal(len(local_bifangles), 40)
    nt.assert_true(np.all(local_bifangles == ref_local_bifangles))
    local_bifangles = get_feat('local_bifurcation_angles', NEURON, neurite_type=NeuriteType.all)
    nt.assert_equal(len(local_bifangles), 40)
    nt.assert_true(np.all(local_bifangles == ref_local_bifangles))
Пример #19
0
def map_segments(neurite, fun):
    '''map a function to the segments in a tree'''

    if is_new_style(neurite):
        if isinstance(neurite, Section):
            neurite = Neurite(neurite)
        return [s for ss in neurite.iter_sections()
                for s in secfun.map_segments(fun, ss)]
    else:
        fun = seg.segment_function(as_tree=False)(fun)
        return list(iter_neurites(neurite, fun))
Пример #20
0
def _check_segment_x_coordinate(obj):

    xcoord = [s for s in iter_neurites(obj, seg.x_coordinate)]

    nt.eq_(xcoord,
           [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
Пример #21
0
"""Calculate inter-segment angles"""

import logging
import numpy as np
from neurom.core.dataformat import COLS
from neurom.point_neurite import triplets as trip
from neurom.point_neurite.io.utils import load_data, make_neuron
from neurom.point_neurite.core import iter_neurites


# root level logger. This would be a top level application logger.
logging.basicConfig()
LOG = logging.getLogger()
LOG.setLevel(logging.DEBUG)
fmt = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
LOG.handlers[0].setFormatter(fmt)


if __name__ == "__main__":

    filename = "test_data/swc/Neuron.swc"
    rd = load_data(filename)
    nrn = make_neuron(rd)

    for tt in nrn.neurites:
        print "Tree ID: {0}, type: {1}".format(tt.value[COLS.ID], tt.value[COLS.TYPE])
        for a in iter_neurites(tt, trip.meander_angle):
            LOG.debug("Angle %f", a)
            if np.isnan(a):
                LOG.warn("Found NaN angle. Check for zero length segments!")
Пример #22
0
def _check_segment_y_coordinate(obj):

    ycoord = [s for s in iter_neurites(obj, seg.y_coordinate)]

    nt.eq_(ycoord,
           [1.0, 3.0, 5.0, 7.0, 0.0, 0.0, 0.0, 0.0])
Пример #23
0
def _check_radius1(obj):

    radii = [r for r in iter_neurites(obj, pts.radius)]
    nt.eq_(radii, [1, 2, 3, 4, 5, 6, 7,
                   1, 2, 3, 4, 5, 6, 7,
                   1, 2, 3, 4, 5, 6, 7])
Пример #24
0
def _check_remote_bifurcation_angles(obj):

    angles = [a for a in iter_neurites(obj, bif.remote_angle)]

    nt.eq_(angles,
           [0.9380474917927135, math.pi / 2, math.pi / 4])
Пример #25
0
def _check_partition(obj):
    p = [a for a in iter_neurites(ODD_NEURON, bif.partition)]

    nt.eq_(p, [5./3., 1., 3., 1.])
Пример #26
0
def _check_local_bifurcation_angles(obj):

    angles = [a for a in iter_neurites(obj, bif.local_angle)]

    nt.eq_(angles, [math.pi / 4, math.pi / 2, math.pi / 4])
Пример #27
0
def test_section_branch_order():

    sec_bo = [bo for bo in iter_neurites(MOCK_TREE, sec.branch_order)]
    nt.eq_(sec_bo, [1, 2, 2, 1, 2, 3, 3, 2])
Пример #28
0
def _check_path_length_start_point(obj, ref):
    pl = [l for l in iter_neurites(obj, sec.start_point_path_length)]
    nt.eq_(pl, ref)
Пример #29
0
def _check_segment_z_coordinate(obj):

    zcoord = [s for s in iter_neurites(obj, seg.z_coordinate)]

    nt.eq_(zcoord,
           [0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 7.0])
Пример #30
0
def _check_segment_taper_rate(obj):

    tp = [t for t in iter_neurites(obj, seg.taper_rate)]

    nt.eq_(tp,
           [0.0, 0.0, 1.0, 0.0, 1.0, 0.5, 0.0, 1.0, 0.5, 0.0])