示例#1
0
def test_all():
    try:
        subprocess.call([
            'git', 'clone',
            'ssh://bbpcode.epfl.ch/experiment/MorphologyRepository'
        ])
    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)
示例#2
0
def diff(morph1, morph2, rtol=1.e-5, atol=1.e-8):
    """Returns a DiffResult object that is equivalent to True when morphologies differ.

    Additional information about why they differ is stored in DiffResult.info
    Morphologies with different formats can be compared.
    Morphologies are considered different if one of the following property differ:
    - number of root sections
    - sections type
    - sections point array
    - sections diameter array
    - sections perimeter array
    - sections number of children
    The soma are NOT taken into consideration

    Args:
        morph1 (str|morphio.Morphology|morphio.mut.Morphology): a morphology
        morph2 (str|morphio.Morphology|morphio.mut.Morphology): a morphology
        rtol (float): the relative tolerance used for comparing points (see numpy.isclose help)
        atol (float): the absolute tolerance used for comparing points (see numpy.isclose help)
    """
    if not isinstance(morph1, Morphology):
        morph1 = Morphology(morph1)
    if not isinstance(morph2, Morphology):
        morph2 = Morphology(morph2)

    if len(morph1.root_sections) != len(morph2.root_sections):
        return DiffResult(True,
                          'Both morphologies have a different number of root sections')

    for section1, section2 in zip(morph1.iter(), morph2.iter()):
        for attrib in ['points', 'diameters', 'perimeters']:
            val1, val2 = getattr(section1, attrib), getattr(section2, attrib)
            if val1.shape != val2.shape:
                return DiffResult(True,
                                  f'Attributes Section.{attrib} of:\n'
                                  f'{section1}\n'
                                  f'{section2}\n'
                                  f'have different shapes: {val1.shape} vs {val2.shape}'
                                  )
            is_close = np.isclose(val1, val2, rtol=rtol, atol=atol)
            if not is_close.all():
                first_diff_index = np.where(~is_close)[0][0]

                return DiffResult(True,
                                  f'Attributes Section.{attrib} of:\n'
                                  f'{section1}\n{section2}\nhave the same shape '
                                  'but different values\n'
                                  f'Vector {attrib} differs at index {first_diff_index}: '
                                  f'{val1[first_diff_index]} != {val2[first_diff_index]}')
        if section1.type != section2.type:
            return DiffResult(True,
                              f'{section1} and {section2} have different section types')
        if len(section1.children) != len(section2.children):
            return DiffResult(True,
                              f'{section1} and {section2} have a different number of children')

    return DiffResult(False)
示例#3
0
def test_iter():
    neuron = Morphology(os.path.join(_path, "iterators.asc"))
    root = neuron.root_sections[0]
    assert_array_equal(
        [section.id for section in root.iter(IterType.depth_first)],
        [0, 1, 2, 3, 4, 5, 6])
    assert_array_equal(
        [section.id for section in root.iter(IterType.breadth_first)],
        [0, 1, 4, 2, 3, 5, 6])

    assert_array_equal(
        [section.id for section in neuron.iter(IterType.breadth_first)],
        [0, 7, 1, 4, 8, 9, 2, 3, 5, 6])

    for _, cell in CELLS.items():
        assert_array_equal([section.id for section in cell.iter()],
                           [0, 1, 2, 3, 4, 5])
        assert_array_equal(
            [section.id for section in cell.iter(IterType.depth_first)],
            [0, 1, 2, 3, 4, 5])
        assert_array_equal([
            section.points for section in
            cell.root_sections[0].children[0].iter(IterType.upstream)
        ], [[[0., 5., 0.], [-5., 5., 0.]], [[0., 0., 0.], [0., 5., 0.]]])
示例#4
0
def test_single_point_section_duplicate_parent():
    '''Section is made only of the duplicate point'''
    with tmp_asc_file('''
                     ((Dendrite)
                      (3 -4 0 2)
                      (3 -10 0 2)
                      (
                        (3 -10 0 4)  ; duplicate point
                      )
                     )''') as tmp_file:

        neuron = Morphology(tmp_file.name)

    assert_array_equal(neuron.root_sections[0].points,
                       [[3., -4., 0.], [3., -10., 0.]])
