From 5b688df428f6b1b11ffe35514e30697da59998bb Mon Sep 17 00:00:00 2001 From: x12sa Date: Mon, 21 Sep 2026 14:55:20 +0200 Subject: [PATCH] fix(flomni): always define tomo_alignment_fit The global var was deleted on stage-in / new alignment and never created at startup, so manual tweaks like fit[0][2] += 5.0 failed with an undefined variable. reset_tomo_alignment_fit() now writes an all-zero 2x5 fit instead of deleting, and Flomni.__init__ creates it if missing (an existing fit is kept so it survives client restarts). Co-Authored-By: Claude Sonnet 5 --- .../bec_ipython_client/plugins/flomni/flomni.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py index 5a105b75..f8cda11a 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py @@ -1406,7 +1406,21 @@ class FlomniAlignmentMixin: logger.warning("Not applying any correction.") def reset_tomo_alignment_fit(self): - self.client.delete_global_var("tomo_alignment_fit") + """Reset the alignment fit to all zeros (no offset applied). + + Writes zeros rather than deleting the global var, so that + "tomo_alignment_fit" is always defined and can be tweaked by hand + (see the layout comment above get_alignment_offset). + """ + self.client.set_global_var("tomo_alignment_fit", np.zeros((2, 5)).tolist()) + + def ensure_tomo_alignment_fit(self): + """Define "tomo_alignment_fit" (all zeros) if it does not exist yet. + + An existing fit is left untouched so it survives a client restart. + """ + if self.client.get_global_var("tomo_alignment_fit") is None: + self.reset_tomo_alignment_fit() def read_alignment_offset( self, @@ -1810,6 +1824,7 @@ class Flomni( self.label_printer = PTouchLabelPrinter(host="BRN94DDF8AAB8EC.psi.ch", template_number=1) self.set_client(client) + self.ensure_tomo_alignment_fit() self._maybe_reset_params_on_account_change() def set_web_password(self, password: str) -> None: