diff --git a/ADwinProII/ADwin_utils.py b/ADwinProII/ADwin_utils.py index 6825e3e86d97113da220af235a725056ce0a2582..fa1d2f41eaf3f9d62313bb05577763dec6f206d9 100644 --- a/ADwinProII/ADwin_utils.py +++ b/ADwinProII/ADwin_utils.py @@ -103,7 +103,7 @@ def get_channel_from_BLACS_name(BLACS_name): return int(channel) -def get_ain_traces(h5file, raw_data_name="ADwinAnalogIn_DATA", convert_data=True, device_name="ADwin"): +def get_ain_traces(h5file, raw_data_name="ADwinAnalogIn_DATA", convert_data=True, device_name="ADwin", write_hdf5 = True): """ Split raw (sorted!) data from ADwin analog inputs into aquisitions of channels and store the traces for each channel in the h5 file. @@ -118,8 +118,11 @@ def get_ain_traces(h5file, raw_data_name="ADwinAnalogIn_DATA", convert_data=True Set is the input voltage is stored as row value, or converted to volts. device_name : str, optional Name of the ADwin device. + write_hdf5 : bool, optional + Decides if the single traces are written to the hdf5 file or returned. """ - with h5py.File(h5file, 'r+') as f: + return_dict = {} + with h5py.File(h5file, 'r'+write_hdf5*'+') as f: # open with(out) write permission depending on argument group = f["data/traces"] if raw_data_name not in group: print(f"No raw acquisition data with name '{raw_data_name}' found!") @@ -154,8 +157,13 @@ def get_ain_traces(h5file, raw_data_name="ADwinAnalogIn_DATA", convert_data=True else: times = np.arange(acquisition_times["start_time"][i],acquisition_times["stop_time"][i]) / clock_rate # print(times.size,acquisition.size) - data = np.rec.fromarrays([times, acquisition], dtype=dtype) - group.create_dataset(label, compression = config.compression, data = data) + if write_hdf5: + data = np.rec.fromarrays([times, acquisition], dtype=dtype) + group.create_dataset(label, compression = config.compression, data = data) + else: + return_dict[label] = times, acquisition + if not write_hdf5: + return return_dict