示例#5
0
def test_get_cut_leaves():
    filename = DATA / "Neuron_slice.h5"
    neuron = Morphology(filename)
    plane = HalfSpace(0, 0, 1, -48, upward=False)
    leaves, quality = test_module._get_cut_leaves(plane,
                                                  neuron,
                                                  bin_width=10,
                                                  percentile_threshold=70.0)
    expected_leaves = np.array(
        [
            [63.97578, 61.525646, 44.460205],
            [70.55578, 91.74565, 44.070206],
            [-99.83422, -2.2443538, 48.600204],
            [-141.51422, 20.185646, 48.680206],
            [-53.534218, 97.40565, 46.410206],
            [56.855785, -71.19435, 43.360207],
            [36.015785, 4.5756464, 44.460205],
            [34.875782, 4.8656464, 39.140205],
            [16.155783, -22.084354, 45.860207],
            [34.845783, 3.395646, 39.690205],
            [61.365784, -80.39435, 40.550205],
            [85.11578, -43.264355, 44.380207],
            [39.885784, -15.054354, 45.240204],
            [88.63578, 11.385646, 45.080204],
            [132.03578, 48.625645, 40.160206],
            [-14.654218, -9.674354, 47.270206],
            [-30.674217, -16.844355, 45.710205],
            [-35.614216, -15.954353, 46.570206],
            [-24.964218, -0.52435374, 46.640205],
            [-16.084217, 19.265646, 46.490204],
            [-6.4742174, 13.075646, 46.180206],
            [-7.8942175, 29.275646, 45.390205],
            [28.885782, 36.645645, 42.660206],
            [27.375782, 49.955647, 45.860207],
            [-3.6142175, 44.925648, 46.020206],
            [-65.55422, 55.615646, 39.140205],
            [37.635784, 43.825645, 43.990204],
            [48.415783, 65.95565, 42.500206],
            [21.215782, 49.985645, 44.140205],
            [35.525784, 70.56565, 42.890205],
            [5.3857822, 61.325645, 44.930206],
        ],
        dtype=float,
    )
    assert_array_almost_equal(np.array(leaves, dtype=float),
                              expected_leaves,
                              decimal=5)
    assert_equal(quality, 25.0)
示例#6
0
def test_single_children():
    '''Single children are merged with their parent'''
    with tmp_asc_file('''
                     ((Dendrite)
                      (3 -4 0 2)
                      (3 -6 0 2)
                      (3 -8 0 2)
                      (3 -10 0 2)
                      (
                        (3 -10 0 2)  ; merged with parent section
                        (0 -10 0 2)  ; merged with parent section
                        (-3 -10 0 2) ; merged with parent section
                        (
                          (-5 -5 5 5)
                          |
                          (-6 -6 6 6)
                        )
                       )
                      )
                 ''') as tmp_file:

        with captured_output() as (_, err):
            with ostream_redirect(stdout=True, stderr=True):
                n = Morphology(tmp_file.name)
                assert_substring(
                    'is the only child of section: 0 starting at:',
                    err.getvalue().strip())
                assert_substring('It will be merged with the parent section',
                                 err.getvalue().strip())

        nt.assert_equal(len(n.soma.points), 0)
        nt.assert_equal(len(n.soma.points), 0)
        assert_equal(len(n.root_sections), 1)
        assert_array_equal(
            n.root_sections[0].points,
            np.array([[3, -4, 0], [3, -6, 0], [3, -8, 0], [3, -10, 0],
                      [0, -10, 0], [-3, -10, 0]],
                     dtype=np.float32))

        assert_equal(len(n.root_sections[0].children), 2)

        assert_array_equal(n.root_sections[0].children[0].points,
                           np.array([[-3, -10, 0], [-5, -5, 5]]))

        assert_array_equal(n.root_sections[0].children[1].points,
                           np.array([[-3, -10, 0], [-6, -6, 6]]))
示例#7
0
def test_soma():
    with tmp_asc_file('''("CellBody"
                         (Color Red)
                         (CellBody)
                         (1 1 0 1 S1)
                         (-1 1 0 1 S2)
                         (-1 -1 0 2 S3)
                         )''') as tmp_file:

        n = Morphology(tmp_file.name)

        assert_array_equal(n.soma.points,
                           [[1, 1, 0],
                            [-1, 1, 0],
                            [-1, -1, 0]])

        nt.assert_equal(len(n.root_sections), 0)
