예제 #1
0
def _integration_tree():

    xyzdtp = np.array([
       [  5.,  -2.,   5.,   0.2,   3.,  -1.],
       [ 11.,  -5.,  12.,   0.2,   3.,   0.],
       [ 18.,  -8.,  19.,   0.4,   3.,   1.],
       [ 24., -11.,  26.,   0.2,   3.,   2.],
       [ 31., -14.,  33.,   0.4,   3.,   3.],
       [ 38., -16.,  40.,   0.6,   3.,   4.],
       [ 45., -18.,  47.,   0.8,   3.,   5.],
       [ 52., -19.,  53.,   0.6,   3.,   6.],
       [ 37., -17.,  39.,   0.4,   3.,   4.],
       [ 44., -20.,  46.,   0.2,   3.,   8.],
       [ 50., -23.,  53.,   0.2,   3.,   9.],
       [ 57., -26.,  60.,   0.4,   3.,  10.],
       [ 63., -29.,  67.,   0.6,   3.,  11.],
       [ 70., -32.,  74.,   0.8,   3.,  12.],
       [ 24., -10.,  26.,   1.0,   3.,   2.],
       [ 31., -12.,  33.,   0.8,   3.,  14.],
       [ 39., -13.,  40.,   0.6,   3.,  15.]])

    return Tree.Tree(
        x=xyzdtp[:, 0], y=xyzdtp[:, 1], z=xyzdtp[:, 2],
        d=xyzdtp[:, 3], t=xyzdtp[:, 4].astype(int), p=xyzdtp[:, 5].astype(int)
    )
예제 #2
0
파일: test_tree.py 프로젝트: vsukhor/TMD
def test_tree_init_():
    tree1 = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p1)
    nt.ok_(np.allclose(tree1.x, x1))
    nt.ok_(np.allclose(tree1.y, y1))
    nt.ok_(np.allclose(tree1.z, z1))
    nt.ok_(np.allclose(tree1.d, d1))
    nt.ok_(np.allclose(tree1.t, t1))
    nt.ok_(np.allclose(tree1.p, p1))
예제 #3
0
파일: io.py 프로젝트: eleftherioszisis/TMD
def make_tree(data):
    '''Make tree structure from loaded data.
       Returns a tree of tmd.Tree
       type.
    '''
    tr_data = _np.transpose(data)

    parents = [_np.where(tr_data[0] == i)[0][0]
               if len(_np.where(tr_data[0] == i)[0]) > 0
               else - 1 for i in tr_data[6]]

    return Tree.Tree(x=tr_data[SWC_DCT['x']], y=tr_data[SWC_DCT['y']], z=tr_data[SWC_DCT['z']],
                     d=tr_data[SWC_DCT['radius']], t=tr_data[SWC_DCT['type']], p=parents)
예제 #4
0
def test_parents_children():

    tree = Tree.Tree(x=np.zeros(5),
                     y=np.zeros(5),
                     z=np.zeros(5),
                     d=np.zeros(5),
                     t=np.zeros(5),
                     p=np.array([-1, 0, 1, 2, 2]))

    parents, children = tree.parents_children

    assert parents == {0: -1, 2: 0, 3: 2, 4: 2}

    expected_children = {2: [3, 4]}

    for key, values in expected_children.items():
        npt.assert_array_equal(children[key], values)
예제 #5
0
파일: test_io.py 프로젝트: masht18/TMD
# Filenames for testing
basic_file = os.path.join(DATA_PATH, 'basic.swc')
nosecids_file = os.path.join(DATA_PATH, 'basic_no_sec_ids.swc')
sample_file = os.path.join(DATA_PATH, 'sample.swc')

sample_h5_v1_file = os.path.join(DATA_PATH, 'sample_v1.h5')
sample_h5_v2_file = os.path.join(DATA_PATH, 'sample_v2.h5')
sample_h5_v0_file = os.path.join(DATA_PATH, 'sample_v0.h5')

neuron_v1 = io.load_neuron(sample_h5_v1_file)
neuron_v2 = io.load_neuron(sample_h5_v2_file)
neuron1 = io.load_neuron(sample_file)

soma_test = Soma.Soma([0.], [0.], [0.], [12.])
soma_test1 = Soma.Soma([0.], [0.], [0.], [6.])
apical_test = Tree.Tree(x=np.array([5., 5.]), y=np.array([6., 6.]), z=np.array([7., 7.]),
                        d=np.array([16., 16.]), t=np.array([4, 4]), p=np.array([-1,  0]))
basal_test = Tree.Tree(x=np.array([4.]), y=np.array([5.]), z=np.array([6.]),
                       d=np.array([14.]), t=np.array([3]), p=np.array([-1]))
axon_test = Tree.Tree(x=np.array([3.]), y=np.array([4.]), z=np.array([5.]),
                      d=np.array([12.]), t=np.array([2]), p=np.array([-1]))


def test_type_dict():
    nt.ok_(io.TYPE_DCT == {'soma': 1,
                           'basal': 3,
                           'apical': 4,
                           'axon': 2})


def test_load_swc_neuron():
    neuron = io.load_neuron(basic_file)
예제 #6
0
파일: test_tree.py 프로젝트: vsukhor/TMD
def test_copy_tree():
    tree1 = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p1)
    tree2 = tree1.copy_tree()
    nt.ok_(tree1.is_equal(tree2))
    nt.ok_(tree1 != tree2)
