Keyword auto updates for alignment scans

This commit is contained in:
gac-x06da
2025-02-18 17:15:17 +01:00
committed by mohacsi_i
parent d8a178ae13
commit 284914dc53

View File

@@ -2,6 +2,13 @@ from bec_widgets.cli.auto_updates import AutoUpdates, ScanInfo
class PlotUpdate(AutoUpdates):
create_default_dock = True
enabled = True
def do_update(self, msg):
"""Save the original scan message for future use"""
self._scan_msg = msg
return super().do_update(msg)
# def simple_line_scan(self, info: ScanInfo) -> None:
# """
@@ -15,6 +22,39 @@ class PlotUpdate(AutoUpdates):
# plt = self.figure.plot(dev_x, dev_y)
# plt.set(title=f"PXIII: Scan {info.scan_number}", x_label=dev_x, y_label=dev_y)
def keyword_handler(self, info: ScanInfo) -> None:
""" Simple keyword handler
This simple keyword handler looks for the keyword 'datasource' in the scan arguments.
This allows the user to explictly specify the desired data source. Useful for alignment
scans.
"""
dev_x = info.scan_report_devices[0]
if "kwargs" in self._scan_msg.info:
dev_y = self._scan_msg.info["kwargs"].get("datasource", None)
else:
dev_y = None
if not dev_y:
return
plt1 = self.get_default_figure()
try:
# This will throw RPCResponseTimeoutError
plt1.clear_all()
except Exception:
pass
try:
# This will throw RPCResponseTimeoutError
plt1.plot(x_name=dev_x, y_name=dev_y)
except Exception:
pass
try:
# This will throw RPCResponseTimeoutError
plt1.set(title=f"PXIII: Scan {info.scan_number}", x_label=dev_x, y_label=dev_y)
except Exception:
pass
# plt1.add_dap(dev_x, dev_y, dap="LinearModel")
def handler(self, info: ScanInfo) -> None:
# EXAMPLES:
# if info.scan_name == "line_scan" and info.scan_report_devices:
@@ -24,3 +64,5 @@ class PlotUpdate(AutoUpdates):
# self.run_grid_scan_update(info)
# return
super().handler(info)
self.keyword_handler(info)