Exemplo n.º 1
0
def test_section_meander_angles():
    s0 = Section(np.array([[0, 0, 0],
                           [1, 0, 0],
                           [2, 0, 0],
                           [3, 0, 0],
                           [4, 0, 0]]))

    nt.assert_equal(_sf.section_meander_angles(s0),
                    [math.pi, math.pi, math.pi])

    s1 = Section(np.array([[0, 0, 0],
                           [1, 0, 0],
                           [1, 1, 0],
                           [2, 1, 0],
                           [2, 2, 0]]))

    nt.assert_equal(_sf.section_meander_angles(s1),
                    [math.pi / 2, math.pi / 2, math.pi / 2])

    s2 = Section(np.array([[0, 0, 0],
                           [0, 0, 1],
                           [0, 0, 2],
                           [0, 0, 0]]))

    nt.assert_equal(_sf.section_meander_angles(s2),
                    [math.pi, 0.])
Exemplo n.º 2
0
    def neurom_tree(self):
        from neurom.core import Neuron as nmNeuron
        from neurom.core import Neurite as nmNeurite
        from neurom.core import Section, Soma

        root = Section(_np.array([[0, 0, 0, 0]]))
        queue = _deque(self._root.children)
        edict = {int(self._root): root}

        sections = []

        while queue:
            node = queue.popleft()
            parent = edict[node.parent]
            enode = Section(_np.array([[0, 0, 0, 0]]))
            parent.add_child(enode)
            edict[node] = enode
            queue.extend(node.children)
            sections.append(enode)

        neurite = nmNeurite(root)
        soma = Soma(self._root.position)
        neuron = nmNeuron(soma, [neurite], [sections])

        return neuron
Exemplo n.º 3
0
def test_section_type():

    sec = Section([], section_type=nm.AXON)
    nt.eq_(sec.type, nm.AXON)

    sec = Section([], section_type=nm.BASAL_DENDRITE)
    nt.eq_(sec.type, nm.BASAL_DENDRITE)
Exemplo n.º 4
0
def test_neurite_type():
    root_node = Section(POINTS0, section_type=nm.AXON)
    nrt = Neurite(root_node)
    nt.eq_(nrt.type, nm.AXON)

    root_node = Section(POINTS0, section_type=nm.BASAL_DENDRITE)
    nrt = Neurite(root_node)
    nt.eq_(nrt.type, nm.BASAL_DENDRITE)
Exemplo n.º 5
0
def test_trunk_origin_elevations():
    class Mock(object):
        pass

    n0 = Mock()
    n1 = Mock()

    s = make_soma([[0, 0, 0, 4]])
    t0 = Section(((1, 0, 0, 2), (2, 1, 1, 2)))
    t0.type = NeuriteType.basal_dendrite
    t1 = Section(((0, 1, 0, 2), (1, 2, 1, 2)))
    t1.type = NeuriteType.basal_dendrite
    n0.neurites = [Neurite(t0), Neurite(t1)]
    n0.soma = s

    t2 = Section(((0, -1, 0, 2), (-1, -2, -1, 2)))
    t2.type = NeuriteType.basal_dendrite
    n1.neurites = [Neurite(t2)]
    n1.soma = s

    pop = Population([n0, n1])
    nt.eq_(list(_nf.trunk_origin_elevations(pop)),
           [0.0, np.pi/2., -np.pi/2.])

    nt.eq_(
        list(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.basal_dendrite)),
        [0.0, np.pi/2., -np.pi/2.])

    nt.eq_(len(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.axon)),
           0)

    nt.eq_(len(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.apical_dendrite)),
           0)
Exemplo n.º 6
0
def test_neurite_type():
    root_node = Section(POINTS0, section_type=nm.AXON)
    nrt = Neurite(root_node)
    nt.eq_(nrt.type, nm.AXON)

    root_node = Section(POINTS0, section_type=nm.BASAL_DENDRITE)
    nrt = Neurite(root_node)
    nt.eq_(nrt.type, nm.BASAL_DENDRITE)

    # https://github.com/BlueBrain/NeuroM/issues/697
    nt.assert_equal(np.array([nm.AXON, nm.BASAL_DENDRITE]).dtype, np.object)
