def test_writing_and_reading_dicts_to_hdf5_int_keys(self): test_dict = { 0: { "name": "I", "theta": 0, "phi": 0, "type": "ge" }, 1: { "name": "rX180", "theta": 180, "phi": 0, "type": "ge" } } data_object = h5d.Data(name='test_object', datadir=self.datadir) h5d.write_dict_to_hdf5(test_dict, data_object) data_object.close() filepath = data_object.filepath new_dict = {} opened_hdf5_file = h5py.File(filepath, 'r') h5d.read_dict_from_hdf5(new_dict, opened_hdf5_file) self.assertEqual(test_dict.keys(), new_dict.keys()) self.assertEqual(test_dict[0], new_dict[0])
def test_storing_and_loading_station_snapshot(self): """ Stores and writes a station (instrument) snapshot. """ self.mock_parabola_2.x(1) self.mock_parabola_2.y(2.245) self.mock_parabola_2.array_like(np.linspace(0, 11, 23)) snap = self.station.snapshot(update=True) data_object = h5d.Data(name='test_object_snap', datadir=self.datadir) h5d.write_dict_to_hdf5(snap, data_object) data_object.close() filepath = data_object.filepath new_dict = {} opened_hdf5_file = h5py.File(filepath, 'r') h5d.read_dict_from_hdf5(new_dict, opened_hdf5_file) self.assertEqual(snap.keys(), new_dict.keys()) self.assertEqual(snap['instruments'].keys(), new_dict['instruments'].keys()) mock_parab_pars = snap['instruments']['mock_parabola_2']['parameters'] self.assertEqual(mock_parab_pars['x']['value'], 1) self.assertEqual(mock_parab_pars['y']['value'], 2.245) np.testing.assert_array_equal(mock_parab_pars['array_like']['value'], np.linspace(0, 11, 23))
def T1_CBox(n_waves=70, time_step=2000, amp180=4000): #input("stop AWG and hit enter....") CBox = qt.instruments['CBox'] AWG = qt.instruments['AWG'] CBox.set_acquisition_mode(0) # sets the codeword to False CBox.set_AWG_triggermode(0, 'False') No_points = 70 NoAvg = 6 #14 # This is a lot and should not be hardcoded # Generates wavetables Wave_I, Wave_Q = mod_gauss(amp180, 25, -0.02) CBox.set_awg_lookuptable(0, 0, 1, np.round(Wave_I)) CBox.set_awg_lookuptable(0, 0, 0, np.round(Wave_Q)) CBox.set_averaging_parameters(No_points, NoAvg) CBox.set_acquisition_mode(4) # This trigger starts the measurement AWG.start() [InputAvgRes0, InputAvgRes1] = CBox.get_integrated_avg_results(timeout=360) # Creates the corresponding sweeppoints time_samples = np.linspace(0, (n_waves - 1) * time_step, n_waves) # Below is data saving AWG.stop() filename = hdf5_data.Data(name="T1") if "Experimental Data" in filename: grp = filename["Experimental Data"] else: grp = filename.create_group('Experimental Data') dataset_samples = grp.create_dataset('time', time_samples.shape, dtype=np.float) dataset_InputAvgRes0 = grp.create_dataset('I_raw', InputAvgRes0.shape, dtype=np.float) dataset_InputAvgRes1 = grp.create_dataset('Q_raw', InputAvgRes1.shape, dtype=np.float) dataset_samples = time_samples dataset_InputAvgRes0[:] = InputAvgRes0[:] dataset_InputAvgRes1[:] = InputAvgRes1[:] filename.close() # fig, ax = plt.subplots(figsize=(10,10)) # ax.set_xlabel('time (us)', fontsize=14) # ax.set_ylabel('output amplitude (Integrated ADC value)', fontsize=14) # ax.plot(time_samples,InputAvgRes0, label = 'I') # ax.plot(time_samples,InputAvgRes1, label = 'Q') # ax.set_title('T1 with CBox generating pulses and acquiring data') # plt.show() return InputAvgRes0, InputAvgRes1
def test_wr_rd_hdf5_array(): datadir = os.path.join(pq.__path__[0], 'tests', 'test_data') test_dict = { 'x': np.linspace(0, 1, 14), 'y': np.cos(np.linspace(0, 2*np.pi, 11))} data_object = h5d.Data(name='test_object', datadir=datadir) h5d.write_dict_to_hdf5(test_dict, data_object) data_object.close() filepath = data_object.filepath new_dict = {} opened_hdf5_file = h5py.File(filepath, 'r') h5d.read_dict_from_hdf5(new_dict, opened_hdf5_file) assert test_dict.keys() == new_dict.keys() np.testing.assert_allclose(test_dict['x'], new_dict['x']) np.testing.assert_allclose(test_dict['y'], new_dict['y'])
def test_writing_and_reading_dicts_to_hdf5(self): """ Tests dumping some random dictionary to hdf5 and reading back the stored values. The input dictionary contains: - list of ints - list of floats - nested dict - 1D array - 2D array """ test_dict = { 'list_of_ints': list(np.arange(5)), 'list_of_floats': list(np.arange(5.1)), 'some_bool': True, 'weird_dict': {'a': 5}, 'dataset1': np.linspace(0, 20, 31), 'dataset2': np.array([[2, 3, 4, 5], [2, 3, 1, 2]]), 'list_of_mixed_type': ['hello', 4, 4.2, {'a': 5}, [4, 3]], 'tuple_of_mixed_type': tuple(['hello', 4, 4.2, {'a': 5}, [4, 3]]), 'a list of strings': ['my ', 'name ', 'is ', 'earl.'], 'some_np_bool': np.bool(True), 'list_of_dicts': [{'a': 5}, {'b': 3}], 'some_int': 3, 'some_float': 3.5, 'some_np_int': np.int(3), 'some_np_float': np.float(3.5) } data_object = h5d.Data(name='test_object', datadir=self.datadir) h5d.write_dict_to_hdf5(test_dict, data_object) data_object.close() filepath = data_object.filepath new_dict = {} opened_hdf5_file = h5py.File(filepath, 'r') try: h5d.read_dict_from_hdf5(new_dict, opened_hdf5_file) # objects are not identical but the string representation should be self.assertEqual(test_dict.keys(), new_dict.keys()) self.assertEqual(test_dict['list_of_ints'], new_dict['list_of_ints']) self.assertEqual(test_dict['list_of_floats'], new_dict['list_of_floats']) self.assertEqual(test_dict['weird_dict'], new_dict['weird_dict']) self.assertEqual(test_dict['some_bool'], new_dict['some_bool']) self.assertEqual(test_dict['list_of_dicts'], new_dict['list_of_dicts']) self.assertEqual(test_dict['list_of_mixed_type'], new_dict['list_of_mixed_type']) self.assertEqual(test_dict['list_of_mixed_type'][0], new_dict['list_of_mixed_type'][0]) self.assertEqual(test_dict['list_of_mixed_type'][2], new_dict['list_of_mixed_type'][2]) self.assertEqual(test_dict['tuple_of_mixed_type'], new_dict['tuple_of_mixed_type']) self.assertEqual(type(test_dict['tuple_of_mixed_type']), type(new_dict['tuple_of_mixed_type'])) self.assertEqual(test_dict['tuple_of_mixed_type'][0], new_dict['tuple_of_mixed_type'][0]) self.assertEqual(test_dict['tuple_of_mixed_type'][2], new_dict['tuple_of_mixed_type'][2]) self.assertEqual(test_dict['some_np_bool'], new_dict['some_np_bool']) self.assertEqual(test_dict['some_int'], new_dict['some_int']) self.assertEqual(test_dict['some_np_float'], new_dict['some_np_float']) self.assertEqual(test_dict['a list of strings'], new_dict['a list of strings']) self.assertEqual(test_dict['a list of strings'][0], new_dict['a list of strings'][0]) opened_hdf5_file.close() except Exception as e: opened_hdf5_file.close() raise e