示例#8
0
def test_read_single_neurite():
    '''Test reading a simple neuron consisting of a point soma
    and a single branch neurite.'''
    with tmp_swc_file('''1 1 0 4 0 3.0 -1
                         2 3 0 0 2 0.5 1
                         3 3 0 0 3 0.5 2
                         4 3 0 0 4 0.5 3
                         5 3 0 0 5 0.5 4''') as tmp_file:
        n = Morphology(tmp_file.name)

    assert_array_equal(n.soma.points, [[0, 4, 0]])
    assert_array_equal(n.soma.diameters, [6.0])
    assert len(n.root_sections) == 1
    assert n.root_sections[0].id == 0
    assert len(n.root_sections) == 1
    assert_array_equal(n.root_sections[0].points,
                       np.array([[0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5]]))
    assert_array_equal(n.section_offsets, [0, 4])
示例#9
0
def test_single_neurite_no_soma():
    with tmp_asc_file('''
                      ( (Color Yellow)
                         (Axon)
                         (Set "axons")
                         (  1.2  2.7   1.0     13)
                         (  1.2  3.7   2.0     13)
                      )''') as tmp_file:
        n = Morphology(tmp_file.name)

        assert_array_equal(n.soma.points, np.empty((0, 3)))
        nt.assert_equal(len(n.root_sections), 1)
        assert_array_equal(
            n.root_sections[0].points,
            np.array([[1.2, 2.7, 1.0], [1.2, 3.7, 2.0]], dtype=np.float32))

        assert_array_equal(n.root_sections[0].diameters,
                           np.array([13., 13.], dtype=np.float32))
示例#10
0
def test_point_to_section_segment():
    neuron = Morphology(DATA / 'apical_test.h5')

    section, segment = spatial.point_to_section_segment(neuron, [0., 25., 0.])
    assert section == 1
    assert segment == 1

    with pytest.raises(ValueError):
        spatial.point_to_section_segment(neuron, [24, 0, 0])

    section, segment = spatial.point_to_section_segment(neuron, [0., 25.1, 0.],
                                                        rtol=1e-1,
                                                        atol=1e-1)
    assert section == 1
    assert segment == 1

    section, segment = spatial.point_to_section_segment(
        neuron, [0., 25.0001, 0.])
    assert section == 1
    assert segment == 1
示例#11
0
def test_simple_reversed():
    with tmp_swc_file('''# This is the same as 'simple.swc',
                         # except w/ leaf nodes before their parents
                         1 1  0  0 0 1. -1
                         2 3 -5  5 0 0.  7
                         3 3  6  5 0 0.  7
                         4 2  6 -4 0 0.  9
                         5 2 -5 -4 0 0.  9
                         6 3  0  0 0 1.  1
                         7 3  0  5 0 1.  6
                         8 2  0  0 0 1.  1
                         9 2  0 -4 0 1.  8 ''') as tmp_file:
        n = Morphology(tmp_file.name)
    assert_array_equal(n.soma.points, [[0, 0, 0]])
    nt.assert_equal(len(n.root_sections), 2)
    assert_array_equal(n.root_sections[0].points, [[0, 0, 0], [0, 5, 0]])
    assert_array_equal(n.root_sections[1].points, [[0, 0, 0], [0, -4, 0]])
    assert_array_equal(n.root_sections[1].children[0].points,
                       [[0, -4, 0], [6, -4, 0]])
    assert_array_equal(n.root_sections[1].children[1].points,
                       [[0, -4, 0], [-5, -4, 0]])
示例#12
0
def test_skip_comments():
    '''Test skipping comments'''
    with tmp_swc_file(('#a comment\n'
                       '# a comment\n'
                       ' # a comment\n'
                       '  #  a comment\n'
                       '1 1 0 4 0 3.0 -1\n'
                       '\t#a tab comment\n'
                       '\t#\ta tab comment\n'
                       '\t\t#\t\ta a tab comment\n'
                       '2 3 0 0 2 0.5 1\n'
                       '3 3 0 0 3 0.5 2\n'
                       '4 3 0 0 4 0.5 3\n'
                       '5 3 0 0 5 0.5 4\n')) as tmp_file:
        n = Morphology(tmp_file.name)
    assert_array_equal(n.soma.points, [[0, 4, 0]])
    assert_array_equal(n.soma.diameters, [6.0])

    nt.eq_(len(n.root_sections), 1)
    assert_array_equal(n.root_sections[0].points,
                       np.array([[0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5]]))
