Пример #1
0
    def testComparisonFailureAddingEpsilon2(self):
        """Load and complex .swc file, and
        change each [x, y, z, r] value in the vertices matrix
        individually, to check that it is not the same.
        """
        testSrcsPath = LocMgr().get_test_srcs_path()
        srcSWCFile = Join(testSrcsPath, "swc_srcs/28o_spindle20aFI.CNG.swc")

        m = MorphologyArray.fromSWC(srcSWCFile)
        MFRandom.seed(0)
        for i in range(len(m)):
            print i, len(m)
            for j in range(4):

                # Only test 2% of cases:
                if not np.random.rand() < 0.02:
                    continue

                m1 = MorphologyArray.fromSWC(srcSWCFile)
                m1._vertices[i, j] = m1._vertices[i, j] + 0.01
                assert MorphArrayComparison.are_same(m,
                                                     m1,
                                                     max_node_distance=0.02)
                assert not MorphArrayComparison.are_same(
                    m, m1, max_node_distance=0.005)
Пример #2
0
    def testComparisonFailureDifferentMorphologies(self):
        """Verify simple .swc snippets are different to each other"""

        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['A']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['B']))
        m3 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))

        assert not MorphArrayComparison.are_same(m1, m2, max_node_distance= 0.00001)
        assert not MorphArrayComparison.are_same(m1, m3, max_node_distance= 0.00001)
        assert not MorphArrayComparison.are_same(m2, m3, max_node_distance= 0.00001)
Пример #3
0
    def testComparisonFailureDifferentMorphologies(self):
        """Verify simple .swc snippets are different to each other"""

        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['A']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['B']))
        m3 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))

        assert not MorphArrayComparison.are_same(
            m1, m2, max_node_distance=0.00001)
        assert not MorphArrayComparison.are_same(
            m1, m3, max_node_distance=0.00001)
        assert not MorphArrayComparison.are_same(
            m2, m3, max_node_distance=0.00001)
Пример #4
0
    def testComparisonFailureAddingEpsilon1(self):
        """Load simple .swc snippets, and change each [x, y, z, r] value in the vertices matrix
        individually, to check that it is not the same. """

        m = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))

        for i in range(len(m)):
            for j in range(4):

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))
                m1._vertices[i, j] = m1._vertices[i, j] + 0.01
                assert MorphArrayComparison.are_same(m, m1, max_node_distance= 0.02)
                assert not MorphArrayComparison.are_same(m, m1, max_node_distance= 0.005)

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))
                m1._vertices[i, j] = m1._vertices[i, j] - 0.001
                assert MorphArrayComparison.are_same(m, m1, max_node_distance= 0.002)
                assert not MorphArrayComparison.are_same(m, m1, max_node_distance= 0.0005)

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Cii']))
                m1._vertices[i, j] = m1._vertices[i, j] + 0.01
                assert MorphArrayComparison.are_same(m, m1, max_node_distance= 0.02)
                assert not MorphArrayComparison.are_same(m, m1, max_node_distance= 0.005)

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Cii']))
                m1._vertices[i, j] = m1._vertices[i, j] - 0.001
                assert MorphArrayComparison.are_same(m, m1, max_node_distance= 0.002)
                assert not MorphArrayComparison.are_same(m, m1, max_node_distance= 0.0005)
Пример #5
0
    def testComparisonSucessful(self):
        """Verify simple .swc snippets are the same"""

        # Loading
        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['A']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['A']))
        assert MorphArrayComparison.are_same(m1, m2, max_node_distance=0.00001)

        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['B']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['B']))
        assert MorphArrayComparison.are_same(m1, m2, max_node_distance=0.00001)

        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['Cii']))
        assert MorphArrayComparison.are_same(m1, m2, max_node_distance=0.00001)
Пример #6
0
    def testComparisonFailureTransplantingALeafNode(self):
        """Remap each leaf node in a complex swc file, onto
        different internal nodes of the morphology,
        and check that the morphology is considered different
        """

        testSrcsPath = LocMgr().get_test_srcs_path()
        srcSWCFile = Join(testSrcsPath, "swc_srcs/28o_spindle20aFI.CNG.swc")

        m = MorphologyArray.fromSWC(srcSWCFile)

        # Find the leaf nodes:
        leaf_nodes = m.get_leaf_vertices_indices()

        for new_parent in [0, 10, 20, leaf_nodes[-1]]:

            for l in leaf_nodes[:-1]:
                v = m._vertices.copy()
                c = m._connectivity.copy()

                # Rewrite the connectivity matrix, mapping the
                # leaf to a new_parent:
                c[c == l] = new_parent

                mNew = MorphologyArray(vertices=v, connectivity=c)
                assert not MorphArrayComparison.are_same(
                    m, mNew, max_node_distance=0.00001)
Пример #7
0
    def testComparisonSucessful(self):
        """Verify simple .swc snippets are the same"""

        # Loading
        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['A']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['A']))
        assert MorphArrayComparison.are_same(m1, m2, max_node_distance= 0.00001)


        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['B']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['B']))
        assert MorphArrayComparison.are_same(m1, m2, max_node_distance= 0.00001)

        m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))
        m2 = MorphologyArray.fromSWC(StringIO(swc_srcs['Cii']))
        assert MorphArrayComparison.are_same(m1, m2, max_node_distance= 0.00001)
