Exemple #1
0
def test_mitochondria():
    morpho = Morphology()
    morpho.soma.points = [[0, 0, 0], [1, 1, 1]]
    morpho.soma.diameters = [1, 1]

    morpho.append_root_section(
        PointLevel([[2, 2, 2], [3, 3, 3]], [4, 4], [5, 5]), SectionType.axon)

    mito = morpho.mitochondria
    first_mito_id = mito.append_root_section(
        MitochondriaPointLevel([0, 0], [0.5, 0.6], [10, 20]))

    first_child = first_mito_id.append_section(
        MitochondriaPointLevel([3, 4, 4, 5], [0.6, 0.7, 0.8, 0.9],
                               [20, 30, 40, 50]))

    second_mito_id = mito.append_root_section(
        MitochondriaPointLevel([0, 1, 1, 2], [0.6, 0.7, 0.8, 0.9],
                               [5, 6, 7, 8]))

    assert_equal(mito.is_root(first_mito_id), True)
    assert_equal(mito.children(first_mito_id), [first_child])
    assert_equal(mito.parent(first_child), first_mito_id)
    assert_equal(mito.root_sections, [first_mito_id, second_mito_id])

    assert_array_equal(first_child.diameters, [20, 30, 40, 50])
    assert_array_equal(first_child.neurite_section_ids, [3, 4, 4, 5])

    assert_array_equal(
        np.array(first_child.relative_path_lengths, dtype=np.float32),
        np.array([0.6, 0.7, 0.8, 0.9], dtype=np.float32))
Exemple #2
0
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:
        morpho.write(os.path.join(tmp_folder, "test.h5"))

        with captured_output() as (_, err):
            with ostream_redirect(stdout=True, stderr=True):
                morpho.write(os.path.join(tmp_folder, "test.swc"))
                assert_string_equal(
                    err.getvalue(),
                    "Warning: this cell has mitochondria, they cannot be saved in "
                    " ASC or SWC format. Please use H5 if you want to save them."
                )

        with captured_output() as (_, err):
            with ostream_redirect(stdout=True, stderr=True):
                morpho.write(os.path.join(tmp_folder, "test.asc"))
                assert_string_equal(
                    err.getvalue(),
                    "Warning: this cell has mitochondria, they cannot be saved in "
                    " ASC or SWC format. Please use H5 if you want to save them."
                )

        mito = ImmutMorphology(os.path.join(tmp_folder,
                                            'test.h5')).mitochondria
        assert_array_equal(mito.root_sections[0].diameters, diameters)
        assert_array_equal(mito.root_sections[0].neurite_section_ids,
                           neuronal_section_ids)
        assert_array_equal(mito.root_sections[0].relative_path_lengths,
                           relative_pathlengths)

        assert_equal(len(mito.root_sections), 1)

        mito = Morphology(os.path.join(tmp_folder, 'test.h5')).mitochondria
        assert_equal(len(mito.root_sections), 1)
        assert_equal(mito.root_sections[0].neurite_section_ids,
                     neuronal_section_ids)
        assert_array_equal(mito.section(0).diameters, diameters)

        assert_array_equal(
            mito.section(0).neurite_section_ids, neuronal_section_ids)