示例#13
0
def test_skip_header():
    '''Test that the header does not cause any issue'''
    with tmp_asc_file('''(FilledCircle
                         (Color RGB (64, 0, 128))
                         (Name "Marker 11")
                         (Set "axons")
                         ( -189.59    55.67    28.68     0.12)  ; 1
                         )  ;  End of markers

                         ((Color Yellow)
                         (Axon)
                         (Set "axons")
                         (  1.2  2.7   1.0     13)
                         (  1.2  3.7   2.0     13)
                         )''') as tmp_file:

        n = Morphology(tmp_file.name)
        nt.assert_equal(len(n.root_sections), 1)
        assert_array_equal(
            n.root_sections[0].points,
            np.array([[1.2, 2.7, 1.0], [1.2, 3.7, 2.0]], dtype=np.float32))
示例#14
0
def test_empty_sibling():
    '''The empty sibling will be removed and the single child will be merged
    with its parent'''
    with captured_output() as (_, err):
        with ostream_redirect(stdout=True, stderr=True):
            with tmp_asc_file('''((Dendrite)
                      (3 -4 0 2)
                      (3 -6 0 2)
                      (3 -8 0 2)
                      (3 -10 0 2)
                      (
                        (3 -10 0 2)
                        (0 -10 0 2)
                        (-3 -10 0 2)
                        |       ; <-- empty sibling but still works !
                       )
                      )
                 ''') as tmp_file:
                n = Morphology(tmp_file.name)
                assert_substring('is the only child of section: 0 starting at:',
                                 err.getvalue().strip())
                assert_substring('It will be merged with the parent section',
                                 err.getvalue().strip())

    assert_equal(len(n.root_sections), 1)
    assert_array_equal(n.root_sections[0].points,
                       np.array([[3, -4, 0],
                                 [3, -6, 0],
                                 [3, -8, 0],
                                 [3, -10, 0],
                                 [0, -10, 0],
                                 [-3, -10, 0]],
                                dtype=np.float32))

    assert_equal(len(n.annotations), 1)
    annotation = n.annotations[0]
    assert_equal(annotation.type, morphio.AnnotationType.single_child)
    assert_equal(annotation.line_number, 6)
    assert_array_equal(annotation.points, [[3, -10, 0], [0, -10, 0], [-3, -10, 0]])
    assert_array_equal(annotation.diameters, [2, 2, 2])
示例#15
0
def test_explicit_duplicates_with_arbitrary_diameter():
    '''If the duplicate is already in the file with an arbitrary diameter, it should be preserved'''
    with tmp_asc_file('''
                     ((Dendrite)
                      (3 -4 0 5)
                      (3 -6 0 5)
                      (3 -8 0 5)
                      (3 -10 0 5)
                      (
                        (3 -10 0 20) ; duplicate
                        (0 -10 0 2)
                        (-3 -10 0 0.3)
                        |
                        (3 -10 0 2)
                        (6 -10 0 2)
                        (9 -10 0 0.3)
                      )
                      )
                     ''') as tmp_file:
        n = Morphology(tmp_file.name)
        assert_array_equal(n.root_sections[0].children[0].diameters,
                           np.array([20, 2, 0.3], dtype=np.float32))
示例#16
0
def test_read_with_duplicates():
    '''Section points are duplicated in the file
what I think the
https://developer.humanbrainproject.eu/docs/projects/morphology-documentation/0.0.2/h5v1.html
would look like'''

    with tmp_asc_file(with_duplicate) as tmp_file:
        n = Morphology(tmp_file.name)

    nt.assert_equal(len(n.root_sections), 1)

    assert_array_equal(n.root_sections[0].points, [
        [3, -4, 0],
        [3, -6, 0],
        [3, -8, 0],
        [3, -10, 0],
    ])

    assert_array_equal(n.root_sections[0].children[0].points,
                       [[3, -10, 0], [0, -10, 0], [-3, -10, 0]])

    assert_array_equal(n.root_sections[0].children[1].points,
                       [[3, -10, 0], [6, -10, 0], [9, -10, 0]])
