Example #1
0
 def __dummy_data_array(set_array: DataArray, scope_data: np.ndarray, channel_index: int = 1, trace_number: int = 1):
     idenifier = 'ScopeTrace_{:03d}'.format(trace_number)
     label = 'Channel_{}'.format(channel_index)
     return DataArray(idenifier, label, preset_data=scope_data, set_arrays=[set_array])
 def test_type_error(self):
     with self.assertRaises(TypeError) as error:
         DataArray('name', 'label')
     self.assertEqual(
         ("Required arguments 'shape' or 'preset_data' not found", ),
         error.exception.args)
Example #3
0
    def test_add_data_unknown_array(self):
        some_array = DataArray('some_array', 'label', shape=(5, 5, 5, 5))
        data_set = DataSet(data_arrays=some_array)

        self.assertRaises(LookupError, data_set.add_data, (3, 3, 3, 3),
                          {'no_such_array': 0.42})
 def test_array_with_float_data(self):
     preset_array = np.array([1., 2.], dtype=np.float32)
     data_array = DataArray('x', 'x', preset_data=preset_array)
     self.assertEqual(data_array._data.dtype, preset_array.dtype)
     self.assertIsInstance(data_array[0], np.float32)
Example #5
0
    def test_sync_from_storage_array(self):
        mock_queue = MagicMock()
        with patch('qilib.data_set.mongo_data_set_io_reader.MongoDataSetIO') as mock_io, patch(
                'qilib.data_set.mongo_data_set_io_reader.Thread') as thread, \
                patch('qilib.data_set.mongo_data_set_io_reader.Queue', return_value=mock_queue):
            mock_io.decode_numpy_array = MongoDataSetIO.decode_numpy_array
            reader = MongoDataSetIOReader(name='test')
            thread.assert_called_once()
            mock_io.assert_called_once_with('test',
                                            None,
                                            create_if_not_found=False,
                                            collection='data_sets',
                                            database='qilib')
            data_set = DataSet(storage_reader=reader)
            set_array = DataArray(name='setter',
                                  label='for_testing',
                                  is_setpoint=True,
                                  preset_data=np.array(range(0, 2)))
            set_array[0] = 42
            set_array[1] = 25
            data_array = DataArray(name='test_array',
                                   label='lab',
                                   unit='V',
                                   is_setpoint=False,
                                   set_arrays=[set_array],
                                   shape=(2, ))

            update_data = {
                "data_arrays": {
                    "setter": {
                        "name":
                        set_array.name,
                        "label":
                        set_array.label,
                        "unit":
                        set_array.unit,
                        "is_setpoint":
                        set_array.is_setpoint,
                        "set_arrays":
                        [array.name for array in set_array.set_arrays],
                        "preset_data":
                        MongoDataSetIO.encode_numpy_array(set_array)
                    }
                }
            }
            mock_queue.get.return_value = {
                'updateDescription': {
                    'updatedFields': update_data
                }
            }
            data_set.sync_from_storage(-1)
            update_data = {
                "data_arrays.test_array": {
                    "name": data_array.name,
                    "label": data_array.label,
                    "unit": data_array.unit,
                    "is_setpoint": data_array.is_setpoint,
                    "set_arrays":
                    [array.name for array in data_array.set_arrays],
                    "preset_data":
                    MongoDataSetIO.encode_numpy_array(data_array)
                }
            }

            mock_queue.get.return_value = {
                'updateDescription': {
                    'updatedFields': update_data
                }
            }
            data_set.sync_from_storage(-1)
            self.assertEqual('test_array', data_set.test_array.name)
            self.assertEqual('lab', data_set.test_array.label)
            self.assertEqual('V', data_set.test_array.unit)
            self.assertFalse(data_set.test_array.is_setpoint)
            self.assertEqual('setter', data_array.set_arrays[0].name)
            self.assertListEqual([42, 25], list(data_array.set_arrays[0]))

            data_array[0] = 255
            update_data["data_arrays.test_array"][
                "preset_data"] = MongoDataSetIO.encode_numpy_array(data_array)
            data_set.sync_from_storage(-1)

            self.assertEqual(255, data_set.test_array[0])