• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tree.val_iter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neurom.core.tree.val_iter函数的典型用法代码示例。如果您正苦于以下问题:Python val_iter函数的具体用法?Python val_iter怎么用?Python val_iter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了val_iter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _evaluate

def _evaluate(tr1, tr2, comp_func):

    for v1, v2 in izip(val_iter(ipreorder(tr1)), val_iter(ipreorder(tr2))):
        #print "v1 : ", v1[:COLS.R]
        #print "v2 : ", v2[:COLS.R]
        #print "-" * 10
        nt.assert_true(comp_func(v1[:COLS.R], v2[:COLS.R]))
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:7,代码来源:test_transform.py


示例2: test_iter_points

    def test_iter_points(self):
        ref_point_radii = []
        for t in self.neuron.neurites:
            ref_point_radii.extend(p[COLS.R] for p in val_iter(ipreorder(t)))

        rads = [r for r in self.neuron.iter_points(lambda p: p[COLS.R])]
        nt.assert_true(np.all(ref_point_radii == rads))
开发者ID:wvangeit,项目名称:NeuroM,代码行数:7,代码来源:test_neuron.py


示例3: point_iter

def point_iter(iterator):
    '''Transform tree iterator into a point iterator

    Args:
        iterator: tree iterator for a tree holding raw data rows.
    '''
    return imap(as_point, tree.val_iter(iterator))
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:7,代码来源:log_neuron.py


示例4: test_copy

def test_copy():

    soma = neuron.make_soma([[0, 0, 0, 1, 1, 1, -1]])   
    nrn1 = neuron.Neuron(soma, [TREE], name="Rabbit of Caerbannog")
    nrn2 = nrn1.copy()

    # check if two neurons are identical

    # somata
    nt.assert_true(isinstance(nrn2.soma, type(nrn1.soma)))
    nt.assert_true(nrn1.soma.radius == nrn2.soma.radius)

    for v1, v2 in izip(nrn1.soma.iter(), nrn2.soma.iter()):

        nt.assert_true(np.allclose(v1, v2))

    # neurites
    for neu1, neu2 in izip(nrn1.neurites, nrn2.neurites):

        nt.assert_true(isinstance(neu2, type(neu1)))

        for v1, v2 in izip(val_iter(ipreorder(neu1)), val_iter(ipreorder(neu2))):

            nt.assert_true(np.allclose(v1, v2))

    # check if the ids are different

    # somata
    nt.assert_true( nrn1.soma is not nrn2.soma)

    # neurites
    for neu1, neu2 in izip(nrn1.neurites, nrn2.neurites):

        nt.assert_true(neu1 is not neu2)

    # check if changes are propagated between neurons

    nrn2.soma.radius = 10.

    nt.assert_false(nrn1.soma.radius == nrn2.soma.radius)
    # neurites
    for neu1, neu2 in izip(nrn1.neurites, nrn2.neurites):

        for v1, v2 in izip(val_iter(ipreorder(neu1)), val_iter(ipreorder(neu2))):

            v2 = np.array([-1000., -1000., -1000., 1000., -100., -100., -100.])
            nt.assert_false(any(v1 == v2))
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:47,代码来源:test_neuron.py


示例5: test_segment_iteration

def test_segment_iteration():

    nt.assert_equal(list(val_iter(isegment(REF_TREE))),
           [(0, 11),(11, 111),(11, 112),
            (0, 12),(12, 121),(121,1211),
            (1211,12111),(1211,12112),(12, 122)])

    nt.assert_equal(list(val_iter(isegment(REF_TREE.children[0]))),
           [(0, 11), (11, 111),(11, 112)])

    nt.assert_equal(list(val_iter(isegment(REF_TREE.children[0].children[0]))),
                    [(11, 111)])

    nt.assert_equal(list(val_iter(isegment(REF_TREE.children[0].children[1]))),
                    [(11, 112)])

    nt.assert_equal(list(val_iter(isegment(REF_TREE.children[1]))),
           [(0, 12), (12, 121), (121, 1211),
            (1211, 12111), (1211, 12112), (12, 122)])

    nt.assert_equal(list(val_iter(isegment(REF_TREE.children[1].children[0]))),
                    [(12, 121), (121, 1211), (1211, 12111), (1211, 12112)])

    nt.assert_equal(list(val_iter(isegment(REF_TREE.children[1].children[1]))),
                    [(12, 122)])
