From 1f913be1830be2347c7f30aedb44df6b11dd25da Mon Sep 17 00:00:00 2001 From: CPD Date: Mon, 10 Mar 2025 11:07:20 +0100 Subject: [PATCH] Capture more metadata --- cpdctrl/measurement.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/cpdctrl/measurement.py b/cpdctrl/measurement.py index 416ef64..2d3da9d 100644 --- a/cpdctrl/measurement.py +++ b/cpdctrl/measurement.py @@ -25,7 +25,8 @@ def measure( stop_on_script_end: bool=False, verbose: bool=False, command_queue: None|Queue=None, - data_queue: None|Queue=None + data_queue: None|Queue=None, + add_measurement_info_to_metadata=True ): """ Perform a measurement @@ -62,22 +63,24 @@ def measure( The default is None. data_queue : None|Queue, optional A queue to put data in. The default is None. - + add_measurement_info_to_metadata : bool, optional + If True, add measurement info to the metadata: + time, measurement_interval, measurement_use_buffer, measurement_voltage_device, measurement_led_device + The default is True. Returns ------- None. """ - # old hack when using multiprocessing instead of mulithreading: - # devices are not pickleable and thus cant be moved to / shared with the measurement process - # if led_dev is None: - # led_dev = LEDD1B() - # if vm_dev is None: - # vm_dev = init("GPIB0::22::INSTR") - # if no "time" in metadata, set the current local time in ISO 8601 format - # and without microseconds - if not "time" in data.metadata: - data.metadata["time"] = datetime.datetime.now().replace(microsecond=0).astimezone().isoformat() + get_time = lambda: datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S") + if add_measurement_info_to_metadata: + data.metadata["measurement_interval"] = str(delta_t) + data.metadata["measurement_use_buffer"] = str(use_buffer) + data.metadata["measurement_voltage_device"] = str(vm_dev) + data.metadata["measurement_led_device"] = str(led_dev) + data.metadata["measurement_time_start"] = get_time() + # write metadata to disk + data.write_metadata() vm_dev.reset(True) if use_buffer: vm_dev.buffer_measure(delta_t, verbose=True) @@ -148,6 +151,10 @@ def measure( except KeyboardInterrupt: pass + if add_measurement_info_to_metadata: + data.metadata["measurement_time_stop"] = get_time() + # Write again after having updated the stop time + data.write_metadata() data.flush(verbose=verbose) led_dev.off()