Exemplo n.º 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]))
Exemplo n.º 8
0
def _genetate_tree_non_monotonic_section_boundary():

    tree = Section(np.array([[0, 0, 0, 1.0, 0, 0],
                             [0, 0, 0, 0.75, 0, 0],
                             [0, 0, 0, 0.5, 0, 0],
                             [0, 0, 0, 0.25, 0, 0]]))

    ch0 = Section(np.array([[0, 0, 0, 0.375, 0, 0],
                            [0, 0, 0, 0.125, 0, 0],
                            [0, 0, 0, 0.0625, 0, 0]]))

    tree.add_child(ch0)
    tree.type = NeuriteType.undefined
    return Neurite(tree)
Exemplo n.º 9
0
def test_section_tortuosity_looping_section():
    sec = Section([
        (0, 0, 0), (1, 0, 0), (1, 2, 0), (0, 2, 0), (0, 0, 0)
    ])

    with warnings.catch_warnings(record=True):
        nt.eq_(_sf.section_tortuosity(sec), np.inf)
Exemplo n.º 10
0
def make_neurites(rdw):
    """Build neurite trees from a raw data wrapper."""
    post_action = _NEURITE_ACTION[rdw.fmt]
    trunks = rdw.neurite_root_section_ids()
    if not trunks:
        return [], []

    # One pass over sections to build nodes
    nodes = tuple(Section(section_id=i,
                          points=rdw.data_block[sec.ids],
                          section_type=_TREE_TYPES[sec.ntype])
                  for i, sec in enumerate(rdw.sections))

    # One pass over nodes to connect children to parents
    for i, node in enumerate(nodes):
        parent_id = rdw.sections[i].pid
        parent_type = nodes[parent_id].type
        # only connect neurites
        if parent_id != ROOT_ID and parent_type != NeuriteType.soma:
            nodes[parent_id].add_child(node)

    neurites = tuple(Neurite(nodes[i]) for i in trunks)

    if post_action is not None:
        for n in neurites:
            post_action(n.root_node)

    return neurites, nodes
Exemplo n.º 11
0
def test_locate_segment_position():
    s = Section(np.array([[0, 0, 0, 0], [3, 0, 4, 100], [6, 4, 4, 200]]))
    nt.assert_equal(
        _sf.locate_segment_position(s, 0.0),
        (0, 0.0)
    )
    nt.assert_equal(
        _sf.locate_segment_position(s, 0.25),
        (0, 2.5)
    )
    nt.assert_equal(
        _sf.locate_segment_position(s, 0.75),
        (1, 2.5)
    )
    nt.assert_equal(
        _sf.locate_segment_position(s, 1.0),
        (1, 5.0)
    )
    nt.assert_raises(
        ValueError,
        _sf.locate_segment_position, s, 1.1
    )
    nt.assert_raises(
        ValueError,
        _sf.locate_segment_position, s, -0.1
    )
Exemplo n.º 12
0
def test_one_point_branch():
    test_section = Neurite(Section(points=np.array([[1., 1., 1., 0.5, 2, 1, 0]])))
    for diameter_scale, linewidth in it.product((1.0, None),
                                                (0.0, 1.2)):
        with get_fig_2d() as (fig, ax):
            view.plot_tree(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth)
        with get_fig_3d() as (fig, ax):
            view.plot_tree3d(ax, test_section, diameter_scale=diameter_scale, linewidth=linewidth)