开发者ID:wvangeit,项目名称:NeuroM,代码行数:25,代码来源:test_tree.py


示例6: calculate_and_plot_end_to_end_distance

def calculate_and_plot_end_to_end_distance(path):
    '''Calculate and plot the end-to-end distance vs the number of segments for
    an increasingly larger part of a given path.

    Note that the plots are not very meaningful for bifurcating trees.'''
    end_to_end_distance = [morphmath.point_dist(segment[1], path.value)
                           for segment in tree.val_iter(tree.isegment(path))]
    make_end_to_end_distance_plot(np.arange(len(end_to_end_distance)) + 1, end_to_end_distance,
                                  path.type)
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:9,代码来源:end_to_end_distance.py


示例7: test_ibifurcation_point_upstream

def test_ibifurcation_point_upstream():
    leaves = [l for l in ileaf(REF_TREE2)]
    ref_paths = [
        [11, 0], [11, 0], [11, 0], [11, 0],
        [1211, 12, 0], [1211, 12, 0], [12, 0]
    ]

    for l, ref in zip(leaves, ref_paths):
        nt.assert_equal([s for s in val_iter(ibifurcation_point(l, iupstream))], ref)
开发者ID:wvangeit,项目名称:NeuroM,代码行数:9,代码来源:test_tree.py


示例8: find_tree_type

def find_tree_type(tree):

    """
    Calculates the 'mean' type of the tree.
    Accepted tree types are:
    'undefined', 'axon', 'basal', 'apical'
    The 'mean' tree type is defined as the type
    that is shared between at least 51% of the tree's points.
    Returns:
        The type of the tree
    """

    tree_types = tuple(TreeType)

    types = [node[COLS.TYPE] for node in tr.val_iter(tr.ipreorder(tree))]
    types = [node[COLS.TYPE] for node in tr.val_iter(tr.ipreorder(tree))]

    return tree_types[int(np.median(types))]
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:18,代码来源:morphtree.py


示例9: neurite_centre_of_mass

def neurite_centre_of_mass(neurite):
    '''Calculate and return centre of mass of a neurite.'''
    centre_of_mass = np.zeros(3)
    total_volume = 0
    for segment in tree.val_iter(tree.isegment(neurite)):
        seg_volume = morphmath.segment_volume(segment)
        centre_of_mass = centre_of_mass + seg_volume * segment_centre_of_mass(segment)
        total_volume += seg_volume
    return centre_of_mass / total_volume
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:9,代码来源:radius_of_gyration.py


示例10: radius_of_gyration

def radius_of_gyration(neurite):
    '''Calculate and return radius of gyration of a given neurite.'''
    centre_mass = neurite_centre_of_mass(neurite)
    sum_sqr_distance = 0
    N = 0
    for segment in tree.val_iter(tree.isegment(neurite)):
        sum_sqr_distance = sum_sqr_distance + distance_sqr(centre_mass, segment)
        N += 1
    return np.sqrt(sum_sqr_distance / N)
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:9,代码来源:radius_of_gyration.py


示例11: test_leaf_iteration

def test_leaf_iteration():
    nt.ok_(list(val_iter(ileaf(REF_TREE))) == [111, 112, 12111, 12112, 122])
    nt.ok_(list(val_iter(ileaf(REF_TREE.children[0]))) == [111, 112])
    nt.ok_(list(val_iter(ileaf(REF_TREE.children[1]))) == [12111, 12112, 122])
    nt.ok_(list(val_iter(ileaf(REF_TREE.children[0].children[0]))) == [111])
    nt.ok_(list(val_iter(ileaf(REF_TREE.children[0].children[1]))) == [112])
    nt.ok_(list(val_iter(ileaf(REF_TREE.children[1].children[0]))) == [12111, 12112])
    nt.ok_(list(val_iter(ileaf(REF_TREE.children[1].children[1]))) == [122])
开发者ID:wvangeit,项目名称:NeuroM,代码行数:8,代码来源:test_tree.py


示例12: _generate_dendro

