Ejemplo n.º 1
0
def test_trunk_origin_azimuths():
    n0 = MockNeuron()
    n1 = MockNeuron()
    n2 = MockNeuron()
    n3 = MockNeuron()
    n4 = MockNeuron()
    n5 = MockNeuron()

    t = PointTree((0, 0, 0, 2))
    t.type = NeuriteType.basal_dendrite
    n0.neurites = [t]
    n1.neurites = [t]
    n2.neurites = [t]
    n3.neurites = [t]
    n4.neurites = [t]
    n5.neurites = [t]
    pop = [n0, n1, n2, n3, n4, n5]
    s0 = make_soma([[0, 0, 1, 4]])
    s1 = make_soma([[0, 0, -1, 4]])
    s2 = make_soma([[0, 0, 0, 4]])
    s3 = make_soma([[-1, 0, -1, 4]])
    s4 = make_soma([[-1, 0, 0, 4]])
    s5 = make_soma([[1, 0, 0, 4]])

    pop[0].soma = s0
    pop[1].soma = s1
    pop[2].soma = s2
    pop[3].soma = s3
    pop[4].soma = s4
    pop[5].soma = s5
    nt.assert_true(np.all(get_feat('trunk_origin_azimuths', pop) ==
                          [-np.pi/2., np.pi/2., 0.0, np.pi/4., 0.0, np.pi]))
    nt.eq_(len(get_feat('trunk_origin_azimuths', pop, neurite_type=NeuriteType.axon)), 0)
Ejemplo n.º 2
0
def _make_tree():
    '''This tree has 3 branching points'''
    p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2]
    T = PointTree(p)
    T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 2.0, 1, 1, 2]))
    T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 3.0, 1, 1, 2]))
    T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 4.0, 1, 1, 2]))
    T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 5.0, 1, 1, 2]))
    T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 6.0, 1, 1, 2]))
    T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 7.0, 1, 1, 2]))
    return T
Ejemplo n.º 3
0
def _make_neuron_tree():
    p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2]
    T = PointTree(p)
    T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2]))
    T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2]))
    T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2]))
    T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2]))
    T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2]))
    T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2]))
    T10 = T9.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2]))
    return T
Ejemplo n.º 4
0
def _make_simple_tree():
    p = [0.0, 0.0, 0.0, 1.0, 1, 1, 1]
    T = PointTree(p)
    T1 = T.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 1]))
    T2 = T1.add_child(PointTree([0.0, 4.0, 0.0, 1.0, 1, 1, 1]))
    T3 = T2.add_child(PointTree([0.0, 6.0, 0.0, 1.0, 1, 1, 1]))
    T4 = T3.add_child(PointTree([0.0, 8.0, 0.0, 1.0, 1, 1, 1]))

    T5 = T.add_child(PointTree([0.0, 0.0, 2.0, 1.0, 1, 1, 1]))
    T6 = T5.add_child(PointTree([0.0, 0.0, 4.0, 1.0, 1, 1, 1]))
    T7 = T6.add_child(PointTree([0.0, 0.0, 6.0, 1.0, 1, 1, 1]))
    T8 = T7.add_child(PointTree([0.0, 0.0, 8.0, 1.0, 1, 1, 1]))

    return T
Ejemplo n.º 5
0
def _make_odd_tree():
    ''' The infamous invisible tree. This should fail check
    in case of integer division in partition
    '''
    p = [0.0, 0.0, 0.0, 0.0, 0, 0, 0]
    T = PointTree(p)
    T.add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.children[1].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.children[1].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.children[1].children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    T.children[1].children[0].add_child(PointTree([0.0, 0.0, 0.0, 0.0, 0, 0, 0]))
    return T
Ejemplo n.º 6
0
def test_principal_direction_extent():

    points = np.array([[-10., 0., 0.],
                        [-9., 0., 0.],
                        [9., 0., 0.],
                        [10., 0., 0.]])

    tree = PointTree(np.array([points[0][0], points[0][1], points[0][2], 1., 0., 0.]))
    tree.add_child(PointTree(np.array([points[1][0], points[1][1], points[1][2], 1., 0., 0.])))
    tree.children[0].add_child(PointTree(np.array([points[2][0], points[2][1], points[2][2], 1., 0., 0.])))
    tree.children[0].add_child(PointTree(np.array([points[3][0], points[3][1], points[3][2], 1., 0., 0.])))

    extent = mtr.principal_direction_extent(tree)

    nt.assert_true(np.allclose(extent, [20., 0., 0.]))