示例#17
0
def test_read_duplicate():
    '''Test reading a simple neuron consisting of a point soma
    and a single branch neurite.'''
    with tmp_swc_file('''# A simple neuron with a duplicate point
                         # at the bifurcation
                         #
                         # soma point
                         1 1 1 0 1 4.0 -1
                         # root section
                         2 3 0 0 2 0.5 1
                         3 3 0 0 3 0.5 2
                         # first child: real duplicate
                         4 3 0 0 3 0.5 3
                         5 3 0 0 7 0.5 4
                         # second child: duplicate with different diameter
                         6 3 0 0 3 2.3 3
                         7 3 0 0 8 3.5 6
                         # third child: no duplicate
                         8 3 1 0 0 2.3 3
                         9 3 1 1 0 3.5 8''') as tmp_file:

        n = Morphology(tmp_file.name)

    nt.eq_(len(n.root_sections), 1)
    nt.eq_(len(n.root_sections[0].children), 3)
    child1, child2, child3 = n.root_sections[0].children
    assert_array_equal(n.root_sections[0].points,
                       np.array([[0, 0, 2], [0, 0, 3]]))
    assert_array_equal(child1.points, np.array([[0, 0, 3], [0, 0, 7]]))
    assert_array_equal(child2.points, np.array([[0, 0, 3], [0, 0, 8]]))
    assert_array_equal(child3.points,
                       np.array([[0, 0, 3], [1, 0, 0], [1, 1, 0]]))
    assert_array_equal(child1.diameters, np.array([1, 1]))
    assert_array_equal(child2.diameters, np.array([4.6, 7], dtype=np.float32))
    assert_array_equal(child3.diameters, np.array([1, 4.6, 7],
                                                  dtype=np.float32))
示例#18
0
def test_no_duplicate():
    with captured_output():
        with ostream_redirect(stdout=True, stderr=True):
            m = Morphology(SIMPLE, options=Option.no_duplicates)

    neurite1 = [[[0., 0., 0.], [0, 5, 0]], [[-5, 5, 0]], [[6, 5, 0]]]

    neurite2 = [[[0, 0, 0], [0, -4, 0]], [[6, -4, 0]], [[-5, -4, 0]]]

    assert_array_equal([section.points.tolist() for section in m.iter()],
                       neurite1 + neurite2)

    # Combining options NO_DUPLICATES and NRN_ORDER
    with captured_output():
        with ostream_redirect(stdout=True, stderr=True):
            m = Morphology(SIMPLE,
                           options=Option.no_duplicates | Option.nrn_order)
    assert_array_equal([section.points.tolist() for section in m.iter()],
                       neurite2 + neurite1)
示例#19
0
def test_build_read_only():
    m = Morphology()
    m.soma.points = [[-1, -2, -3]]
    m.soma.diameters = [-4]

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

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

    section.append_section(
        PointLevel([[4, 5, 6], [10, 11, 12]], [2, 2], [20, 20]))

    immutable_morphology = ImmutableMorphology(m)

    sections = list(immutable_morphology.iter())
    assert_equal(len(sections), 3)

    assert_array_equal(immutable_morphology.soma.points, [[-1, -2, -3]])
    assert_array_equal(immutable_morphology.soma.diameters, [-4])

    assert_array_equal(
        immutable_morphology.section(0).points, [[1, 2, 3], [4, 5, 6]])
    assert_array_equal(immutable_morphology.section(0).diameters, [2, 2])
    assert_array_equal(immutable_morphology.section(0).perimeters, [20, 20])

    assert_equal(len(immutable_morphology.section(0).children), 2)

    child = immutable_morphology.section(0).children[0]
    assert_array_equal(child.points, [[4, 5, 6], [7, 8, 9]])
    assert_array_equal(child.diameters, [2, 3])
    assert_array_equal(child.perimeters, [20, 30])

    same_child = immutable_morphology.section(1)
    assert_array_equal(same_child.points, [[4, 5, 6], [7, 8, 9]])
    assert_array_equal(same_child.diameters, [2, 3])
    assert_array_equal(same_child.perimeters, [20, 30])
示例#20
0
def test_no_duplicate():
    with captured_output():
        with ostream_redirect(stdout=True, stderr=True):
            m = Morphology(SIMPLE, options=Option.no_duplicates)

    neurite1 = np.array([[0., 0., 0.], [0, 5, 0], [-5, 5, 0], [6, 5, 0]])

    neurite2 = np.array([[0, 0, 0], [0, -4, 0], [6, -4, 0], [-5, -4, 0]])

    assert_array_equal(np.vstack([section.points for section in m.iter()]),
                       np.vstack([neurite1, neurite2]))

    # Combining options NO_DUPLICATES and NRN_ORDER
    with captured_output():
        with ostream_redirect(stdout=True, stderr=True):
            m = Morphology(SIMPLE,
                           options=Option.no_duplicates | Option.nrn_order)
    assert_array_equal(np.vstack([section.points for section in m.iter()]),
                       np.vstack([neurite2, neurite1]))
