Example #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)
Example #2
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)
Example #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)
Example #4
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)
Example #5
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)
Example #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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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)
Example #11
0
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------
"""Load  SWC data from a string directly into a MorphologyArray.
We can load .swc from any file-like object, so we can use StringIO to load directly from strings.
"""

from morphforge.morphology.core import MorphologyArray
from StringIO import StringIO

swcSrc = """
1 0 1.0 2.0 3.0 4.0 -1
2 0 5.0 6.0 7.0 8.0 1
"""

m = MorphologyArray.fromSWC(StringIO(swcSrc))

print 'Morphology Vertices:'
print m._vertices

print 'Morphology Connectivity:'
print m._connectivity
Example #12
0








from morphforge.morphology.core import MorphologyArray
from StringIO import StringIO

swcSrc = """
1 0 1.0 2.0 3.0 4.0 -1
2 0 5.0 6.0 7.0 8.0 1
"""

m = MorphologyArray.fromSWC(StringIO(swcSrc))

print 'Morphology Vertices:'
print m._vertices

print 'Morphology Connectivity:'
print m._connectivity