How to use the morphio.SectionType 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_6_writers.py View on Github external
def test_single_point_root_section():
    m = Morphology()
    points = []
    diameters = []

    # Too hide the warning: appending empty section
    with captured_output():
        with ostream_redirect(stdout=True, stderr=True):
            m.append_root_section(PointLevel(points, diameters), SectionType(2))

            with setup_tempdir('test_single_point_root_section', no_cleanup=True) as tmp_folder:
                assert_raises(SectionBuilderError, m.write, os.path.join(tmp_folder, "h5/empty_vasculature.h5"))

    m = Morphology()
    points = [[1., 1., 1.]]
    diameters = [2.]
    m.append_root_section(PointLevel(points, diameters), SectionType(2))

    with setup_tempdir('test_single_point_root_section', no_cleanup=True) as tmp_folder:
        assert_raises(SectionBuilderError, m.write, os.path.join(tmp_folder, "h5/empty_vasculature.h5"))
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,
github BlueBrain / MorphIO / tests / test_3_h5.py View on Github external
assert_equal(len(n.root_sections), 2)
    assert_equal(n.root_sections[0].type, 3)
    assert_equal(n.root_sections[1].type, 2)

    n = Morphology(os.path.join(H5V1_PATH, 'Neuron.h5'))
    assert_equal(n.version, MORPHOLOGY_VERSION_H5_1)


    assert_equal(len(n.sections), 84)
    assert_equal(len(n.soma.points), 3)
    assert_equal(len(list(n.iter())), 84)
    assert_equal(len(n.points), 924)

    section_types = list(s.type for s in n.iter())
    assert_equal(len(section_types), 84)
    real_section_types = list(chain(repeat(SectionType.apical_dendrite, 21),
                                    repeat(SectionType.basal_dendrite, 42),
                                    repeat(SectionType.axon, 21)))

    assert_equal(section_types, real_section_types)
    assert_array_equal(n.points[:7],
                       [[0.0, 0.0, 0.0],
                        [0.0, 0.0, 0.10000000149011612],
                        [0.5529246926307678, -0.7534923553466797, 0.9035181403160095],
                        [1.2052767276763916, -1.3861794471740723, 1.6835479736328125],
                        [1.2670834064483643, -1.3914604187011719, 2.4186644554138184],
                        [1.271288275718689, -2.3130500316619873, 3.192789077758789],
                        [1.605881929397583, -2.6893420219421387, 3.992844343185425]])
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_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):
                with ostream_redirect(stdout=True, stderr=True):
                    outfile = os.path.join(tmp_folder, 'tmp.' + ext)
                    morpho.write(outfile)
                    assert_equal(err.getvalue().strip(),
                                 'Warning: writing file without a soma')
github BlueBrain / MorphIO / tests / test_7_modifiers.py View on Github external
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])