def setUp(self): """ Reset the database before each test. """ self.test_user = TestFactory.create_user("UserPM") self.test_project = TestFactory.create_project(self.test_user) zip_path = os.path.join(os.path.dirname(tvb_data.sensors.__file__), 'eeg_brainstorm_65.txt') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.EEG_SENSORS) zip_path = os.path.join(os.path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip') TestFactory.import_surface_zip(self.test_user, self.test_project, zip_path, CORTICAL, True) self.surface = TestFactory.get_entity(self.test_project, CorticalSurface()) self.assertTrue(self.surface is not None) self.sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) self.assertTrue(self.sensors is not None) self.importer = TestFactory.create_adapter( 'tvb.adapters.uploaders.projection_matrix_importer', 'ProjectionMatrixSurfaceEEGImporter')
def test_launch_EEG(self): """ Check that all required keys are present in output from EegSensorViewer launch. """ ## Import Sensors zip_path = os.path.join(os.path.dirname(sensors_dataset.__file__), 'EEG_unit_vectors_BrainProducts_62.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.EEG_SENSORS) sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) ## Import EEGCap zip_path = os.path.join(os.path.dirname(surfaces_dataset.__file__), 'eeg_skin_surface.zip') TestFactory.import_surface_zip(self.test_user, self.test_project, zip_path, EEG_CAP, True) eeg_cap_surface = TestFactory.get_entity(self.test_project, EEGCap()) viewer = EegSensorViewer() viewer.current_project_id = self.test_project.id ## Launch with EEG Cap selected result = viewer.launch(sensors, eeg_cap_surface) self.assert_compliant_dictionary(self.EXPECTED_KEYS_EEG, result) for key in ['urlVertices', 'urlTriangles', 'urlLines', 'urlNormals']: self.assertIsNotNone(result[key], "Value at key %s should not be None" % key) ## Launch without EEG Cap result = viewer.launch(sensors) self.assert_compliant_dictionary(self.EXPECTED_KEYS_EEG, result) for key in ['urlVertices', 'urlTriangles', 'urlLines', 'urlNormals']: self.assertTrue(not result[key] or result[key] == "[]", "Value at key %s should be None or empty, but is %s" % (key, result[key]))
def test_happy_flow_import(self): """ Test that importing a CFF generates at least one DataType in DB. """ ConnectivityZipTest.import_test_connectivity96(self.test_user, self.test_project, subject=TEST_SUBJECT_A) field = FilterChain.datatype + '.subject' filters = FilterChain('', [field], [TEST_SUBJECT_A], ['==']) reference_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters) dt_count_before = TestFactory.get_entity_count(self.test_project, Connectivity()) self._import_csv_test_connectivity(reference_connectivity.gid, TEST_SUBJECT_B) dt_count_after = TestFactory.get_entity_count(self.test_project, Connectivity()) self.assertEqual(dt_count_before + 1, dt_count_after) filters = FilterChain('', [field], [TEST_SUBJECT_B], ['like']) imported_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters) # check relationship between the imported connectivity and the reference self.assertTrue((reference_connectivity.centres == imported_connectivity.centres).all()) self.assertTrue((reference_connectivity.orientations == imported_connectivity.orientations).all()) self.assertEqual(reference_connectivity.number_of_regions, imported_connectivity.number_of_regions) self.assertTrue((reference_connectivity.region_labels == imported_connectivity.region_labels).all()) self.assertFalse((reference_connectivity.weights == imported_connectivity.weights).all()) self.assertFalse((reference_connectivity.tract_lengths == imported_connectivity.tract_lengths).all())
def setUp(self): """ Reset the database before each test. """ self.test_user = TestFactory.create_user("UserPM") self.test_project = TestFactory.import_default_project(self.test_user) self.surface = TestFactory.get_entity(self.test_project, CorticalSurface()) self.assertTrue(self.surface is not None) self.sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) self.assertTrue(self.sensors is not None)
def setUp(self): """ Reset the database before each test. """ self.test_user = TestFactory.create_user("UserPM") self.test_project = TestFactory.import_default_project(self.test_user) 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.sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) self.assertTrue(self.sensors is not None)
def setUp(self): """ Sets up the environment for running the tests; creates a test user, a test project, a connectivity and a surface; imports a CFF data-set """ self.test_user = TestFactory.create_user() self.test_project = TestFactory.import_default_project(self.test_user) self.surface = TestFactory.get_entity(self.test_project, CorticalSurface()) self.assertTrue(self.surface is not None) self.region_mapping = TestFactory.get_entity(self.test_project, RegionMapping()) self.assertTrue(self.region_mapping is not None)
def test_import_bold(self): ### Retrieve Adapter instance importer = TestFactory.create_adapter( 'tvb.adapters.uploaders.mat_timeseries_importer', 'MatTimeSeriesImporter') args = dict( data_file=self.bold_path, dataset_name='QL_20120824_DK_BOLD_timecourse', structure_path='', transpose=False, slice=None, sampling_rate=1000, start_time=0, tstype='region', tstype_parameters_option_region_connectivity=self.connectivity.gid, Data_Subject="QL") ### Launch import Operation FlowService().fire_operation(importer, self.test_user, self.test_project.id, **args) tsr = TestFactory.get_entity(self.test_project, TimeSeriesRegion()) self.assertEqual((661, 1, 68, 1), tsr.read_data_shape())
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_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()) self.assertTrue(self.connectivity 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)
def test_launch(self): """ Check that all required keys are present in output from BrainViewer launch. """ zip_path = os.path.join(os.path.dirname(sensors_dataset.__file__), 'eeg_unitvector_62.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, 'EEG Sensors') sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) time_series = self.datatypeFactory.create_timeseries(self.connectivity, 'EEG', sensors) viewer = EegMonitor() result = viewer.launch(time_series) expected_keys = ['tsNames', 'groupedLabels', 'tsModes', 'tsStateVars', 'longestChannelLength', 'label_x', 'entities', 'page_size', 'number_of_visible_points', 'extended_view', 'initialSelection', 'ag_settings', 'ag_settings'] for key in expected_keys: self.assertTrue(key in result, "key not found %s" % key) expected_ag_settings = ['channelsPerSet', 'channelLabels', 'noOfChannels', 'translationStep', 'normalizedSteps', 'nan_value_found', 'baseURLS', 'pageSize', 'nrOfPages', 'timeSetPaths', 'totalLength', 'number_of_visible_points', 'extended_view', 'measurePointsSelectionGIDs'] ag_settings = json.loads(result['ag_settings']) for key in expected_ag_settings: self.assertTrue(key in ag_settings, "ag_settings should have the key %s" % key)
def test_bad_reference(self): TestFactory.import_cff(test_user=self.test_user, test_project=self.test_project) field = FilterChain.datatype + '.subject' filters = FilterChain('', [field], [TEST_SUBJECT_A], ['!=']) bad_reference_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters) self.assertRaises(OperationException, self._import_csv_test_connectivity, bad_reference_connectivity.gid, TEST_SUBJECT_A)
def setUp(self): """ Reset the database before each test. """ self.test_user = TestFactory.create_user("UserPM") self.test_project = TestFactory.create_project(self.test_user) zip_path = os.path.join(os.path.dirname(tvb_data.sensors.__file__), "eeg_brainstorm_65.txt") TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.EEG_SENSORS) zip_path = os.path.join(os.path.dirname(tvb_data.surfaceData.__file__), "cortex_16384.zip") TestFactory.import_surface_zip(self.test_user, self.test_project, zip_path, CORTICAL, True) self.surface = TestFactory.get_entity(self.test_project, CorticalSurface()) self.assertTrue(self.surface is not None) self.sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) self.assertTrue(self.sensors is not None)
def _import_connectivity(self): importer = TestFactory.create_adapter('tvb.adapters.uploaders.zip_connectivity_importer', 'ZIPConnectivityImporter') ### Launch Operation FlowService().fire_operation(importer, self.test_user, self.test_project.id, uploaded=self.connectivity_path, Data_Subject='QL') self.connectivity = TestFactory.get_entity(self.test_project, Connectivity())
def _import_connectivity(self): group = dao.find_group('tvb.adapters.uploaders.zip_connectivity_importer', 'ZIPConnectivityImporter') importer = ABCAdapter.build_adapter(group) ### Launch Operation FlowService().fire_operation(importer, self.test_user, self.test_project.id, uploaded=self.connectivity_path, Data_Subject='QL') self.connectivity = TestFactory.get_entity(self.test_project, Connectivity())
def test_happy_flow_import(self): """ Test that importing a CFF generates at least one DataType in DB. """ ConnectivityZipTest.import_test_connectivity96(self.test_user, self.test_project, subject=TEST_SUBJECT_A) field = FilterChain.datatype + '.subject' filters = FilterChain('', [field], [TEST_SUBJECT_A], ['==']) reference_connectivity = TestFactory.get_entity( self.test_project, Connectivity(), filters) dt_count_before = TestFactory.get_entity_count(self.test_project, Connectivity()) self._import_csv_test_connectivity(reference_connectivity.gid, TEST_SUBJECT_B) dt_count_after = TestFactory.get_entity_count(self.test_project, Connectivity()) self.assertEqual(dt_count_before + 1, dt_count_after) filters = FilterChain('', [field], [TEST_SUBJECT_B], ['like']) imported_connectivity = TestFactory.get_entity(self.test_project, Connectivity(), filters) # check relationship between the imported connectivity and the reference self.assertTrue( (reference_connectivity.centres == imported_connectivity.centres ).all()) self.assertTrue((reference_connectivity.orientations == imported_connectivity.orientations).all()) self.assertEqual(reference_connectivity.number_of_regions, imported_connectivity.number_of_regions) self.assertTrue((reference_connectivity.region_labels == imported_connectivity.region_labels).all()) self.assertFalse( (reference_connectivity.weights == imported_connectivity.weights ).all()) self.assertFalse((reference_connectivity.tract_lengths == imported_connectivity.tract_lengths).all())
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_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()) self.assertTrue(self.connectivity 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)
def setUp(self): zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip') self.test_user = TestFactory.create_user('Test_User') self.test_project = TestFactory.create_project(self.test_user, "Test_Project") TestFactory.import_zip_connectivity(self.test_user, self.test_project, "John", zip_path) self.connectivity = TestFactory.get_entity(self.test_project, Connectivity())
def test_bad_reference(self): TestFactory.import_cff(test_user=self.test_user, test_project=self.test_project) field = FilterChain.datatype + '.subject' filters = FilterChain('', [field], [TEST_SUBJECT_A], ['!=']) bad_reference_connectivity = TestFactory.get_entity( self.test_project, Connectivity(), filters) self.assertRaises(OperationException, self._import_csv_test_connectivity, bad_reference_connectivity.gid, TEST_SUBJECT_A)
def setUp(self): """ Sets up the environment for running the tests; creates a test user, a test project, a connectivity and a 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) self.connectivity = TestFactory.get_entity(self.test_project, Connectivity()) self.assertTrue(self.connectivity is not None)
def test_launch_eeg(self): """ Tests successful launch of a BrainEEG and that all required keys are present in returned template dictionary """ sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) time_series = self.datatypeFactory.create_timeseries(self.connectivity, 'EEG', sensors) time_series.configure() viewer = DualBrainViewer() viewer.current_project_id = self.test_project.id result = viewer.launch(time_series) for key in BrainViewerTest.EXPECTED_KEYS + BrainViewerTest.EXPECTED_EXTRA_KEYS: self.assertTrue(key in result and result[key] is not None) self.assertTrue(result['extended_view'])
def test_launch_internal(self): """ Check that all required keys are present in output from InternalSensorViewer launch. """ zip_path = os.path.join(os.path.dirname(sensors_dataset.__file__), 'internal_39.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.INTERNAL_SENSORS) sensors = TestFactory.get_entity(self.test_project, SensorsInternal()) viewer = InternalSensorViewer() viewer.current_project_id = self.test_project.id result = viewer.launch(sensors) self.assert_compliant_dictionary(self.EXPECTED_KEYS_INTERNAL, result)
def test_launch_MEG(self): """ Check that all required keys are present in output from MEGSensorViewer launch. """ zip_path = os.path.join(os.path.dirname(sensors_dataset.__file__), 'meg_channels_reg13.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.MEG_SENSORS) sensors = TestFactory.get_entity(self.test_project, SensorsMEG()) viewer = MEGSensorViewer() viewer.current_project_id = self.test_project.id result = viewer.launch(sensors) self.assert_compliant_dictionary(self.EXPECTED_KEYS_MEG, result)
def test_launch_eeg(self): """ Tests successful launch of a BrainEEG and that all required keys are present in returned template dictionary """ sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) time_series = self.datatypeFactory.create_timeseries( self.connectivity, 'EEG', sensors) time_series.configure() viewer = DualBrainViewer() viewer.current_project_id = self.test_project.id result = viewer.launch(time_series) for key in BrainViewerTest.EXPECTED_KEYS + BrainViewerTest.EXPECTED_EXTRA_KEYS: self.assertTrue(key in result and result[key] is not None) self.assertTrue(result['extended_view'])
def test_launch_EEG(self): """ Check that all required keys are present in output from EegSensorViewer launch. """ ## Import Sensors zip_path = os.path.join(os.path.dirname(tvb_data.sensors.__file__), 'EEG_unit_vectors_BrainProducts_62.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.EEG_SENSORS) sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) ## Import EEGCap cap_path = os.path.join(os.path.dirname(tvb_data.obj.__file__), 'eeg_cap.obj') TestFactory.import_surface_obj(self.test_user, self.test_project, cap_path, EEG_CAP) eeg_cap_surface = TestFactory.get_entity(self.test_project, EEGCap()) viewer = SensorsViewer() viewer.current_project_id = self.test_project.id ## Launch with EEG Cap selected result = viewer.launch(sensors, eeg_cap_surface) self.assert_compliant_dictionary(self.EXPECTED_KEYS_EEG, result) for key in ['urlVertices', 'urlTriangles', 'urlLines', 'urlNormals']: self.assertIsNotNone(result[key], "Value at key %s should not be None" % key) ## Launch without EEG Cap result = viewer.launch(sensors) self.assert_compliant_dictionary(self.EXPECTED_KEYS_EEG, result) for key in ['urlVertices', 'urlTriangles', 'urlLines', 'urlNormals']: self.assertTrue( not result[key] or result[key] == "[]", "Value at key %s should be None or empty, but is %s" % (key, result[key]))
def test_launch_internal(self): """ Check that all required keys are present in output from InternalSensorViewer launch. """ zip_path = os.path.join(os.path.dirname(tvb_data.sensors.__file__), 'internal_39.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.INTERNAL_SENSORS) sensors = TestFactory.get_entity(self.test_project, SensorsInternal()) viewer = SensorsViewer() viewer.current_project_id = self.test_project.id result = viewer.launch(sensors) self.assert_compliant_dictionary(self.EXPECTED_KEYS_INTERNAL, result)
def test_import_bold(self): ### Retrieve Adapter instance importer = TestFactory.create_adapter('tvb.adapters.uploaders.mat_timeseries_importer', 'MatTimeSeriesImporter') args = dict(data_file=self.bold_path, dataset_name='QL_20120824_DK_BOLD_timecourse', structure_path='', transpose=False, slice=None, sampling_rate=1000, start_time=0, tstype='region', tstype_parameters_option_region_connectivity=self.connectivity.gid, Data_Subject="QL") ### Launch import Operation FlowService().fire_operation(importer, self.test_user, self.test_project.id, **args) tsr = TestFactory.get_entity(self.test_project, TimeSeriesRegion()) self.assertEqual((661, 1, 68, 1), tsr.read_data_shape())
def test_launch_MEG(self): """ Check that all required keys are present in output from MEGSensorViewer launch. """ zip_path = os.path.join(os.path.dirname(tvb_data.sensors.__file__), 'meg_channels_reg13.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, Sensors_Importer.MEG_SENSORS) sensors = TestFactory.get_entity(self.test_project, SensorsMEG()) viewer = SensorsViewer() viewer.current_project_id = self.test_project.id result = viewer.launch(sensors) self.assert_compliant_dictionary(self.EXPECTED_KEYS_MEG, result)
def test_launch_eeg(self): """ Tests successful launch of a BrainEEG and that all required keys are present in returned template dictionary """ sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) time_series = self.datatypeFactory.create_timeseries(self.connectivity, 'EEG', sensors) time_series.configure() viewer = BrainEEG() viewer.current_project_id = self.test_project.id result = viewer.launch(time_series) expected_keys = ['urlVertices', 'urlNormals', 'urlTriangles', 'urlMeasurePointsLabels', 'title', 'time_series', 'shelfObject', 'pageSize', 'labelsStateVar', 'labelsModes', 'minActivityLabels', 'minActivity', 'measure_points', 'maxActivity', 'isOneToOneMapping', 'isAdapter', 'extended_view', 'base_activity_url', 'alphas_indices'] for key in expected_keys: self.assertTrue(key in result and result[key] is not None) self.assertTrue(result['extended_view'])
def test_launch(self): """ Check that all required keys are present in output from BrainViewer launch. """ zip_path = os.path.join(os.path.dirname(sensors_dataset.__file__), 'EEG_unit_vectors_BrainProducts_62.txt.bz2') TestFactory.import_sensors(self.test_user, self.test_project, zip_path, 'EEG Sensors') sensors = TestFactory.get_entity(self.test_project, SensorsEEG()) time_series = self.datatypeFactory.create_timeseries( self.connectivity, 'EEG', sensors) viewer = EegMonitor() result = viewer.launch(time_series) expected_keys = [ 'tsNames', 'groupedLabels', 'tsModes', 'tsStateVars', 'longestChannelLength', 'label_x', 'entities', 'page_size', 'number_of_visible_points', 'extended_view', 'initialSelection', 'ag_settings', 'ag_settings' ] for key in expected_keys: self.assertTrue(key in result, "key not found %s" % key) expected_ag_settings = [ 'channelsPerSet', 'channelLabels', 'noOfChannels', 'translationStep', 'normalizedSteps', 'nan_value_found', 'baseURLS', 'pageSize', 'nrOfPages', 'timeSetPaths', 'totalLength', 'number_of_visible_points', 'extended_view', 'measurePointsSelectionGIDs' ] ag_settings = json.loads(result['ag_settings']) for key in expected_ag_settings: self.assertTrue(key in ag_settings, "ag_settings should have the key %s" % key)
def setUp(self): zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip') self.test_user = TestFactory.create_user('Test_User') self.test_project = TestFactory.create_project(self.test_user, "Test_Project") TestFactory.import_zip_connectivity(self.test_user,self.test_project, "John", zip_path) self.connectivity = TestFactory.get_entity(self.test_project, Connectivity())