Пример #8
0
    def testComparisonFailureTransplantingALeafNode(self):
        """Remap each leaf node in a complex swc file, onto
        different internal nodes of the morphology,
        and check that the morphology is considered different
        """

        testSrcsPath = LocMgr().get_test_srcs_path()
        srcSWCFile = Join(testSrcsPath, "swc_srcs/28o_spindle20aFI.CNG.swc")

        m = MorphologyArray.fromSWC(srcSWCFile)

        # Find the leaf nodes:
        leaf_nodes = m.get_leaf_vertices_indices()

        for new_parent in [0, 10, 20, leaf_nodes[-1]]:

            for l in leaf_nodes[:-1]:
                v = m._vertices.copy()
                c = m._connectivity.copy()

                # Rewrite the connectivity matrix, mapping the
                # leaf to a new_parent:
                c[c==l]=new_parent

                mNew = MorphologyArray(vertices=v, connectivity=c)
                assert not MorphArrayComparison.are_same(m, mNew, max_node_distance= 0.00001)
Пример #9
0
    def testComparisonFailureAddingEpsilon2(self):
        """Load and complex .swc file, and
        change each [x, y, z, r] value in the vertices matrix
        individually, to check that it is not the same.
        """
        testSrcsPath = LocMgr().get_test_srcs_path()
        srcSWCFile = Join(testSrcsPath, "swc_srcs/28o_spindle20aFI.CNG.swc")

        m = MorphologyArray.fromSWC(srcSWCFile)
        MFRandom.seed(0)
        for i in range(len(m)):
            print i, len(m)
            for j in range(4):

                # Only test 2% of cases:
                if not np.random.rand() < 0.02:
                    continue

                m1 = MorphologyArray.fromSWC(srcSWCFile)
                m1._vertices[i, j] = m1._vertices[i, j] + 0.01
                assert MorphArrayComparison.are_same(m, m1, max_node_distance= 0.02)
                assert not MorphArrayComparison.are_same(m, m1, max_node_distance= 0.005)
Пример #10
0
    def testComparisonFailureAddingEpsilon1(self):
        """Load simple .swc snippets, and change each [x, y, z, r] value in the vertices matrix
        individually, to check that it is not the same. """

        m = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))

        for i in range(len(m)):
            for j in range(4):

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))
                m1._vertices[i, j] = m1._vertices[i, j] + 0.01
                assert MorphArrayComparison.are_same(m,
                                                     m1,
                                                     max_node_distance=0.02)
                assert not MorphArrayComparison.are_same(
                    m, m1, max_node_distance=0.005)

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Ci']))
                m1._vertices[i, j] = m1._vertices[i, j] - 0.001
                assert MorphArrayComparison.are_same(m,
                                                     m1,
                                                     max_node_distance=0.002)
                assert not MorphArrayComparison.are_same(
                    m, m1, max_node_distance=0.0005)

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Cii']))
                m1._vertices[i, j] = m1._vertices[i, j] + 0.01
                assert MorphArrayComparison.are_same(m,
                                                     m1,
                                                     max_node_distance=0.02)
                assert not MorphArrayComparison.are_same(
                    m, m1, max_node_distance=0.005)

                m1 = MorphologyArray.fromSWC(StringIO(swc_srcs['Cii']))
                m1._vertices[i, j] = m1._vertices[i, j] - 0.001
                assert MorphArrayComparison.are_same(m,
                                                     m1,
                                                     max_node_distance=0.002)
                assert not MorphArrayComparison.are_same(
                    m, m1, max_node_distance=0.0005)
Пример #11
0

m = MorphologyImporter.fromSWCFile(filename="/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc", astype=MorphologyTree)


MorphologyExporter.toSWCFile(morphology = m, filename="/home/michael/Desktop/test1.swc")

m2 = MorphologyImporter.fromSWCFile(filename="/home/michael/Desktop/test1.swc", astype=MorphologyTree)



#m2 = MorphologyLoader.fromSWC(src=open("/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc"))







are_same =  MorphArrayComparison.are_same(m, m2)
print are_same

#m = MorphologyLoader2.loadSWCFile(filename="/home/michael/workspace/morphforge/src/test_data/swc_srcs/05b_pyramidal9aACC.CNG_short.swc", astype=MorphologyTree)

#MayaViRenderer(morph=m).showSimpleCylinders().show()
#MorphologyLoader2.loadSWCFile(astype=MorphologyArray)
MatPlotLibViewer(m)

import pylab
pylab.show()
Пример #12
0
from morphforge.morphology.importer.morphologyimporter import MorphologyImporter
from morphforge.morphology.exporter.morphologyexporter import MorphologyExporter
from morphforge.morphology.comparison.comparearrays import MorphArrayComparison
from morphforge.morphology.builders.morphologyloader import MorphologyLoader

m = MorphologyImporter.fromSWCFile(
    filename=
    "/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc",
    astype=MorphologyTree)

MorphologyExporter.toSWCFile(morphology=m,
                             filename="/home/michael/Desktop/test1.swc")

m2 = MorphologyImporter.fromSWCFile(filename="/home/michael/Desktop/test1.swc",
                                    astype=MorphologyTree)

#m2 = MorphologyLoader.fromSWC(src=open("/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc"))

are_same = MorphArrayComparison.are_same(m, m2)
print are_same

#m = MorphologyLoader2.loadSWCFile(filename="/home/michael/workspace/morphforge/src/test_data/swc_srcs/05b_pyramidal9aACC.CNG_short.swc", astype=MorphologyTree)

#MayaViRenderer(morph=m).showSimpleCylinders().show()
#MorphologyLoader2.loadSWCFile(astype=MorphologyArray)
MatPlotLibViewer(m)

import pylab

pylab.show()