Ejemplo n.º 7
0
def _form_branching_tree():
    p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2]
    T = PointTree(p)
    T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2]))
    T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2]))
    T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2]))
    T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2]))
    T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2]))
    T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2]))
    T10 = T9.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2]))
    T11 = T9.add_child(PointTree([0.0, 6.0, 4.0, 0.75, 1, 1, 2]))
    T33 = T3.add_child(PointTree([1.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T331 = T33.add_child(PointTree([15.0, 15.0, 0.0, 2.0, 1, 1, 2]))
    return T
Ejemplo n.º 8
0
def test_principal_directions_extents():
    points = np.array([[-10., 0., 0.],
                       [-9., 0., 0.],
                       [9., 0., 0.],
                       [10., 0., 0.]])

    tree = PointTree(np.array([points[0][0], points[0][1], points[0][2], 1., 0., 0.]))
    tree.add_child(PointTree(np.array([points[1][0], points[1][1], points[1][2], 1., 0., 0.])))
    tree.children[0].add_child(PointTree(np.array([points[2][0], points[2][1], points[2][2], 1., 0., 0.])))
    tree.children[0].add_child(PointTree(np.array([points[3][0], points[3][1], points[3][2], 1., 0., 0.])))

    neurites = [tree, tree, tree]
    extents0 = get_feat('principal_direction_extents', neurites, direction='first')
    nt.assert_true(np.allclose(extents0, [20., 20., 20.]))
    extents1 = get_feat('principal_direction_extents', neurites, direction='second')
    nt.assert_true(np.allclose(extents1, [0., 0., 0.]))
    extents2 = get_feat('principal_direction_extents', neurites, direction='third')
    nt.assert_true(np.allclose(extents2, [0., 0., 0.]))
Ejemplo n.º 9
0
def trunk_section_length(tree):
    '''Length of the initial tree section

    Returns:
        Length of first section of tree or 0 if single point tree
    '''
    try:
        _it = imap_val(mm.section_length, ptr.isection(tree))
        return _it.next()
    except StopIteration:
        return 0.0
Ejemplo n.º 10
0
def _make_branching_tree_zero_length_bif_segments():
    '''This tree has 3 branching points'''
    p = [0.0, 0.0, 0.0, 1.0, 1, 1, 2]
    T = PointTree(p)
    T1 = T.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2]))
    T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2]))
    T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2]))
    T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T5_0 = T4.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T5 = T5_0.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2]))
    T6_0 = T4.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T6 = T6_0.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2]))
    T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2]))
    T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2]))
    T10_0 = T9.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2]))
    T10 = T10_0.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2]))
    T11 = T9.add_child(PointTree([0.0, 6.0, 4.0, 0.75, 1, 1, 2]))
    T33 = T3.add_child(PointTree([1.0, 5.0, 0.0, 2.0, 1, 1, 2]))
    T331 = T33.add_child(PointTree([15.0, 15.0, 0.0, 2.0, 1, 1, 2]))
    return T
Ejemplo n.º 11
0
def i_section_radial_dist(tree, pos=None, use_start_point=False):
    '''Return an iterator of radial distances of tree sections to a given point

    The radial distance is the euclidian distance between the either the
    end-point or rhe start point of the section and the point in question.

    Parameters:
        tree: tree object
        pos: origin to which distances are measured. It must have at least 3\
            components. The first 3 components are (x, y, z).\
            (default tree origin)

        use_start_point: If true, calculate distance from section start point,\
            else from end-point (default, False)

    '''
    pos = tree.value if pos is None else pos
    sec_idx = 0 if use_start_point else -1
    return imap_val(lambda s: mm.point_dist(s[sec_idx], pos), ptr.isection(tree))
Ejemplo n.º 12
0
def test_trunk_origin_elevations():
    n0 = MockNeuron()
    n1 = MockNeuron()

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

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

    pop = [n0, n1]
    nt.assert_true(np.all(get_feat('trunk_origin_elevations', pop) ==
                          [0.0, np.pi/2., -np.pi/2.]))
    nt.eq_(len(get_feat('trunk_origin_elevations', pop, neurite_type=NeuriteType.axon)), 0)
Ejemplo n.º 13
0
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from nose import tools as nt
import os
from neurom.point_neurite.core import iter_neurites
from neurom.point_neurite import io
from neurom.point_neurite.io.utils import make_neuron
from neurom.point_neurite.point_tree import PointTree, isection
from neurom.point_neurite import segments as seg
from neurom.point_neurite import sections as sec


# Mock tree holding integers, not points
MOCK_TREE = PointTree(0)
MOCK_TREE.add_child(PointTree(11))
MOCK_TREE.add_child(PointTree(12))
MOCK_TREE.children[0].add_child(PointTree(111))
MOCK_TREE.children[0].add_child(PointTree(112))
MOCK_TREE.children[1].add_child(PointTree(121))
MOCK_TREE.children[1].add_child(PointTree(122))
MOCK_TREE.children[1].children[0].add_child(PointTree(1211))
MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12111))
MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12112))


class MockNeuron(object):
    pass

Ejemplo n.º 14
0
def n_segments(tree):
    """
    Return number of segments in tree
    """
    return sum(1 for _ in ptr.isegment(tree))
Ejemplo n.º 15
0
def n_sections(tree):
    """
    Return number of sections in tree
    """
    return sum(1 for _ in ptr.isection(tree))