Exemplo n.º 13
0
def _generate_back_track_tree(n, dev):

    tree = Section(
        np.array([[0., 0., 0., 0.2, 1., 0.,
                   0.], [0., 1., 0., 0.15, 1., 0., 0.],
                  [0., 2., 0., 0.14, 1., 0., 0.]]))

    ch0 = Section(
        np.array([[0., 2., 0., 0.14, 1., 0.,
                   0.], [1., 3., 0., 0.15, 1., 0., 0.],
                  [2., 4., 0., 0.11, 1., 0., 0.]]))

    ch1 = Section(
        np.array([[0., 2., 0., 0.14, 1., 0., 0.],
                  [1., -3., 0., 0.15, 1., 0., 0.],
                  [2., -4., 0., 0.12, 1., 0., 0.],
                  [dev[0], dev[1], dev[2], 0.11, 1., 0., 0.],
                  [3., -5., 0., 0.1, 1., 0., 0.],
                  [4., -6., 0., 0.1, 1., 0., 0.]]))

    tree.add_child(ch0)
    tree.add_child(ch1)
    tree.children[1].points[3] += tree.children[n].points[1]
    tree.type = NeuriteType.undefined

    return Neurite(tree)
Exemplo n.º 14
0
    def fake_tree(init_radius, mode):

        radius = init_radius

        sec = []
        for _ in range(5):
            sec.append([0, 0, 0, radius, 0, 0])
            radius = new_radius(radius, mode)

        return Section(np.array(sec))
Exemplo n.º 15
0
def test_section_tortuosity_looping_section():
    sec = Section([(0, 0, 0), (1, 0, 0), (1, 2, 0), (0, 2, 0), (0, 0, 0)])

    # is infinity
    nt.eq_(_sf.section_tortuosity(sec), np.inf)
    nt.ok_(math.isinf(_sf.section_tortuosity(sec)))
    nt.ok_(np.isinf(_sf.section_tortuosity(sec)))

    # is not NaN
    nt.ok_(not math.isnan(_sf.section_tortuosity(sec)))
    nt.ok_(not np.isnan(_sf.section_tortuosity(sec)))
Exemplo n.º 16
0
def test_trunk_origin_elevations():
    class Mock(object):
        pass

    n0 = Mock()
    n1 = Mock()

    s = make_soma([[0, 0, 0, 4]])
    t0 = Section(((1, 0, 0, 2), (2, 1, 1, 2)))
    t0.type = NeuriteType.basal_dendrite
    t1 = Section(((0, 1, 0, 2), (1, 2, 1, 2)))
    t1.type = NeuriteType.basal_dendrite
    n0.neurites = [Neurite(t0), Neurite(t1)]
    n0.soma = s

    t2 = Section(((0, -1, 0, 2), (-1, -2, -1, 2)))
    t2.type = NeuriteType.basal_dendrite
    n1.neurites = [Neurite(t2)]
    n1.soma = s

    pop = Population([n0, n1])
    nt.eq_(list(_nf.trunk_origin_elevations(pop)), [0.0, np.pi / 2.0, -np.pi / 2.0])

    nt.eq_(
        list(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.basal_dendrite)),
        [0.0, np.pi / 2.0, -np.pi / 2.0],
    )

    nt.eq_(len(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.axon)), 0)

    nt.eq_(len(_nf.trunk_origin_elevations(pop, neurite_type=NeuriteType.apical_dendrite)), 0)
Exemplo n.º 17
0
def _generate_back_track_tree(n, dev):

    tree = Section(np.array([[0., 0., 0., 0.2, 1., 0., 0.],
                             [0., 1., 0., 0.15, 1., 0., 0.],
                             [0., 2., 0., 0.14, 1., 0., 0.]]))

    ch0 = Section(np.array([[0., 2., 0., 0.14, 1., 0., 0.],
                            [1., 3., 0., 0.15, 1., 0., 0.],
                            [2., 4., 0., 0.11, 1., 0., 0.]]))

    ch1 = Section(np.array([[0., 2., 0., 0.14, 1., 0., 0.],
                            [1., -3., 0., 0.15, 1., 0., 0.],
                            [2., -4., 0., 0.12, 1., 0., 0.],
                            [dev[0], dev[1], dev[2], 0.11, 1., 0., 0.],
                            [3., -5., 0., 0.1, 1., 0., 0.],
                            [4., -6., 0., 0.1, 1., 0., 0.]]))

    tree.add_child(ch0)
    tree.add_child(ch1)
    tree.children[1].points[3] += tree.children[n].points[1]
    tree.type = NeuriteType.undefined

    return Neurite(tree)
