def deserialize_simulator(simulator_gid, storage_path):
        simulator_in_path = h5.path_for(storage_path, SimulatorH5,
                                        simulator_gid)
        simulator_in = SimulatorAdapterModel()

        with SimulatorH5(simulator_in_path) as simulator_in_h5:
            simulator_in_h5.load_into(simulator_in)
            simulator_in.connectivity = simulator_in_h5.connectivity.load()
            simulator_in.stimulus = simulator_in_h5.stimulus.load()
            simulator_in.history_gid = simulator_in_h5.simulation_state.load()

        if isinstance(simulator_in.monitors[0], Projection):
            # TODO: simplify this part
            with SimulatorH5(simulator_in_path) as simulator_in_h5:
                monitor_h5_path = simulator_in_h5.get_reference_path(
                    simulator_in.monitors[0].gid)

            monitor_h5_class = h5_factory.monitor_h5_factory(
                type(simulator_in.monitors[0]))

            with monitor_h5_class(monitor_h5_path) as monitor_h5:
                sensors_gid = monitor_h5.sensors.load()
                region_mapping_gid = monitor_h5.region_mapping.load()

            sensors = ABCAdapter.load_traited_by_gid(sensors_gid)

            if isinstance(simulator_in.monitors[0], EEG):
                sensors = SensorsEEG.build_sensors_subclass(sensors)
            elif isinstance(simulator_in.monitors[0], MEG):
                sensors = SensorsMEG.build_sensors_subclass(sensors)
            elif isinstance(simulator_in.monitors[0], iEEG):
                sensors = SensorsInternal.build_sensors_subclass(sensors)

            simulator_in.monitors[0].sensors = sensors
            region_mapping = ABCAdapter.load_traited_by_gid(region_mapping_gid)
            simulator_in.monitors[0].region_mapping = region_mapping

        if simulator_in.surface:
            cortex_path = h5.path_for(storage_path, CortexH5,
                                      simulator_in.surface.gid)
            with CortexH5(cortex_path) as cortex_h5:
                simulator_in.surface.local_connectivity = cortex_h5.local_connectivity.load(
                )
                simulator_in.surface.region_mapping_data = cortex_h5.region_mapping_data.load(
                )
                rm_index = dao.get_datatype_by_gid(
                    simulator_in.surface.region_mapping_data.hex)
                simulator_in.surface.surface_gid = uuid.UUID(
                    rm_index.surface_gid)

        return simulator_in
Example #2
0
    def transactional_setup_method(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity and a list of BCT adapters;
        imports a CFF data-set
        """
        self.test_user = TestFactory.create_user("BCT_User")
        self.test_project = TestFactory.create_project(self.test_user,
                                                       "BCT-Project")
        # Make sure Connectivity is in DB
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__),
                                'connectivity', 'connectivity_66.zip')
        conn_index = TestFactory.import_zip_connectivity(
            self.test_user, self.test_project, zip_path)
        self.connectivity = ABCAdapter.load_traited_by_gid(conn_index.gid)

        # make weights matrix symmetric, or else some BCT algorithms will run infinitely:
        w = self.connectivity.weights
        self.connectivity.weights = w + w.T - numpy.diag(w.diagonal())

        algorithms = dao.get_generic_entity(Algorithm,
                                            'Brain Connectivity Toolbox',
                                            'group_description')
        assert algorithms is not None
        assert len(algorithms) > 5

        self.bct_adapters = []
        for algo in algorithms:
            self.bct_adapters.append(ABCAdapter.build_adapter(algo))
Example #3
0
    def deserialize_simulator(simulator_gid, storage_path):
        simulator_in_path = h5.path_for(storage_path, SimulatorH5,
                                        simulator_gid)
        simulator_in = SimulatorAdapterModel()

        with SimulatorH5(simulator_in_path) as simulator_in_h5:
            simulator_in_h5.load_into(simulator_in)
            simulator_in.connectivity = simulator_in_h5.connectivity.load()
            simulator_in.stimulus = simulator_in_h5.stimulus.load()
            simulator_in.history_gid = simulator_in_h5.simulation_state.load()

        for monitor in simulator_in.monitors:
            if isinstance(monitor, Projection):
                with SimulatorH5(simulator_in_path) as simulator_in_h5:
                    monitor_h5_path = simulator_in_h5.get_reference_path(
                        monitor.gid)

                monitor_h5_class = h5_factory.monitor_h5_factory(type(monitor))

                with monitor_h5_class(monitor_h5_path) as monitor_h5:
                    sensors_gid = monitor_h5.sensors.load()
                    projection_gid = monitor_h5.projection.load()
                    region_mapping_gid = monitor_h5.region_mapping.load()

                sensors_index = ABCAdapter.load_entity_by_gid(sensors_gid.hex)
                projection_index = ABCAdapter.load_entity_by_gid(
                    projection_gid.hex)

                sensors_class = monitor.projection_class().sensors.field_type
                sensors = h5.load_from_index(sensors_index,
                                             dt_class=sensors_class)

                projection_class = monitor.projection_class()
                projection = h5.load_from_index(projection_index,
                                                dt_class=projection_class)

                region_mapping = ABCAdapter.load_traited_by_gid(
                    region_mapping_gid)

                monitor.sensors = sensors
                monitor.projection = projection
                monitor.region_mapping = region_mapping

        if simulator_in.surface:
            cortex_path = h5.path_for(storage_path, CortexH5,
                                      simulator_in.surface.gid)
            with CortexH5(cortex_path) as cortex_h5:
                simulator_in.surface.local_connectivity = cortex_h5.local_connectivity.load(
                )
                simulator_in.surface.region_mapping_data = cortex_h5.region_mapping_data.load(
                )
                rm_index = dao.get_datatype_by_gid(
                    simulator_in.surface.region_mapping_data.hex)
                simulator_in.surface.surface_gid = uuid.UUID(
                    rm_index.fk_surface_gid)

        return simulator_in