示例#21
0
def test_three_point_soma():
    n = Morphology(os.path.join(_path, 'three_point_soma.swc'))
    assert_equal(n.soma_type, SomaType.SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS)
示例#22
0
def test_multiple_soma():
    with pytest.raises(SomaError, match='Multiple somata found') as e:
        Morphology(os.path.join(_path, 'multiple_soma.swc'))
    assert e.match('multiple_soma.swc:2:error')
    assert e.match('multiple_soma.swc:11:error')
示例#23
0
def test_soma_type():
    '''The ordering of IDs is not required'''
    # 1 point soma
    with tmp_swc_file('''1 1 0 0 0 3.0 -1''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_SINGLE_POINT)

    # 2 point soma
    with tmp_swc_file('''1 1 0 0 0 3.0 -1
                         2 1 0 0 0 3.0  1''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_UNDEFINED)

    # > 3 points soma
    with tmp_swc_file('''1 1 0 0 0 3.0 -1
                         2 1 0 0 0 3.0  1
                         3 1 0 0 0 3.0  2
                         4 1 0 0 0 3.0  3
                         5 1 0 0 0 3.0  4''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_CYLINDERS)

    # 3 points soma can be of type SOMA_CYLINDERS or SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS
    # depending on the point layout

    # SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS are characterized by
    # one soma point with 2 children
    with tmp_swc_file('''1 1 0  0 0 3.0 -1
    2 1 0 -3 0 3.0  1
    3 1 0  3 0 3.0  1 # PID is 1''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type,
            SomaType.SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS)

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

            with tmp_swc_file('''1 1 0  0 0 3.0 -1
                                 2 1 1 -3 0 3.0  1
                                 3 1 0  0 0 3.0  1 # PID is 1''') as tmp_file:
                assert_equal(
                    Morphology(tmp_file.name).soma_type,
                    SomaType.SOMA_NEUROMORPHO_THREE_POINT_CYLINDERS)
                assert_string_equal(
                    '''{}:0:warning
                       Warning: the soma does not conform the three point soma spec
                       The only valid neuro-morpho soma is:
                       1 1 x   y   z r -1
                       2 1 x (y-r) z r  1
                       3 1 x (y+r) z r  1

                       Got:
                       1 1 0 0 0 3 -1
                       2 1 1.000000 (exp. 0.000000) -3.000000 0.000000 3.000000 1
                       3 1 0.000000 0.000000 (exp. 3.000000) 0.000000 3.000000 1'''
                    .format(tmp_file.name),
                    err.getvalue(),
                )


# If this configuration is not respected -> SOMA_CYLINDERS
    with tmp_swc_file('''1 1 0 0 0 3.0 -1
                         2 1 0 0 0 3.0  1
                         3 1 0 0 0 3.0  2 # PID is 2''') as tmp_file:
        assert_equal(
            Morphology(tmp_file.name).soma_type, SomaType.SOMA_CYLINDERS)
示例#24
0
import os

import numpy as np
from morphio import Morphology, Option, SectionType, ostream_redirect
from morphio.mut import Morphology as MutableMorphology
from numpy.testing import assert_array_equal

from utils import captured_output

_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
SIMPLE = os.path.join(_path, 'simple.swc')

SIMPLE_NO_MODIFIER = Morphology(SIMPLE)


def test_no_modifier():
    assert_array_equal(SIMPLE_NO_MODIFIER.points,
                       Morphology(SIMPLE, options=Option.no_modifier).points)


def test_nrn_order():
    filename = os.path.join(_path, 'reversed_NRN_neurite_order.swc')

    m = Morphology(filename, options=Option.nrn_order)
    assert ([section.type for section in m.root_sections] == [
        SectionType.axon, SectionType.basal_dendrite,
        SectionType.apical_dendrite
    ])

    normal = Morphology(filename)
    m = MutableMorphology(normal, options=Option.nrn_order)
