From 7a4c19f38f4ab54b4acd1057de971ca4e870ae12 Mon Sep 17 00:00:00 2001 From: appel_c Date: Mon, 15 Jun 2026 14:01:16 +0200 Subject: [PATCH] feat(utils): add utils to migrate previous scan_info to scans_v4 scan_info --- csaxs_bec/devices/utils/__init__.py | 0 csaxs_bec/devices/utils/utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 csaxs_bec/devices/utils/__init__.py create mode 100644 csaxs_bec/devices/utils/utils.py diff --git a/csaxs_bec/devices/utils/__init__.py b/csaxs_bec/devices/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/csaxs_bec/devices/utils/utils.py b/csaxs_bec/devices/utils/utils.py new file mode 100644 index 0000000..1475961 --- /dev/null +++ b/csaxs_bec/devices/utils/utils.py @@ -0,0 +1,26 @@ +"""Utility functions for the devices.""" + +from copy import deepcopy + +import numpy as np +from bec_lib.devicemanager import ScanInfo +from bec_server.scan_server.scans.scan_base import ScanInfo as ScanServerScanInfo +from pydantic import ValidationError + + +def fetch_scan_info(scan_info: ScanInfo) -> ScanServerScanInfo: + """Fetch the scan parameters from the scan_info object and return them as a ScanServerScanInfo object.""" + info = scan_info.msg.info + if isinstance(info["positions"], list): + info["positions"] = np.array(info["positions"]) + try: + msg = ScanServerScanInfo.model_validate(info) + except ValidationError: # This means we have an old scan_info object. + info = deepcopy(info) + # We need to convert a few parameters manually. + info["scan_type"] = ( + "hardware_triggered" if info["scan_type"] == "fly" else "software_triggered" + ) + msg = ScanServerScanInfo.model_validate(info) + + return msg