Exemplo n.º 1
0
    def setUp(self):
        self.datatypeFactory = DatatypesFactory()
        self.test_project = self.datatypeFactory.get_project()
        self.test_user = self.datatypeFactory.get_user()

        TestFactory.import_cff(test_user=self.test_user,
                               test_project=self.test_project)
        zip_path = os.path.join(os.path.dirname(surface_dataset.__file__),
                                'face-surface.zip')
        TestFactory.import_surface_zip(self.test_user, self.test_project,
                                       zip_path, 'Face', 1)
        zip_path = os.path.join(os.path.dirname(surface_dataset.__file__),
                                'eeg_skin_surface.zip')
        TestFactory.import_surface_zip(self.test_user, self.test_project,
                                       zip_path, 'EEG Cap', 1)
        self.connectivity = TestFactory.get_entity(self.test_project,
                                                   Connectivity())
        self.assertTrue(self.connectivity is not None)
        self.surface = TestFactory.get_entity(self.test_project,
                                              CorticalSurface())
        self.assertTrue(self.surface is not None)
        self.face_surface = TestFactory.get_entity(self.test_project,
                                                   FaceSurface())
        self.assertTrue(self.face_surface is not None)
        self.assertTrue(
            TestFactory.get_entity(self.test_project, EEGCap()) is not None)
Exemplo n.º 2
0
    def setUp(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity, a cortical surface and a face surface;
        imports a CFF data-set
        """
        self.datatypeFactory = DatatypesFactory()
        self.test_project = self.datatypeFactory.get_project()
        self.test_user = self.datatypeFactory.get_user()

        TestFactory.import_cff(test_user=self.test_user,
                               test_project=self.test_project)
        zip_path = os.path.join(os.path.dirname(surface_dataset.__file__),
                                'face-surface.zip')
        TestFactory.import_surface_zip(self.test_user, self.test_project,
                                       zip_path, 'Face', 1)
        zip_path = os.path.join(os.path.dirname(surface_dataset.__file__),
                                'eeg_skin_surface.zip')
        TestFactory.import_surface_zip(self.test_user, self.test_project,
                                       zip_path, 'EEG Cap', 1)
        self.connectivity = TestFactory.get_entity(self.test_project,
                                                   Connectivity())
        self.assertTrue(self.connectivity is not None)
        self.surface = TestFactory.get_entity(self.test_project,
                                              CorticalSurface())
        self.assertTrue(self.surface is not None)
        self.face_surface = TestFactory.get_entity(self.test_project,
                                                   FaceSurface())
        self.assertTrue(self.face_surface is not None)
        self.assertTrue(
            TestFactory.get_entity(self.test_project, EEGCap()) is not None)
Exemplo n.º 3
0
    def transactional_setup_method(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity, a cortical surface and a face surface;
        imports a CFF data-set
        """
        self.datatypeFactory = DatatypesFactory()
        self.test_user = self.datatypeFactory.get_user()
        self.test_project = TestFactory.import_default_project(self.test_user)
        self.datatypeFactory.project = self.test_project

        self.connectivity = TestFactory.get_entity(self.test_project,
                                                   Connectivity())
        assert self.connectivity is not None
        self.face_surface = TestFactory.get_entity(self.test_project,
                                                   FaceSurface())
        assert self.face_surface is not None
        assert TestFactory.get_entity(self.test_project, EEGCap()) is not None
    def launch(self, uploaded, surface_type, zero_based_triangles = False):
        """
        Execute import operations: unpack ZIP and build Surface object as result.
        """
        if uploaded is None:
            raise LaunchException ("Please select ZIP file which contains data to import")
  
        self.logger.debug("Start to import surface: '%s' from file: %s"%(surface_type, uploaded))
        try:
            files = FilesHelper().unpack_zip(uploaded, self.storage_path)
        except IOError:
            exception_str = "Did not find the specified ZIP at %s" % uploaded
            raise LaunchException(exception_str)
        
        vertices = []
        normals = []
        triangles = []
        for file_name in files:
            if file_name.lower().find(self.VERTICES_TOKEN) >= 0:
                vertices.append(file_name)            
                continue
            if file_name.lower().find(self.NORMALS_TOKEN) >= 0:
                normals.append(file_name)            
                continue
            if file_name.lower().find(self.TRIANGLES_TOKEN) >= 0:
                triangles.append(file_name)
                
        # Now detect and instantiate correct surface type
        self.logger.debug("Create surface instance")
        if surface_type == CORTICAL:
            surface = CorticalSurface()
        elif surface_type == INNER_SKULL:
            surface = BrainSkull()
        elif surface_type == OUTER_SKULL:
            surface = SkullSkin()
        elif surface_type == OUTER_SKIN:
            surface = SkinAir()
        elif surface_type == EEG_CAP:
            surface = EEGCap()
        elif surface_type == FACE:
            surface = FaceSurface()
        else:
            exception_str = "Could not determine surface type (selected option %s)" % surface_type
            raise LaunchException(exception_str)
            
        surface.storage_path = self.storage_path

        all_vertices, all_normals, all_triangles = self._process_files(vertices, normals, triangles)
        FilesHelper.remove_files(files, True)
        surface.zero_based_triangles = zero_based_triangles
        surface.vertices = all_vertices
        surface.vertex_normals = all_normals
        if zero_based_triangles:
            surface.triangles = all_triangles
        else :
            surface.triangles = all_triangles - 1
        surface.triangle_normals = None

        # Now check if the triangles of the surface are valid   
        triangles_min_vertex = numpy.amin(surface.triangles)
        if triangles_min_vertex < 0:
            if triangles_min_vertex == -1 and not zero_based_triangles:
                raise RuntimeError("Triangles contain a negative vertex index. Maybe you have a ZERO based surface.")
            else:
                raise RuntimeError("Your triangles contain a negative vertex index: %d" %triangles_min_vertex)
        
        no_of_vertices = len(surface.vertices)        
        triangles_max_vertex = numpy.amax(surface.triangles)
        if triangles_max_vertex >= no_of_vertices:
            if triangles_max_vertex == no_of_vertices and zero_based_triangles:
                raise RuntimeError("Your triangles contain an invalid vertex index: %d. \
                Maybe your surface is NOT ZERO Based."%triangles_max_vertex)
            else:
                raise RuntimeError("Your triangles contain an invalid vertex index: %d." %triangles_max_vertex)
            
        self.logger.debug("Surface ready to be stored")
        return surface