def _generate_dendro(current_node, lines, colors, n, max_dims,
                     spacing, offsets, show_diameters=True):
    '''Recursive function for dendrogram line computations
    '''

    start_x = _spacingx(current_node, max_dims, offsets, spacing)

    radii = [0., 0.]
    # store the parent radius in order to construct polygonal segments
    # isntead of simple line segments
    radii[0] = current_node.value[3] if show_diameters else 0.

    for child in current_node.children:

        # segment length
        length = segment_length(list(val_iter((current_node, child))))

        # extract the radius of the child node. Need both radius for
        # realistic segment representation
        radii[1] = child.value[3] if show_diameters else 0.

        # number of leaves in child
        terminations = n_terminations(child)

        # horizontal spacing with respect to the number of
        # terminations
        new_offsets = (start_x + spacing[0] * terminations / 2.,
                       offsets[1] + spacing[1] * 2. + length)

        # vertical segment
        lines[n[0]] = _vertical_segment(offsets, new_offsets, spacing, radii)

        # assign segment id to color array
        colors[n[0]] = child.value[4]
        n[0] += 1

        if offsets[1] + spacing[1] * 2 + length > max_dims[1]:
            max_dims[1] = offsets[1] + spacing[1] * 2. + length

        # recursive call to self.
        _generate_dendro(child, lines, colors, n, max_dims,
                         spacing, new_offsets, show_diameters=show_diameters)

        # update the starting position for the next child
        start_x += terminations * spacing[0]

        # write the horizontal lines only for bifurcations, where the are actual horizontal lines
        # and not zero ones
        if offsets[0] != new_offsets[0]:

            # horizontal segment
            lines[n[0]] = _horizontal_segment(offsets, new_offsets, spacing, 0.)
            colors[n[0]] = current_node.value[4]
            n[0] += 1
开发者ID:wvangeit,项目名称:NeuroM,代码行数:54,代码来源:dendrogram.py


示例13: nonzero_neurite_radii

def nonzero_neurite_radii(neuron, threshold=0.0):
    '''Check presence of neurite points with radius not above threshold

    Arguments:
        neuron: Neuron object whose segments will be tested
        threshold: value above which a radius is considered to be non-zero
    Return: list of IDs of zero-radius points
    '''

    ids = [[i[COLS.ID] for i in val_iter(ipreorder(t))
            if i[COLS.R] <= threshold] for t in neuron.neurites]
    return [i for i in chain(*ids)]
开发者ID:wvangeit,项目名称:NeuroM,代码行数:12,代码来源:morphology.py


示例14: nonzero_segment_lengths

def nonzero_segment_lengths(neuron, threshold=0.0):
    '''Check presence of neuron segments with length not above threshold

    Arguments:
        neuron: Neuron object whose segments will be tested
        threshold: value above which a segment length is considered to be non-zero
    Return: list of (first_id, second_id) of zero length segments
    '''
    l = [[s for s in val_iter(isegment(t))
          if segment_length(s) <= threshold]
         for t in neuron.neurites]
    return [(i[0][COLS.ID], i[1][COLS.ID]) for i in chain(*l)]
开发者ID:wvangeit,项目名称:NeuroM,代码行数:12,代码来源:morphology.py


示例15: nonzero_section_lengths

def nonzero_section_lengths(neuron, threshold=0.0):
    '''Check presence of neuron sections with length not above threshold

    Arguments:
        neuron: Neuron object whose segments will be tested
        threshold: value above which a section length is considered to be non-zero
    Return: list of ids of first point in bad sections
    '''
    l = [[s for s in val_iter(isection(t))
          if section_length(s) <= threshold]
         for t in neuron.neurites]
    return [i[0][COLS.ID] for i in chain(*l)]
开发者ID:wvangeit,项目名称:NeuroM,代码行数:12,代码来源:morphology.py


示例16: test_upstream_iteration

def test_upstream_iteration():

    nt.ok_(list(val_iter(iupstream(REF_TREE))) == [0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0]))) == [11, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0].children[0]))) == [111, 11, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[0].children[1]))) == [112, 11, 0])

    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1]))) == [12, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1].children[0]))) == [121, 12, 0])
    nt.ok_(list(val_iter(iupstream(REF_TREE.children[1].children[1]))) == [122, 12, 0])
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:10,代码来源:test_tree.py


