diff --git a/framework_tvb/tvb/interfaces/web/controllers/simulator_controller.py b/framework_tvb/tvb/interfaces/web/controllers/simulator_controller.py index aeee45466e1c1cc6803c5651f6ecf0c15ceb6e85..b0599f2fdfd230f3695bb4060232e9ebce25b103 100644 --- a/framework_tvb/tvb/interfaces/web/controllers/simulator_controller.py +++ b/framework_tvb/tvb/interfaces/web/controllers/simulator_controller.py @@ -717,11 +717,11 @@ class SimulatorController(BurstBaseController): session_stored_simulator.monitors[0].region_mapping = region_mapping # load sensors and projection - sensors_index = ABCAdapter.load_entity_by_gid(data['_sensors']) + sensors_index = ABCAdapter.load_entity_by_gid(data['sensors']) sensors_class = session_stored_simulator.monitors[0].projection_class().sensors.field_type sensors = h5.load_from_index(sensors_index, dt_class=sensors_class) - projection_surface_index = ABCAdapter.load_entity_by_gid(data['_projection']) + projection_surface_index = ABCAdapter.load_entity_by_gid(data['projection']) projection_class = session_stored_simulator.monitors[0].projection_class() projection = h5.load_from_index(projection_surface_index, dt_class=projection_class) diff --git a/framework_tvb/tvb/tests/framework/adapters/uploaders/projection_matrix_importer_test.py b/framework_tvb/tvb/tests/framework/adapters/uploaders/projection_matrix_importer_test.py index a5cd732c8d732b2a2d2b0a12370199d75071a076..67fac054ab61be63b95ab82a7f1886615125df18 100644 --- a/framework_tvb/tvb/tests/framework/adapters/uploaders/projection_matrix_importer_test.py +++ b/framework_tvb/tvb/tests/framework/adapters/uploaders/projection_matrix_importer_test.py @@ -78,9 +78,6 @@ class TestProjectionMatrix(TransactionalTestCase): self.sensors = TestFactory.get_entity(self.test_project, SensorsIndex) assert self.sensors is not None - self.importer = TestFactory.create_adapter('tvb.adapters.uploaders.projection_matrix_importer', - 'ProjectionMatrixSurfaceEEGImporter') - def transactional_teardown_method(self): """ Clean-up tests data @@ -94,20 +91,9 @@ class TestProjectionMatrix(TransactionalTestCase): file_path = os.path.join(os.path.abspath(os.path.dirname(dataset.__file__)), 'projection_eeg_62_surface_16k.mat') - form = ProjectionMatrixImporterForm() - form.fill_from_post({'projection_file': Part(file_path, HeaderMap({}), ''), - 'dataset_name': 'ProjectionMatrix', - 'sensors': self.sensors.gid, - 'surface': self.surface.gid, - 'Data_Subject': 'John Doe' - }) - form.projection_file.data = file_path - view_model = form.get_view_model()() - form.fill_trait(view_model) - self.importer.submit_form(form) - try: - FlowService().fire_operation(self.importer, self.test_user, self.test_project.id, view_model=view_model) + TestFactory.import_projection_matrix(self.test_user, self.test_project, file_path, self.sensors.gid, + self.surface.gid) raise AssertionError("This was expected not to run! 62 rows in proj matrix, but 65 sensors") except OperationException: pass @@ -117,23 +103,12 @@ class TestProjectionMatrix(TransactionalTestCase): Verifies the happy flow for importing a surface. """ dt_count_before = TestFactory.get_entity_count(self.test_project, ProjectionMatrixIndex()) + file_path = os.path.join(os.path.abspath(os.path.dirname(dataset.__file__)), 'projection_eeg_65_surface_16k.npy') - form = ProjectionMatrixImporterForm() - form.fill_from_post({'projection_file': Part(file_path, HeaderMap({}), ''), - 'dataset_name': 'ProjectionMatrix', - 'sensors': self.sensors.gid, - 'surface': self.surface.gid, - 'Data_Subject': 'John Doe' - }) - form.projection_file.data = file_path - view_model = form.get_view_model()() - view_model.subject = 'John Doe' - form.fill_trait(view_model) - self.importer.submit_form(form) - - FlowService().fire_operation(self.importer, self.test_user, self.test_project.id, view_model=view_model) + TestFactory.import_projection_matrix(self.test_user, self.test_project, file_path, self.sensors.gid, self.surface.gid) + dt_count_after = TestFactory.get_entity_count(self.test_project, ProjectionMatrixIndex()) assert dt_count_before + 1 == dt_count_after diff --git a/framework_tvb/tvb/tests/framework/core/factory.py b/framework_tvb/tvb/tests/framework/core/factory.py index dd66142d3705fd1548d77f5922f8d3c14f9c07a4..9c6426b746658a9a62c42bb865465417d496a961 100644 --- a/framework_tvb/tvb/tests/framework/core/factory.py +++ b/framework_tvb/tvb/tests/framework/core/factory.py @@ -43,7 +43,9 @@ import random import tvb_data from cherrypy._cpreqbody import Part from cherrypy.lib.httputil import HeaderMap +from tvb.adapters.datatypes.db.projections import ProjectionMatrixIndex from tvb.adapters.datatypes.db.region_mapping import RegionMappingIndex +from tvb.adapters.uploaders.projection_matrix_importer import ProjectionMatrixImporterForm from tvb.adapters.uploaders.region_mapping_importer import RegionMappingImporterForm from tvb.core.entities.model.model_burst import BurstConfiguration from tvb.core.utils import hash_password @@ -356,6 +358,35 @@ class TestFactory(object): return time_series + @staticmethod + def import_projection_matrix(user, project, file_path, sensors_gid, surface_gid): + importer = TestFactory.create_adapter('tvb.adapters.uploaders.projection_matrix_importer', + 'ProjectionMatrixSurfaceEEGImporter') + + form = ProjectionMatrixImporterForm() + + form.fill_from_post({'projection_file': Part(file_path, HeaderMap({}), ''), + 'dataset_name': 'ProjectionMatrix', + 'sensors': sensors_gid, + 'surface': surface_gid, + 'Data_Subject': 'John Doe' + }) + form.projection_file.data = file_path + view_model = form.get_view_model()() + form.fill_trait(view_model) + importer.submit_form(form) + + FlowService().fire_operation(importer, user, project.id, view_model=view_model) + + data_types = FlowService().get_available_datatypes(project.id, ProjectionMatrixIndex)[0] + assert 1 == len(data_types), "Project should contain only one data type = Projection Matrix." + + projection_matrix = ABCAdapter.load_entity_by_gid(data_types[0][2]) + assert projection_matrix is not None, "Projection Matrix instance should not be none" + + return projection_matrix + + @staticmethod def import_zip_connectivity(user, project, zip_path, subject=DataTypeMetaData.DEFAULT_SUBJECT): diff --git a/framework_tvb/tvb/tests/framework/interfaces/web/controllers/simulator_controller_test.py b/framework_tvb/tvb/tests/framework/interfaces/web/controllers/simulator_controller_test.py index 4e701925ae588f86aab4ca640e905ce3ed1eb509..6f01b58caeac039589c8551ba5ee29ce96e5170b 100644 --- a/framework_tvb/tvb/tests/framework/interfaces/web/controllers/simulator_controller_test.py +++ b/framework_tvb/tvb/tests/framework/interfaces/web/controllers/simulator_controller_test.py @@ -38,10 +38,10 @@ from tvb.adapters.simulator.simulator_adapter import SimulatorAdapterModel, Cort from tvb.adapters.uploaders.sensors_importer import SensorsImporterModel from tvb.basic.profile import TvbProfile import numpy -import tvb_data import tvb_data.surfaceData import tvb_data.regionMapping import tvb_data.sensors +import tvb_data.projectionMatrix from datetime import datetime from cherrypy.lib.sessions import RamSession from cherrypy.test import helper @@ -360,14 +360,20 @@ class TestSimulationController(BaseTransactionalControllerTest, helper.CPWebCase def test_set_eeg_monitor_params(self): region_mapping = self.set_region_mapping() - eeg_file = path.join(path.dirname(tvb_data.sensors.__file__), 'eeg_unitvector_62.txt') - eeg_sensors = TestFactory.import_sensors(self.test_user, self.test_project, eeg_file, + eeg_sensors_file = path.join(path.dirname(tvb_data.sensors.__file__), 'eeg_unitvector_62.txt') + eeg_sensors = TestFactory.import_sensors(self.test_user, self.test_project, eeg_sensors_file, SensorsImporterModel.OPTIONS['EEG Sensors']) + surface_file = path.join(path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip') + surface = TestFactory.import_surface_zip(self.test_user, self.test_project, surface_file, CORTICAL, True) + + eeg_projection_file = path.join(path.dirname(tvb_data.projectionMatrix.__file__), 'projection_eeg_62_surface_16k.mat') + eeg_projections = TestFactory.import_projection_matrix(self.test_user, self.test_project, eeg_projection_file, eeg_sensors.gid, surface.gid) + self.sess_mock['period'] = '0.75' self.sess_mock['variables_of_interest'] = '[0, 1]' self.sess_mock['region_mapping'] = region_mapping.gid - self.sess_mock['projection'] = eeg_sensors.gid + self.sess_mock['projection'] = eeg_projections.gid self.sess_mock['sigma'] = "1.0" self.sess_mock['sensors'] = eeg_sensors.gid @@ -390,14 +396,20 @@ class TestSimulationController(BaseTransactionalControllerTest, helper.CPWebCase def test_set_meg_monitor_params(self): region_mapping = self.set_region_mapping() - meg_file = path.join(path.dirname(tvb_data.sensors.__file__), 'meg_151.txt.bz2') - meg_sensors = TestFactory.import_sensors(self.test_user, self.test_project, meg_file, + meg_sensors_file = path.join(path.dirname(tvb_data.sensors.__file__), 'meg_brainstorm_276.txt') + meg_sensors = TestFactory.import_sensors(self.test_user, self.test_project, meg_sensors_file, SensorsImporterModel.OPTIONS['MEG Sensors']) + surface_file = path.join(path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip') + surface = TestFactory.import_surface_zip(self.test_user, self.test_project, surface_file, CORTICAL, True) + + meg_projection_file = path.join(path.dirname(tvb_data.projectionMatrix.__file__), 'projection_meg_276_surface_16k.npy') + meg_projections = TestFactory.import_projection_matrix(self.test_user, self.test_project, meg_projection_file, meg_sensors.gid, surface.gid) + self.sess_mock['period'] = '0.75' self.sess_mock['variables_of_interest'] = '[0, 1]' self.sess_mock['region_mapping'] = region_mapping.gid - self.sess_mock['projection'] = meg_sensors.gid + self.sess_mock['projection'] = meg_projections.gid self.sess_mock['sigma'] = 1.0 self.sess_mock['sensors'] = meg_sensors.gid @@ -420,14 +432,22 @@ class TestSimulationController(BaseTransactionalControllerTest, helper.CPWebCase def test_set_seeg_monitor_params(self): region_mapping = self.set_region_mapping() - seeg_file = path.join(path.dirname(tvb_data.sensors.__file__), 'seeg_39.txt') - seeg_sensors = TestFactory.import_sensors(self.test_user, self.test_project, seeg_file, + seeg_sensors_file = path.join(path.dirname(tvb_data.sensors.__file__), 'seeg_588.txt') + seeg_sensors = TestFactory.import_sensors(self.test_user, self.test_project, seeg_sensors_file, SensorsImporterModel.OPTIONS['Internal Sensors']) + surface_file = path.join(path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip') + surface = TestFactory.import_surface_zip(self.test_user, self.test_project, surface_file, CORTICAL, True) + + seeg_projection_file = path.join(path.dirname(tvb_data.projectionMatrix.__file__), + 'projection_seeg_588_surface_16k.npy') + seeg_projections = TestFactory.import_projection_matrix(self.test_user, self.test_project, seeg_projection_file, + seeg_sensors.gid, surface.gid) + self.sess_mock['period'] = '0.75' self.sess_mock['variables_of_interest'] = '[0, 1]' self.sess_mock['region_mapping'] = region_mapping.gid - self.sess_mock['projection'] = seeg_sensors.gid + self.sess_mock['projection'] = seeg_projections.gid self.sess_mock['sigma'] = "1.0" self.sess_mock['sensors'] = seeg_sensors.gid