Ejemplo n.º 16
0
def test_trunk_origin_radius():
    t = PointTree((0, 0, 0, 42))
    t.add_child(PointTree((1, 0, 0, 4)))
    nt.assert_equal(mtr.trunk_origin_radius(t), 42.0)
Ejemplo n.º 17
0
def test_trunk_section_length():
    t = PointTree((0, 0, 0, 42))
    tt = t.add_child(PointTree((10, 0, 0, 4)))
    tt.add_child(PointTree((10, 15, 0, 4)))
    nt.assert_almost_equal(mtr.trunk_section_length(t), 25.0)
Ejemplo n.º 18
0
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from nose import tools as nt
from copy import deepcopy
from neurom.core._neuron import Neuron
from neurom.core import make_soma
from neurom.point_neurite.point_tree import PointTree
from neurom.point_neurite.point_tree import val_iter
from itertools import izip
import numpy as np

SOMA_SINGLE_PTS = [[11, 22, 33, 44, 1, 1, -1]]

TREE = PointTree([0.0, 0.0, 0.0, 1.0, 1, 1, 2])
T1 = TREE.add_child(PointTree([0.0, 1.0, 0.0, 1.0, 1, 1, 2]))
T2 = T1.add_child(PointTree([0.0, 2.0, 0.0, 1.0, 1, 1, 2]))
T3 = T2.add_child(PointTree([0.0, 4.0, 0.0, 2.0, 1, 1, 2]))
T4 = T3.add_child(PointTree([0.0, 5.0, 0.0, 2.0, 1, 1, 2]))
T5 = T4.add_child(PointTree([2.0, 5.0, 0.0, 1.0, 1, 1, 2]))
T6 = T4.add_child(PointTree([0.0, 5.0, 2.0, 1.0, 1, 1, 2]))
T7 = T5.add_child(PointTree([3.0, 5.0, 0.0, 0.75, 1, 1, 2]))
T8 = T7.add_child(PointTree([4.0, 5.0, 0.0, 0.75, 1, 1, 2]))
T9 = T6.add_child(PointTree([0.0, 5.0, 3.0, 0.75, 1, 1, 2]))
T10 = T9.add_child(PointTree([0.0, 6.0, 3.0, 0.75, 1, 1, 2]))


def test_deep_copy():

    soma = make_soma([[0, 0, 0, 1, 1, 1, -1]])
Ejemplo n.º 19
0
import numpy as np
from nose import tools as nt
from neurom.point_neurite.point_tree import PointTree
from neurom.point_neurite.core import Neuron
from neurom.core import make_soma
from neurom.core import NeuriteType
from neurom.point_neurite.treefunc import set_tree_type
import neurom.point_neurite.dendrogram as dm


TREE = PointTree(np.array([0., 0., 0., 10., 4., 0., 0.]))
TREE.add_child(PointTree(np.array([3., 3., 3., 9., 4., 0., 0.])))

TREE.children[0].add_child(PointTree(np.array([10., 10., 10., 5., 4., 0., 0.])))
TREE.children[0].add_child(PointTree(np.array([-10., -10., -10., 7., 4., 0., 0.])))

set_tree_type(TREE)

SOMA = make_soma(np.array([[0., 0., 0., 1., 1., 1., -1.]]))
NEURON = Neuron(SOMA, [TREE, TREE, TREE])

OLD_OFFS = [1.2, -1.2]
NEW_OFFS = [2.3, -2.3]
SPACING = (40., 0.)

def test_n_rectangles_tree():

    nt.assert_equal(dm._n_rectangles(TREE), 5)

Ejemplo n.º 20
0
import numpy as np

DATA_PATH = './test_data'
SWC_PATH = os.path.join(DATA_PATH, 'swc/')

data    = io.load_data(SWC_PATH + 'Neuron.swc')
neuron0 = make_neuron(data)
tree0   = neuron0.neurites[0]
tree_types = [NeuriteType.axon,
              NeuriteType.basal_dendrite,
              NeuriteType.basal_dendrite,
              NeuriteType.apical_dendrite]


# Mock tree holding integers, not points
MOCK_TREE = PointTree(0)
MOCK_TREE.add_child(PointTree(11))
MOCK_TREE.add_child(PointTree(12))
MOCK_TREE.children[0].add_child(PointTree(111))
MOCK_TREE.children[0].add_child(PointTree(112))
MOCK_TREE.children[1].add_child(PointTree(121))
MOCK_TREE.children[1].add_child(PointTree(122))
MOCK_TREE.children[1].children[0].add_child(PointTree(1211))
MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12111))
MOCK_TREE.children[1].children[0].children[0].add_child(PointTree(12112))
T1111 = MOCK_TREE.children[0].children[0].add_child(PointTree(1111))
T11111 = T1111.add_child(PointTree(11111))
T11112 = T1111.add_child(PointTree(11112))
T11113 = T1111.add_child(PointTree(11113))

REF_TREE3 = PointTree(np.array([0.,0.,0.,1.,0.,0.,0.]))