From f7dd2455593fad007695709d04467a4e2b94b9d5 Mon Sep 17 00:00:00 2001 From: appel_c Date: Tue, 28 Jul 2026 14:09:25 +0200 Subject: [PATCH] fix: add saxs_scan_macro --- csaxs_bec/macros/saxs_scan_macro.py | 49 +++++++++++++++++++++++++++ csaxs_bec/scripts/saxs_scan_script.py | 38 --------------------- 2 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 csaxs_bec/macros/saxs_scan_macro.py delete mode 100644 csaxs_bec/scripts/saxs_scan_script.py diff --git a/csaxs_bec/macros/saxs_scan_macro.py b/csaxs_bec/macros/saxs_scan_macro.py new file mode 100644 index 0000000..bd71e75 --- /dev/null +++ b/csaxs_bec/macros/saxs_scan_macro.py @@ -0,0 +1,49 @@ +""" +saxs_scan_macro_py macro - Created at 2026-07-15 10:57:40 +""" + + +def saxs_scan_macro_py( + session_name: str, use_index: int = -1, phone_numbers: list[str] | None = None +): + """ + Description of what this macro does. + + Add your macro implementation here. + """ + print("Executing macro: saxs_scan_macro_py") + # TODO: Add your macro code here + + # If not Swiss numbers, please provide + prefix. If empty, no signal notifications will be sent. + # List of phone numbers to send signal notifications to, example: ["+1234567890", "+0987654321"]. + if phone_numbers is None: + phone_numbers = [] + + # count = -1 means latest saved table from the SAXS widget, 0 means first saved table, 1 means second saved table, etc. -1 is DEFAULT + # Provide it as a kwargs if you need to fetch older table data. + msg = get_saxs_widget_table_data(session_name=session_name, count=use_index) + + print( + f"Fetched {len(msg.value)} rows from SAXS widget table for session '{msg.metadata.get('session_name')}'. Table data created at {msg.metadata.get('timestamp')}" + ) + + total_rows = len(msg.value) + for ii, row in enumerate(msg.value): + print(f"Running continuous grid scan for row {ii + 1}/{total_rows}: {row}") + run_cont_grid_scan_for_table_row( + session_name=session_name, row=row, phone_numbers=phone_numbers + ) + if ii % 10 == 0: + # Send update to scilog every 10 scans to avoid spamming the log + message = bec.messaging.scilog.new() + message.add_text( + f"Completed {ii + 1}/{total_rows} continuous grid scans for session '{session_name}'" + ) + message.send() + # Send update to signal if phone numbers are provided + if phone_numbers: + message = bec.messaging.signal.new() + message.add_text( + f"Completed {ii + 1}/{total_rows} continuous grid scans for session '{session_name}'" + ) + message.send(scope=phone_numbers) diff --git a/csaxs_bec/scripts/saxs_scan_script.py b/csaxs_bec/scripts/saxs_scan_script.py deleted file mode 100644 index dccb034..0000000 --- a/csaxs_bec/scripts/saxs_scan_script.py +++ /dev/null @@ -1,38 +0,0 @@ -# List of phone numbers to send signal notifications to, example: ["+1234567890", "+0987654321"]. -# If not Swiss numbers, please provide + prefix. If empty, no signal notifications will be sent. - -############# -### Example script, copy from here and edit to your needs -############# -TELEFON_NUMBERS = [] -SESSION_NAME = "test_session" - - -# count = -1 means latest saved table from the SAXS widget, 0 means first saved table, 1 means second saved table, etc. -1 is DEFAULT -# Provide it as a kwargs if you need to fetch older table data. -msg = get_saxs_widget_table_data(SESSION_NAME) - -print( - f"Fetched {len(msg.value)} rows from SAXS widget table for session '{msg.metadata.get('session_name')}'. Table data created at {msg.metadata.get('timestamp')}" -) - -total_rows = len(msg.value) -for ii, row in enumerate(msg.value): - print(f"Running continuous grid scan for row {ii + 1}/{len(msg.value)}: {row}") - run_cont_grid_scan_for_table_row( - session_name=SESSION_NAME, row=row, phone_numbers=TELEFON_NUMBERS - ) - if ii % 10 == 0: - # Send update to scilog every 10 scans to avoid spamming the log - msg = bec.messaging.scilog.new() - msg.add_text( - f"Completed {ii + 1}/{total_rows} continuous grid scans for session '{SESSION_NAME}'" - ) - msg.send() - # Send update to signal if phone numbers are provided - if TELEFON_NUMBERS: - msg = bec.messaging.signal.new() - msg.add_text( - f"Completed {ii + 1}/{total_rows} continuous grid scans for session '{SESSION_NAME}'" - ) - msg.send(scope=TELEFON_NUMBERS)