Exemplo n.º 18
0
def _genetate_tree_non_monotonic_section_boundary():

    tree = Section(
        np.array([[0, 0, 0, 1.0, 0, 0], [0, 0, 0, 0.75, 0, 0],
                  [0, 0, 0, 0.5, 0, 0], [0, 0, 0, 0.25, 0, 0]]))

    ch0 = Section(
        np.array([[0, 0, 0, 0.375, 0, 0], [0, 0, 0, 0.125, 0, 0],
                  [0, 0, 0, 0.0625, 0, 0]]))

    tree.add_child(ch0)
    tree.type = NeuriteType.undefined
    return Neurite(tree)
Exemplo n.º 19
0
def test_principal_direction_extents():
    # test with a realistic neuron
    nrn = nm.load_neuron(os.path.join(H5_PATH, 'bio_neuron-000.h5'))

    p_ref = [
        1672.9694359427331, 142.43704397865031, 226.45895382204986,
        415.50612748523838, 429.83008974193206, 165.95410536922873,
        346.83281498399697
    ]

    p = _nf.principal_direction_extents(nrn)
    _close(np.array(p), np.array(p_ref))


s0 = Section(42)
s1 = s0.add_child(Section(42))
s2 = s0.add_child(Section(42))
s3 = s0.add_child(Section(42))
s4 = s1.add_child(Section(42))
s5 = s1.add_child(Section(42))
s6 = s4.add_child(Section(42))
s7 = s4.add_child(Section(42))


def test_n_bifurcation_points():
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s0)), 2)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s1)), 2)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s2)), 0)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s3)), 0)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s4)), 1)
Exemplo n.º 20
0
def test_section_area():

    sec = Section(POINTS)
    area = 2 * math.pi * RADIUS * REF_LEN
    nt.assert_almost_equal(sec.area, area)
Exemplo n.º 21
0
def test_section_volume():

    sec = Section(POINTS)
    volume = math.pi * RADIUS * RADIUS * REF_LEN
    nt.assert_almost_equal(sec.volume, volume)
Exemplo n.º 22
0
    nt.assert_true(np.allclose(a, b))


def test_principal_direction_extents():
    # test with a realistic neuron
    nrn = nm.load_neuron(os.path.join(H5_PATH, 'bio_neuron-000.h5'))

    p_ref = [1672.9694359427331, 142.43704397865031, 226.45895382204986,
             415.50612748523838, 429.83008974193206, 165.95410536922873,
             346.83281498399697]

    p = _nf.principal_direction_extents(nrn)
    _close(np.array(p), np.array(p_ref))


s0 = Section(42)
s1 = s0.add_child(Section(42))
s2 = s0.add_child(Section(42))
s3 = s0.add_child(Section(42))
s4 = s1.add_child(Section(42))
s5 = s1.add_child(Section(42))
s6 = s4.add_child(Section(42))
s7 = s4.add_child(Section(42))


def test_n_bifurcation_points():
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s0)), 2)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s1)), 2)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s2)), 0)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s3)), 0)
    nt.assert_equal(_nf.n_bifurcation_points(Neurite(s4)), 1)
Exemplo n.º 23
0
def test_section_length():

    sec = Section(POINTS)
    nt.assert_almost_equal(sec.length, REF_LEN)
Exemplo n.º 24
0
def test_init_empty():

    sec = Section([])
    nt.ok_(sec.id is None)
    nt.eq_(sec.type, nm.NeuriteType.undefined)
    nt.eq_(len(sec.points), 0)
