How to use the morphio.mut.Morphology function in morphio

To help you get started, we’ve selected a few morphio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BlueBrain / MorphIO / tests / test_8_all_morphologies.py View on Github external
except:
        pass

    not_same_same = list()

    def walk(folder):
        import os
        for root, _, files in os.walk(folder):
            for file in files:
                yield os.path.join(root, file)

    # for i, f in enumerate(filter(_is_good_file, walk('MorphologyRepository'))):
    for i, f in enumerate(not_same_same_list):
        print(i)
        print(f)
        m = MutMorphology(f)
        immut = Morphology(f)
        try:
            m.write_h5('morph.h5')
        except MorphioError:
            continue

        m.write_swc('morph.swc')
        m.write_asc('morph.asc')
        same_same = ((immut == Morphology("morph.h5")) and
                     (immut == Morphology("morph.swc")) and
                     (immut == Morphology("morph.asc")))

        if not same_same:
            not_same_same.append(f)
    print(not_same_same)
github BlueBrain / MorphIO / tests / test_7_modifiers.py View on Github external
m = Morphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'), options=Option.nrn_order)
    assert_equal([section.type for section in m.root_sections],
                 [SectionType.axon,
                  SectionType.basal_dendrite,
                  SectionType.apical_dendrite])


    normal = Morphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'))
    m = MutableMorphology(normal, options=Option.nrn_order)
    assert_equal([section.type for section in m.root_sections],
                 [SectionType.axon,
                  SectionType.basal_dendrite,
                  SectionType.apical_dendrite])

    normal = MutableMorphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'))
    m = MutableMorphology(normal, options=Option.nrn_order)
    assert_equal([section.type for section in m.root_sections],
                 [SectionType.axon,
                  SectionType.basal_dendrite,
                  SectionType.apical_dendrite])
github BlueBrain / MorphIO / tests / test_5_mut.py View on Github external
def test_empty_neurite():
    m = Morphology()
    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):
            root = m.append_root_section(PointLevel(), SectionType.axon)
            assert_equal(err.getvalue().strip(),
                         'Warning: appending empty section with id: 0')

    assert_equal(len(m.root_sections), 1)
    assert_equal(m.root_sections[0].type,
                 SectionType.axon)

    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):
            root.append_section(PointLevel(), SectionType.axon)
            assert_equal(err.getvalue().strip(),
                         'Warning: appending empty section with id: 1')
github BlueBrain / MorphIO / tests / test_7_modifiers.py View on Github external
def test_nrn_order():
    m = Morphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'), options=Option.nrn_order)
    assert_equal([section.type for section in m.root_sections],
                 [SectionType.axon,
                  SectionType.basal_dendrite,
                  SectionType.apical_dendrite])


    normal = Morphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'))
    m = MutableMorphology(normal, options=Option.nrn_order)
    assert_equal([section.type for section in m.root_sections],
                 [SectionType.axon,
                  SectionType.basal_dendrite,
                  SectionType.apical_dendrite])

    normal = MutableMorphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'))
    m = MutableMorphology(normal, options=Option.nrn_order)
    assert_equal([section.type for section in m.root_sections],
                 [SectionType.axon,
                  SectionType.basal_dendrite,
                  SectionType.apical_dendrite])
github BlueBrain / MorphIO / tests / test_6_writers.py View on Github external
def test_write_no_soma():
    morpho = Morphology()
    dendrite = morpho.append_root_section(
                                     PointLevel([[0, 0, 0],
                                                 [0, 5, 0]],
                                                [2, 2],
                                                [5, 6]),
                                     SectionType.basal_dendrite)
    dendrite = morpho.append_root_section(
                                     PointLevel([[0, 1, 0],
                                                 [0, 7, 0]],
                                                [2, 2],
                                                [5, 6]),
                                     SectionType.basal_dendrite)

    with setup_tempdir('test_write_no_soma') as tmp_folder:
        for ext in ['asc', 'h5', 'swc']:
            with captured_output() as (_, err):
github BlueBrain / MorphIO / tests / test_6_writers.py View on Github external
def test_mitochondria():
    morpho = Morphology()
    morpho.soma.points = [[0, 0, 0], [1, 1, 1]]
    morpho.soma.diameters = [1, 1]

    neuronal_section_ids = [0, 0]
    relative_pathlengths = np.array([0.5, 0.6], dtype=np.float32)
    diameters = [10, 20]
    mito_id = morpho.mitochondria.append_root_section(
        MitochondriaPointLevel(neuronal_section_ids,
                                   relative_pathlengths,
                                   diameters))

    mito_id.append_section(
        MitochondriaPointLevel([0, 0, 0, 0],
                                        [0.6, 0.7, 0.8, 0.9],
                                        [20, 30, 40, 50]))
    with setup_tempdir('test_mitochondria') as tmp_folder:
github BlueBrain / MorphIO / tests / test_5_mut.py View on Github external
def test_append_no_duplicate():
    m = Morphology()

    section = m.append_root_section(PointLevel([[1, 2, 3], [4, 5, 6]],
                                               [2, 2],
                                               [20, 20]),
                                    SectionType.axon)
    assert_equal(section.id, 0)

    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):

            section.append_section(
                             PointLevel([[400, 5, 6], [7, 8, 9]],
                                        [2, 3],
                                        [20, 30]))
            assert_equal(err.getvalue().strip(),
                         'Warning: while appending section: 1 to parent: 0\n'
github BlueBrain / MorphIO / tests / test_5_mut.py View on Github external
def test_mitochondria_read():
    '''Read a H5 file with a mitochondria'''
    morpho = Morphology(os.path.join(_path, "h5/v1/mitochondria.h5"))
    mito = morpho.mitochondria
    assert_equal(len(mito.root_sections), 2)

    mitochondria = mito.root_sections

    assert_array_equal(mitochondria[0].diameters,
                       [10, 20])
    assert_array_equal(mitochondria[0].relative_path_lengths,
                       np.array([0.5, 0.6], dtype=np.float32))
    assert_array_equal(mitochondria[0].neurite_section_ids,
                       np.array([0., 0.], dtype=np.float32))

    assert_equal(len(mito.children(mito.root_sections[0])), 1)

    assert_equal(mito.parent(mito.children(mitochondria[0])[0]),
                 mitochondria[0])
github BlueBrain / MorphIO / tests / test_6_writers.py View on Github external
def test_write_perimeter():
    morpho = Morphology()
    morpho.soma.points = [[0, 0, 0]]
    morpho.soma.diameters = [2]

    dendrite = morpho.append_root_section(
                                     PointLevel([[0, 0, 0],
                                                 [0, 5, 0]],
                                                [2, 2],
                                                [5, 6]),
                                     SectionType.basal_dendrite)

    dendrite.append_section(
                          PointLevel([[0, 5, 0],
                                      [-5, 5, 0]],
                                     [2, 3],
                                     [6, 7]))
github BlueBrain / MorphIO / tests / test_5_mut.py View on Github external
def test_child_section():
    m = Morphology()
    section = m.append_root_section(PointLevel([[1, 2, 3]], [2], [20]),
                                    SectionType.axon)

    ok_(section.is_root)

    section.append_section(PointLevel([[1, 2, 3], [4, 5, 6]],
                                      [2, 3],
                                      [20, 30]))

    children = m.root_sections[0].children

    assert_equal(len(children),
                 1)

    assert_array_equal(children[0].points,
                       [[1, 2, 3], [4, 5, 6]])