Пример #1
0
 def _store_float_array(array_data, subject_name, operation_id):
     """Create Float Array and DB persist it"""
     datatype_inst = MappedArray(user_tag_1=subject_name)
     datatype_inst.set_operation_id(operation_id)
     datatype_inst.array_data = array_data
     datatype_inst.type = "MappedArray"
     datatype_inst.module = "tvb.datatypes.arrays"
     datatype_inst.subject = subject_name
     datatype_inst.state = "RAW"
     dao.store_entity(datatype_inst)
 def _store_float_array(array_data, subject_name, operation_id):
     """Create Float Array and DB persist it"""
     datatype_inst = MappedArray(user_tag_1=subject_name)
     datatype_inst.set_operation_id(operation_id)
     datatype_inst.array_data = array_data
     datatype_inst.type = "MappedArray"
     datatype_inst.module = "tvb.datatypes.arrays"
     datatype_inst.subject = subject_name
     datatype_inst.state = "RAW"
     dao.store_entity(datatype_inst)
 def launch(self, input_data=None):
     """
     Saves in the db the following array.
     """
     self.launch_param = input_data
     array_inst = MappedArray()
     array_inst.storage_path = self.storage_path
     array_inst.array_data = numpy.array(range(1, 46)).reshape((5, 3, 3))
     array_inst.type = "MappedArray"
     array_inst.module = "tvb.datatypes.arrays"
     array_inst.subject = "John Doe"
     array_inst.state = "RAW"
     return array_inst
Пример #4
0
 def launch(self, input_data=None):
     """
     Saves in the db the following array.
     """
     self.launch_param = input_data
     array_inst = MappedArray()
     array_inst.storage_path = self.storage_path
     array_inst.array_data = numpy.array(range(1, 46)).reshape((5, 3, 3))
     array_inst.type = "MappedArray"
     array_inst.module = "tvb.datatypes.arrays"
     array_inst.subject = "John Doe"
     array_inst.state = "RAW"
     return array_inst
Пример #5
0
    def test_read_write_arrays(self):
        """
        Test the filter function when retrieving dataTypes with a filter
        after a column from a class specific table (e.g. DATA_arraywrapper).
        """
        test_array = numpy.array(range(16))
        shapes = [test_array.shape, (2, 8), (2, 2, 4), (2, 2, 2, 2)]
        storage_path = self.flow_service.file_helper.get_project_folder(
            self.operation.project, str(self.operation.id))
        for i in range(4):
            datatype_inst = MappedArray(title="dim_" + str(i + 1),
                                        d_type="MappedArray",
                                        storage_path=storage_path,
                                        module="tvb.datatypes.arrays",
                                        subject="John Doe",
                                        state="RAW",
                                        operation_id=self.operation.id)
            datatype_inst.array_data = test_array.reshape(shapes[i])
            result = dao.store_entity(datatype_inst)
            result.array_data = None

        inserted_data = self.flow_service.get_available_datatypes(
            self.test_project.id, "tvb.datatypes.arrays.MappedArray")[0]
        self.assertEqual(len(inserted_data), 4,
                         "Found " + str(len(inserted_data)))

        for i in range(4):
            ## inserted_data will be retrieved in the opposite order than the insert order
            actual_datatype = dao.get_generic_entity(MappedArray,
                                                     inserted_data[3 - i][2],
                                                     'gid')[0]
            self.assertEqual(actual_datatype.length_1d, shapes[i][0])
            if i > 0:
                self.assertEqual(actual_datatype.length_2d, shapes[i][1])
            expected_arr = test_array.reshape(shapes[i])
            self.assertTrue(
                numpy.equal(actual_datatype.array_data, expected_arr).all(),
                str(i + 1) + "D Data not read correctly")
            actual_datatype.array_data = None
            ### Check that meta-data are also written for Array attributes.
            metadata = actual_datatype.get_metadata('array_data')
            self.assertTrue(actual_datatype.METADATA_ARRAY_MAX in metadata)
            self.assertEqual(metadata[actual_datatype.METADATA_ARRAY_MAX], 15)
            self.assertTrue(actual_datatype.METADATA_ARRAY_MIN in metadata)
            self.assertEqual(metadata[actual_datatype.METADATA_ARRAY_MIN], 0)
            self.assertTrue(actual_datatype.METADATA_ARRAY_MEAN in metadata)
            self.assertEqual(metadata[actual_datatype.METADATA_ARRAY_MEAN],
                             7.5)
Пример #6
0
    def test_read_write_arrays(self):
        """
        Test the filter function when retrieving dataTypes with a filter
        after a column from a class specific table (e.g. DATA_arraywrapper).
        """ 
        test_array = numpy.array(range(16))
        shapes = [test_array.shape, (2, 8), (2, 2, 4), (2, 2, 2, 2)]
        storage_path = self.flow_service.file_helper.get_project_folder(self.operation.project, str(self.operation.id))
        for i in range(4):
            datatype_inst = MappedArray(title="dim_" + str(i + 1), d_type="MappedArray",
                                        storage_path=storage_path, module="tvb.datatypes.arrays",
                                        subject="John Doe", state="RAW", operation_id=self.operation.id)
            datatype_inst.array_data = test_array.reshape(shapes[i])
            result = dao.store_entity(datatype_inst)
            result.array_data = None
        
        inserted_data = self.flow_service.get_available_datatypes(self.test_project.id,
                                                                  "tvb.datatypes.arrays.MappedArray")[0]
        self.assertEqual(len(inserted_data), 4, "Found " + str(len(inserted_data)))
 
        for i in range(4):
            ## inserted_data will be retrieved in the opposite order than the insert order
            actual_datatype = dao.get_generic_entity(MappedArray, inserted_data[3 - i][2], 'gid')[0]
            self.assertEqual(actual_datatype.length_1d, shapes[i][0])
            if i > 0:
                self.assertEqual(actual_datatype.length_2d, shapes[i][1])
            expected_arr = test_array.reshape(shapes[i])
            self.assertTrue(numpy.equal(actual_datatype.array_data, expected_arr).all(), 
                            str(i + 1) + "D Data not read correctly")
            actual_datatype.array_data = None
            ### Check that meta-data are also written for Array attributes.
            metadata = actual_datatype.get_metadata('array_data')
            self.assertTrue(actual_datatype.METADATA_ARRAY_MAX in metadata)
            self.assertEqual(metadata[actual_datatype.METADATA_ARRAY_MAX], 15)
            self.assertTrue(actual_datatype.METADATA_ARRAY_MIN in metadata)
            self.assertEqual(metadata[actual_datatype.METADATA_ARRAY_MIN], 0)
            self.assertTrue(actual_datatype.METADATA_ARRAY_MEAN in metadata)
            self.assertEqual(metadata[actual_datatype.METADATA_ARRAY_MEAN], 7.5)