Exemplo n.º 25
0
def test_section_id():

    sec = Section([], section_id=42)
    nt.eq_(sec.id, 42)
Exemplo n.º 26
0
from neurom.core import Neurite, Section

RADIUS = 4.
POINTS0 = np.array([[0., 0., 0., RADIUS], [0., 0., 1., RADIUS],
                    [0., 0., 2., RADIUS], [0., 0., 3., RADIUS],
                    [1., 0., 3., RADIUS], [2., 0., 3., RADIUS],
                    [3., 0., 3., RADIUS]])

POINTS1 = np.array([[3., 0., 3., RADIUS], [3., 0., 4., RADIUS],
                    [3., 0., 5., RADIUS], [3., 0., 6., RADIUS],
                    [4., 0., 6., RADIUS], [5., 0., 6., RADIUS],
                    [6., 0., 6., RADIUS]])

REF_LEN = 12

ROOT_NODE = Section(POINTS0)
ROOT_NODE.add_child(Section(POINTS1))


def test_init():
    nrt = Neurite(ROOT_NODE)
    nt.eq_(nrt.type, nm.NeuriteType.undefined)
    nt.eq_(len(nrt.points), 13)


def test_neurite_type():
    root_node = Section(POINTS0, section_type=nm.AXON)
    nrt = Neurite(root_node)
    nt.eq_(nrt.type, nm.AXON)

    root_node = Section(POINTS0, section_type=nm.BASAL_DENDRITE)
Exemplo n.º 27
0
def test_section_meander_angles_single_segment():
    s = Section(np.array([[0, 0, 0], [1, 1, 1]]))
    nt.assert_equal(len(_sf.section_meander_angles(s)), 0)
Exemplo n.º 28
0
def test_section_area():
    sec = Section(np.array([[0, 0, 0, 1], [1, 0, 0, 1]]))
    area = _sf.section_area(sec)
    nt.eq_(math.pi * 1 * 2 * 1, area)
Exemplo n.º 29
0
                   [1., 0., 3., RADIUS],
                   [2., 0., 3., RADIUS],
                   [3., 0., 3., RADIUS]])

POINTS1 = np.array([[3., 0., 3., RADIUS],
                   [3., 0., 4., RADIUS],
                   [3., 0., 5., RADIUS],
                   [3., 0., 6., RADIUS],
                   [4., 0., 6., RADIUS],
                   [5., 0., 6., RADIUS],
                   [6., 0., 6., RADIUS]])

REF_LEN = 12


ROOT_NODE = Section(POINTS0)
ROOT_NODE.add_child(Section(POINTS1))


def test_init():
    nrt = Neurite(ROOT_NODE)
    nt.eq_(nrt.type, nm.NeuriteType.undefined)
    nt.eq_(len(nrt.points), 13)


def test_neurite_type():
    root_node = Section(POINTS0, section_type=nm.AXON)
    nrt = Neurite(root_node)
    nt.eq_(nrt.type, nm.AXON)

    root_node = Section(POINTS0, section_type=nm.BASAL_DENDRITE)
Exemplo n.º 30
0
def test_setion_tortuosity_single_point():
    sec = Section([(1, 2, 3)])
    nt.eq_(_sf.section_tortuosity(sec), 1.0)
Exemplo n.º 31
0
def test_setion_tortuosity_empty_section():
    sec = Section([])
    nt.eq_(_sf.section_tortuosity(sec), 1.0)
Exemplo n.º 32
0
def test_one_point_branch():
    test_section = Section(points=np.array([[1., 1., 1., 0.5, 2, 1, 0]]))
    for diameter, linewidth in it.product((True, False),
                                          (0.0, 1.2)):
        view.tree(test_section, diameter=diameter, linewidth=linewidth)
        view.tree3d(test_section, diameter=diameter, linewidth=linewidth)