Example #1
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 #2
0
    def load_swc_single(cls, src, name=None):

        dtype = {'names':   ('id', 'type', 'x', 'y', 'z', 'r', 'pid'),
                 'formats': ('int32', 'int32', 'f4', 'f4', 'f4', 'f4', 'int32') }

        swc_data_raw = np.loadtxt(src, dtype=dtype)

        if len(np.nonzero(swc_data_raw['pid'] == -1)) != 1:
            assert False, "Unexpected number of id'errstr of -1 in file"

        # We might not nessesarily have continuous indices in the
        # SWC file, so lets convert them:
        index_to_id = swc_data_raw['id']
        id_to_index_dict = dict([(_id, index) for (index, _id) in enumerate(index_to_id)])
        if len(id_to_index_dict) != len(index_to_id):
            errstr =  "Internal Error Loading SWC: Index and ID map are different lengths."
            errstr += " [ID:%swc_data_raw, Index:%swc_data_raw]" % (len(index_to_id), len(id_to_index_dict))
            raise MorphologyImportError(errstr)

        # Vertices are easy:
        vertices = swc_data_raw[['x', 'y', 'z', 'r']]
        vertices = np.vstack([swc_data_raw['x'], swc_data_raw['y'], swc_data_raw['z'], swc_data_raw['r']]).T

        # Connections need to translate id_to_index:
        connection_indices = [(id_to_index_dict[ID], id_to_index_dict[parent_id]) for ID, parent_id in swc_data_raw[['id', 'pid']] if parent_id != -1]

        # Types are specified per connection:
        section_types = [swctype for ID, swctype, parent_id in swc_data_raw[['id', 'type', 'pid']] if parent_id != -1]

        return MorphologyArray(vertices=vertices, connectivity=connection_indices, section_types=section_types, dummy_vertex_index=0, name=name)