Capture more metadata

This commit is contained in:
CPD 2025-03-10 11:07:20 +01:00
parent 2232a91f2e
commit 910737202f

View File

@ -25,7 +25,8 @@ def measure(
stop_on_script_end: bool=False, stop_on_script_end: bool=False,
verbose: bool=False, verbose: bool=False,
command_queue: None|Queue=None, command_queue: None|Queue=None,
data_queue: None|Queue=None data_queue: None|Queue=None,
add_measurement_info_to_metadata=True
): ):
""" """
Perform a measurement Perform a measurement
@ -62,22 +63,24 @@ def measure(
The default is None. The default is None.
data_queue : None|Queue, optional data_queue : None|Queue, optional
A queue to put data in. The default is None. 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 Returns
------- -------
None. None.
""" """
# old hack when using multiprocessing instead of mulithreading: get_time = lambda: datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
# devices are not pickleable and thus cant be moved to / shared with the measurement process if add_measurement_info_to_metadata:
# if led_dev is None: data.metadata["measurement_interval"] = str(delta_t)
# led_dev = LEDD1B() data.metadata["measurement_use_buffer"] = str(use_buffer)
# if vm_dev is None: data.metadata["measurement_voltage_device"] = str(vm_dev)
# vm_dev = init("GPIB0::22::INSTR") data.metadata["measurement_led_device"] = str(led_dev)
# if no "time" in metadata, set the current local time in ISO 8601 format data.metadata["measurement_time_start"] = get_time()
# and without microseconds # write metadata to disk
if not "time" in data.metadata: data.write_metadata()
data.metadata["time"] = datetime.datetime.now().replace(microsecond=0).astimezone().isoformat()
vm_dev.reset(True) vm_dev.reset(True)
if use_buffer: if use_buffer:
vm_dev.buffer_measure(delta_t, verbose=True) vm_dev.buffer_measure(delta_t, verbose=True)
@ -148,6 +151,10 @@ def measure(
except KeyboardInterrupt: except KeyboardInterrupt:
pass 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) data.flush(verbose=verbose)
led_dev.off() led_dev.off()