From c8f3daefdc545629d5c9b17b8b178f68314b8247 Mon Sep 17 00:00:00 2001 From: Leolab SDR PC <johannes.schabbauer@tuwien.ac.at> Date: Mon, 9 Sep 2024 18:04:33 +0200 Subject: [PATCH] Adwin Analog inputs: added getting traces without writing to hdf5 file (much faster, esp. if we need them just once for plotting) --- ADwinProII/ADwin_utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ADwinProII/ADwin_utils.py b/ADwinProII/ADwin_utils.py index 6825e3e..fa1d2f4 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 -- GitLab