示例#25
0
def test_version():
    assert_array_equal(
        Morphology(os.path.join(_path, 'simple.swc')).version, ('swc', 1, 0))
示例#26
0
def test_markers():
    '''Test that markers do not prevent file from being read correctly'''

    with tmp_asc_file('''
( (Color White)  ; [10,1]
  (Dendrite)
  ( -290.87  -113.09   -16.32     2.06)  ; Root
  ( -290.87  -113.09   -16.32     2.06)  ; R, 1
  (
    ( -277.14  -119.13   -18.02     0.69)  ; R-1, 1
    ( -275.54  -119.99   -16.67     0.69)  ; R-1, 2
    (Cross  ;  [3,3]
      (Color Orange)
      (Name "Marker 3")
      ( -271.87  -121.14   -16.27     0.69)  ; 1
      ( -269.34  -122.29   -15.48     0.69)  ; 2
    )  ;  End of markers
     Normal
  |
    ( -277.80  -120.28   -19.48     0.92)  ; R-2, 1
    ( -276.65  -121.14   -20.20     0.92)  ; R-2, 2
    (Cross  ;  [3,3]
      (Color Orange)
      (Name "Marker 3")
      ( -279.41  -119.99   -18.00     0.46)  ; 1
      ( -272.98  -126.60   -21.22     0.92)  ; 2
    )  ;  End of markers
    (
      ( -267.94  -128.61   -22.57     0.69)  ; R-2-1, 1
      ( -204.90  -157.63   -42.45     0.69)  ; R-2-1, 34
      (Cross  ;  [3,3]
        (Color Orange)
        (Name "Marker 3")
        ( -223.67  -157.92   -42.45     0.69)  ; 1
        ( -222.76  -154.18   -39.90     0.69)  ; 2
      )  ;  End of markers
       Incomplete
    |
      ( -269.77  -129.47   -22.57     0.92)  ; R-2-2, 1
      ( -268.17  -130.62   -24.75     0.92)  ; R-2-2, 2
      ( -266.79  -131.77   -26.13     0.92)  ; R-2-2, 3
       Incomplete
    )  ;  End of split
  )  ;  End of split
)
''') as tmp_file:

        n = Morphology(tmp_file.name)

        nt.assert_equal(len(n.root_sections), 1)

        assert_array_equal(
            n.root_sections[0].points,
            np.array([
                [-290.87, -113.09, -16.32],
                [-290.87, -113.09, -16.32],
            ],
                     dtype=np.float32))

        assert_array_equal(
            n.root_sections[0].children[0].points,
            np.array([[-290.87, -113.09, -16.32], [-277.14, -119.13, -18.02],
                      [-275.54, -119.99, -16.67]],
                     dtype=np.float32))

        assert_array_equal(
            n.root_sections[0].children[1].points,
            np.array([[-290.87, -113.09, -16.32], [-277.80, -120.28, -19.48],
                      [-276.65, -121.14, -20.20]],
                     dtype=np.float32))

        assert_array_equal(
            n.root_sections[0].children[1].children[0].points,
            np.array([[-276.65, -121.14, -20.20], [-267.94, -128.61, -22.57],
                      [-204.90, -157.63, -42.45]],
                     dtype=np.float32))

        assert_array_equal(
            n.root_sections[0].children[1].children[1].points,
            np.array([[-276.65, -121.14, -20.20], [-269.77, -129.47, -22.57],
                      [-268.17, -130.62, -24.75], [-266.79, -131.77, -26.13]],
                     dtype=np.float32))
示例#27
0
def test_no_modifier():
    assert_array_equal(SIMPLE_NO_MODIFIER.points,
                       Morphology(SIMPLE, options=Option.no_modifier).points)
示例#28
0
def test_mutable_immutable_equivalence():
    morpho = ImmutableMorphology(os.path.join(_path, "simple.swc"))
    assert_array_equal(morpho.points,
                       morpho.as_mutable().as_immutable().points)
示例#29
0
def test__find_apical_section_segment():
    neuron = Morphology(os.path.join(DATA, 'apical_test.swc'))
    section, segment = apical_point_section_segment(neuron)
    eq_(section, 1)
    eq_(segment, 1)
示例#30
0
def test_soma_sphere():
    m = Morphology(os.path.join(_path, 'soma_multiple_frustums.swc'),
                   options=Option.soma_sphere)
    assert_array_equal(m.soma.points, [[1.5, 0, 0]])