def save(self, save_filename=None): # ************************* # *** Save data to HDF5 *** # ************************* if save_filename is None: script_path = os.path.realpath(__file__) # full path of current script current_dir, script_basename = os.path.split(script_path) script_filename = os.path.splitext(script_basename)[0] # name of current script timestamp = time.strftime("%Y%m%d_%H%M%S", time.localtime()) # current date and time save_basename = f"{script_filename:s}_{timestamp:s}.h5" # name of save file save_path = os.path.join(current_dir, "data", save_basename) # full path of save file else: save_path = os.path.realpath(save_filename) source_code = get_sourcecode(__file__) # save also the sourcecode of the script for future reference with h5py.File(save_path, "w") as h5f: dt = h5py.string_dtype(encoding='utf-8') ds = h5f.create_dataset("source_code", (len(source_code), ), dt) for ii, line in enumerate(source_code): ds[ii] = line for attribute in self.__dict__: print(f"{attribute}: {self.__dict__[attribute]}") if attribute.startswith("_"): # don't save private attributes continue if attribute == "jpa_params": h5f.attrs[attribute] = str(self.__dict__[attribute]) elif np.isscalar(self.__dict__[attribute]): h5f.attrs[attribute] = self.__dict__[attribute] else: h5f.create_dataset(attribute, data=self.__dict__[attribute]) print(f"Data saved to: {save_path}") return save_path
store_arr = data_I + 1j * data_Q # ************************* # *** Save data to HDF5 *** # ************************* script_path = os.path.realpath(__file__) # full path of current script current_dir, script_basename = os.path.split(script_path) script_filename = os.path.splitext(script_basename)[ 0] # name of current script timestamp = time.strftime("%Y%m%d_%H%M%S", time.localtime()) # current date and time save_basename = f"{script_filename:s}_{timestamp:s}.h5" # name of save file save_path = os.path.join(current_dir, "data", save_basename) # full path of save file source_code = get_sourcecode( __file__) # save also the sourcecode of the script for future reference with h5py.File(save_path, "w") as h5f: dt = h5py.string_dtype(encoding='utf-8') ds = h5f.create_dataset("source_code", (len(source_code), ), dt) for ii, line in enumerate(source_code): ds[ii] = line h5f.attrs["num_averages"] = num_averages h5f.attrs["readout_freq"] = readout_freq h5f.attrs["control_freq"] = control_freq h5f.attrs["readout_duration"] = readout_duration h5f.attrs["control_duration"] = control_duration h5f.attrs["readout_amp"] = readout_amp h5f.attrs["control_amp"] = control_amp h5f.attrs["sample_duration"] = sample_duration h5f.attrs["wait_delay"] = wait_delay h5f.attrs["readout_decay"] = readout_decay
store_arr = data_I + 1j * data_Q # ************************* # *** Save data to HDF5 *** # ************************* script_path = os.path.realpath(__file__) # full path of current script current_dir, script_basename = os.path.split(script_path) script_filename = os.path.splitext(script_basename)[ 0] # name of current script timestamp = time.strftime("%Y%m%d_%H%M%S", time.localtime()) # current date and time save_basename = f"{script_filename:s}_{timestamp:s}.h5" # name of save file save_path = os.path.join(current_dir, "data", save_basename) # full path of save file source_code = get_sourcecode( script_path) # save also the sourcecode of the script for future reference with h5py.File(save_path, "w") as h5f: dt = h5py.string_dtype(encoding='utf-8') ds = h5f.create_dataset("source_code", (len(source_code), ), dt) for ii, line in enumerate(source_code): ds[ii] = line h5f.attrs["num_averages"] = num_averages h5f.attrs["control_freq"] = control_freq h5f.attrs["readout_freq"] = readout_freq h5f.attrs["readout_duration"] = readout_duration h5f.attrs["readout_amp"] = readout_amp h5f.attrs["control_amp"] = control_amp h5f.attrs["sample_duration"] = sample_duration h5f.attrs["rabi_n"] = rabi_n h5f.attrs["rabi_dt"] = rabi_dt h5f.attrs["wait_delay"] = wait_delay