예제 #7
0
파일: test_tree.py 프로젝트: vsukhor/TMD
def test_tree_is_equal():
    tree1 = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p1)
    tree2 = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p1)
    nt.ok_(tree1.is_equal(tree2))
    tree3 = Tree.Tree(x=x2, y=y1, z=z1, d=d1, t=t1, p=p1)
    nt.ok_(not tree1.is_equal(tree3))
예제 #8
0
])

secs_h5_end_points = np.array([
    16, 17, 21, 30, 52, 78, 86, 91, 190, 196, 219, 222, 230, 249, 256, 301,
    330, 334, 385, 406, 409, 454, 482, 494, 508, 519, 522, 612, 640, 645, 678,
    682, 684, 710, 730, 738, 772, 795, 804, 828, 829, 832, 838
])

x1 = np.array([0., 1., 2., 3., 4.])
y1 = np.array([0., 2., 3., 4., 5.])
z1 = np.array([0., 3., 4., 5., 6.])
d1 = np.array([2., 4., 6., 8., 10.])
t1 = np.array([2, 2, 2, 2, 2])
p1 = np.array([-1, 0, 1, 2, 1])

tree = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p1)


def test_rd():
    nt.ok_(methods._rd([0, 0], [0, 1]) == 1.)
    nt.ok_(methods._rd([0, 0, 0], [0, 0, 1]) == 1.)
    nt.ok_(methods._rd([1, 2, 0], [0, 2, 1]) == np.sqrt(2.))


# def test_rd_w():
#    nt.ok_(methods._rd_w([0,0], [0,1], w=[0., 1.]) == 1.)
#    nt.ok_(methods._rd_w([0,0], [1,1], w=[0., 2.], normed=False) == 2.)
#    nt.ok_(methods._rd_w([0,0], [1,1], w=[0., 0.], normed=False) == 0.)
#    nt.ok_(methods._rd_w([1,2,0], [0,2,1], normed=False) == methods._rd([1,2,0], [0,2,1]))

예제 #9
0
DATA_PATH = os.path.join(_path, '../../../test_data')

sample_ph_0 = os.path.join(DATA_PATH, 'sample_ph_0.txt')
sample_ph_1 = os.path.join(DATA_PATH, 'sample_ph_1.txt')

x1 = np.array([0.,  0.,   0.,  1.,   1.])
y1 = np.array([0.,  1.,  -1.,  1.,   0.])
z1 = np.array([0.,  0.,   0,   0.,  -1.])
d1 = np.array([2.,  2.,  2.,  2.,  2.])
t1 = np.array([ 1,  1,  1,  1,  1])
p1 = np.array([-1,  0,  1,  2,  3])

x2 = np.array([0.,  3.,  4.,  5.,  4.])
p2 = np.array([-1,  0,  1,  1,  1])

tree = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p1)
tree_trifork = Tree.Tree(x=x1, y=y1, z=z1, d=d1, t=t1, p=p2)

# ===================================== tree0 =======================================

x2 = np.array([0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1., -2.,
       -3., -4., -5.,  1.,  2.,  3.,  4.,  5.,  5.,  5.,  5.,  5.,  5.,
        5.,  5.,  5.,  5.,  5.])
y2 = np.array([0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10., 10., 10.,
       10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.,
       10., 10., 10., 10., 10.])
z2 = np.array([0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  2.,  3.,  4.,  5.,
       -1., -2., -3., -4., -5.])
d2 = np.array([0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4,
       0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4,
예제 #10
0
def convert_morphio_trees(morphio_neuron):
    """Convert morphio morphology's trees to tmd ones

    Args:
        morphio_neuron (Union[morphio.Morphology, morphio.mut.Morphology]):
            morphio neuron object

    Yields:
        tuple:
            - tree (Tree): The constructed tmd Tree
            - tree_types (dict): The neuron tree types
    """
    total_points = len(morphio_neuron.diameters)

    x = np.empty(total_points, dtype=np.float32)
    y = np.empty(total_points, dtype=np.float32)
    z = np.empty(total_points, dtype=np.float32)
    d = np.empty(total_points, dtype=np.float32)
    t = np.empty(total_points, dtype=np.int32)
    p = np.empty(total_points, dtype=np.int64)

    section_final_nodes = np.empty(total_points, dtype=np.int)

    tree_end = 0
    for root in morphio_neuron.root_sections:

        tree_length = 0
        tree_beg = tree_end

        for section in root.iter():

            # root sections have parent -1
            if section.is_root:
                start = 0
                parent = -1
            else:
                # tmd does not use a duplicate point representation
                # thus the first point of the section is dropped
                start = 1
                parent = section_final_nodes[section.parent.id]

            n, data = _section_to_data(section, tree_length, start, parent)

            x[tree_end:n + tree_end] = data.points[:, 0]
            y[tree_end:n + tree_end] = data.points[:, 1]
            z[tree_end:n + tree_end] = data.points[:, 2]
            d[tree_end:n + tree_end] = data.diameters
            t[tree_end:n + tree_end] = data.section_type
            p[tree_end:n + tree_end] = data.parents

            tree_end += n
            tree_length += n

            # keep track of the last node in the section because we need
            # to establish the correct connectivity when we ommit the first
            # point from the children sections
            section_final_nodes[section.id] = tree_length - 1

        yield Tree.Tree(x=x[tree_beg:tree_end],
                        y=y[tree_beg:tree_end],
                        z=z[tree_beg:tree_end],
                        d=d[tree_beg:tree_end],
                        t=t[tree_beg:tree_end],
                        p=p[tree_beg:tree_end])