From 09132b8bdde8b94befd148ea4893f5ed15643839 Mon Sep 17 00:00:00 2001 From: x12sa Date: Thu, 10 Sep 2026 10:14:40 +0200 Subject: [PATCH] Automatic backup triggered by new deployment --- csaxs_bec/device_configs/main.yaml | 8 +- .../run_cont_grid_scan_for_table_row.py.bak | 133 ++++++++++++++++++ 2 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 csaxs_bec/macros/run_cont_grid_scan_for_table_row.py.bak diff --git a/csaxs_bec/device_configs/main.yaml b/csaxs_bec/device_configs/main.yaml index 48261723..576e8817 100644 --- a/csaxs_bec/device_configs/main.yaml +++ b/csaxs_bec/device_configs/main.yaml @@ -13,14 +13,14 @@ optics: endstation: - !include ./bl_endstation.yaml -detectors: - - !include ./bl_detectors.yaml +# detectors: +# - !include ./bl_detectors.yaml xeye: - !include ./xeye.yaml -ssaxs: - - !include ./ssaxs.yaml +# ssaxs: +# - !include ./ssaxs.yaml #sastt: # - !include ./sastt.yaml diff --git a/csaxs_bec/macros/run_cont_grid_scan_for_table_row.py.bak b/csaxs_bec/macros/run_cont_grid_scan_for_table_row.py.bak new file mode 100644 index 00000000..cdfbd530 --- /dev/null +++ b/csaxs_bec/macros/run_cont_grid_scan_for_table_row.py.bak @@ -0,0 +1,133 @@ +""" +This macro is used to run a cont_grid scan for a single row of the data provided by the SAXS widget. +These are fetched through the get_saxs_widget_table_data macro, which returns a Variable message containing +'value' and 'metadata' fields. 'value' contains a list of dictionaries, each representing a row in the table. +This dictionary is the input for this macro. +""" + +from __future__ import annotations + +import numpy as np +from bec_lib.scan_repeat import scan_repeat + + +# TODO Default True here means that ANY error will be retried up to 3 times. This is dangerous in the sense that +# if the error is due to a misconfiguration of the scan parameters, it will just keep retrying and failing. +# Please contact the BEC team if you want to establish a dedicated error handling for this macro. +@scan_repeat(max_repeats=3, default=True) +def run_cont_grid_scan_for_table_row( + session_name: str, row: dict, phone_numbers: list[str] | None = None +) -> None: + """ + Run a continuous grid scan for a specific row in the SAXS widget table. + + Args: + row (dict): A dictionary representing a row in the SAXS widget table. This should contain all necessary + parameters for the continuous grid scan. + phone_numbers (list[str] | None): A list of phone numbers to notify in case of errors. Defaults to None. + """ + metadata = { + "session_name": session_name, + "sample_name": row["sample_name"], + "sample_id": row["sample_id"], + "comment": row["comment"], + "raw_roi": { + "x": row["raw_roi_x"], + "y": row["raw_roi_y"], + "width": row["raw_roi_width"], + "height": row["raw_roi_height"], + }, + "camera_center": {"x": row["camera_center_x"], "y": row["camera_center_y"]}, + "correction_camera_scale_pixel_x": row["correction_camera_scale_pixel_x"], + "correction_offset_cam_xray_x": row["correction_offset_cam_xray_x"], + "grid_scan_params": { + "fast_axis": row["fast_axis"], + "fast_start": row["fast_start"], + "fast_stop": row["fast_stop"], + "fast_step": row["fast_step"], + "stepper_axis": row["stepper_axis"], + "stepper_start": row["stepper_start"], + "stepper_stop": row["stepper_stop"], + "stepper_step": row["stepper_step"], + "exposure_time": row["exposure_time"], + "images_per_line": row["images_per_line"], + "num_lines": row["num_lines"], + }, + } + if row["template"] == "tensor": + metadata.update( + { + "roty_axis": row["roty_axis"], + "roty": row["roty"], + "rotx_axis": row["rotx_axis"], + "rotx": row["rotx"], + } + ) + + # Move rotation motors if tensor tomography scan template is send. + if row["template"] == "tensor": + try: + # Move motors to the starting position of the scan + move_command = [] + roty_motor = dev.devices[row["roty_axis"]] + setpoint_roty = roty_motor.setpoint.get(cached=True) + if not np.isclose(setpoint_roty, row["roty"]): + move_command.extend([row["roty_axis"], row["roty"]]) + setpoint_rotx = dev.devices[row["rotx_axis"]].setpoint.get(cached=True) + if not np.isclose(setpoint_rotx, row["rotx"]): + move_command.extend([row["rotx_axis"], row["rotx"]]) + # Wait for all motor movements to complete + if move_command: + scans.umv(*move_command, relative=False) + except Exception as e: + info_msg = ( + "Error while moving motors to starting position for sample " + f"'{row['sample_name']}' (ID: {row['sample_id']})." + ) + print(info_msg) + # Send message to scilog with error tag and text + msg = bec.messaging.scilog.new() + msg.add_tags("error") + msg.add_text(info_msg) + msg.add_text(f"Error details: {e}") + msg.send() + # Notify the user via SMS if phone numbers are provided + if phone_numbers: + msg = bec.messaging.signal.new() + msg.add_text(info_msg) + msg.send(scope=phone_numbers) + raise + + # Scan command + try: + scans.cont_grid( + fast_axis=row["fast_axis"], + fast_start=row["fast_start"], + fast_end=row["fast_stop"], + fast_step_size=row["fast_step"], + stepper_axis=row["stepper_axis"], + stepper_start=row["stepper_start"], + stepper_stop=row["stepper_stop"], + stepper_step_size=row["stepper_step"], + exp_time=row["exposure_time"], + relative=False, + metadata=metadata, + ) + except Exception as e: + info_msg = ( + f"Error while executing cont_grid scan for sample '{row['sample_name']}' " + f"with ID '{row['sample_id']}'." + ) + print(info_msg) + # Send message to scilog with error tag and text + msg = bec.messaging.scilog.new() + msg.add_tags("error") + msg.add_text(info_msg) + msg.add_text(f"Error details: {e}") + msg.send() + # Notify the user via SMS if phone numbers are provided + if phone_numbers: + msg = bec.messaging.signal.new() + msg.add_text(info_msg) + msg.send(scope=phone_numbers) + raise