示例17: test_make_copy

def test_make_copy():

    tree_copy = make_copy(REF_TREE3)

    # assert that the two trees have the same values

    # first by total nodes
    nt.assert_true(len(list(ipreorder(tree_copy))) == len(list(ipreorder(REF_TREE3))))

    # then node by node
    for val1, val2 in izip(val_iter(ipreorder(tree_copy)), val_iter(ipreorder(REF_TREE3))):

        nt.assert_true(all(val1 == val2))

    # assert that the tree values do not have the same identity
    for val1, val2 in izip(val_iter(ipreorder(tree_copy)), val_iter(ipreorder(REF_TREE3))):

        nt.assert_false(val1 is val2)

    # create a deepcopy of the original tree for validation
    validation_tree = deepcopy(REF_TREE3)

    # modify copied tree
    tree_copy.value[0:3] = np.array([1000.0, 1000.0, -1000.0])
    tree_copy.children[0].add_child(Tree(np.array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0])))

    # check if anything changed in REF_TREE3 with respect to the validation deepcopy
    nt.assert_true(len(list(ipreorder(validation_tree))) == len(list(ipreorder(REF_TREE3))))
    for val1, val2 in izip(val_iter(ipreorder(REF_TREE3)), val_iter(ipreorder(validation_tree))):

        nt.assert_true(all(val1 == val2))
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:31,代码来源:test_tree.py


示例18: test_section_upstream_iteration

def test_section_upstream_iteration():
    leaves = [l for l in ileaf(REF_TREE2)]
    ref_paths = [
        [(1111, 11111), (11, 111, 1111), (0, 11)],
        [(1111, 11112), (11, 111, 1111), (0, 11)],
        [(1111, 11113), (11, 111, 1111), (0, 11)],
        [(11, 112), (0, 11)],
        [(1211, 12111), (12, 121, 1211), (0, 12)],
        [(1211, 12112), (12, 121, 1211), (0, 12)],
        [(12, 122), (0, 12)]]

    for l, ref in zip(leaves, ref_paths):
        nt.assert_equal([s for s in val_iter(isection(l, iupstream))], ref)
开发者ID:wvangeit,项目名称:NeuroM,代码行数:13,代码来源:test_tree.py


示例19: compare_trees

def compare_trees(tree1, tree2):
    '''
    Comparison between all the nodes and their respective radii between two trees.
    Ids are do not have to be identical between the trees, and swapping is allowed

    Returns:

        False if the trees are not identical. True otherwise.
    '''
    leaves1 = list(tr.ileaf(tree1))
    leaves2 = list(tr.ileaf(tree2))

    if len(leaves1) != len(leaves2):

        return False

    else:

        nleaves = len(leaves1)

        for leaf1, leaf2 in product(leaves1, leaves2):

            is_equal = True

            for node1, node2 in izip(tr.val_iter(tr.iupstream(leaf1)),
                                     tr.val_iter(tr.iupstream(leaf2))):

                if any(node1[0:5] != node2[0:5]):

                    is_equal = False
                    continue

            if is_equal:
                nleaves -= 1

    return nleaves == 0
开发者ID:Tsolmongerel,项目名称:NeuroM,代码行数:36,代码来源:morphtree.py


示例20: get_bounding_box

def get_bounding_box(tree):
    """
    Returns:
        The boundaries of the tree in three dimensions:
            [[xmin, ymin, zmin],
            [xmax, ymax, zmax]]
    """

    min_xyz, max_xyz = (np.array([np.inf, np.inf, np.inf]), np.array([np.NINF, np.NINF, np.NINF]))

    for p in val_iter(tr.ipreorder(tree)):
        min_xyz = np.minimum(p[: COLS.R], min_xyz)
        max_xyz = np.maximum(p[: COLS.R], max_xyz)

    return np.array([min_xyz, max_xyz])
开发者ID:wvangeit,项目名称:NeuroM,代码行数:15,代码来源:morphtree.py



注:本文中的neurom.core.tree.val_iter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tree.Tree类代码示例发布时间:2022-05-27
下一篇:
Python neurom.load_neuron函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap