diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py index f4847c67..83def288 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py @@ -217,9 +217,10 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools f"step={p.get('tomo_shellstep')}um ctime={p.get('tomo_countingtime')}s" ) - def __init__(self, client): + def __init__(self, client, csaxs=None): super().__init__() self.client = client + self.csaxs = csaxs self.set_client(client) self.device_manager = client.device_manager self.init = LaMNIInitStages(client) diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py index 27998ae8..10915a20 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py @@ -214,12 +214,58 @@ class LamNIOpticsMixin: return None return param.get(var) + @property + def _sl1xs_before_eye(self): + return self.client.get_global_var("lamni_sl1xs_before_eye") + + @_sl1xs_before_eye.setter + def _sl1xs_before_eye(self, val): + self.client.set_global_var("lamni_sl1xs_before_eye", val) + + @property + def _sl1ys_before_eye(self): + return self.client.get_global_var("lamni_sl1ys_before_eye") + + @_sl1ys_before_eye.setter + def _sl1ys_before_eye(self, val): + self.client.set_global_var("lamni_sl1ys_before_eye", val) + def leye_out(self): self.loptics_in() # Close (not open) the shutter as the eye leaves the beam, like # flomni's feye_out(). Was fshclose() originally; commit 4967474 # ("removed fsh commands") turned it into fshopen() by mistake. dev.fsh.fshclose() + + if self.csaxs is not None: + self.csaxs.fil_trans(1, print_only=False) + + sl1xs_before = self._sl1xs_before_eye + sl1ys_before = self._sl1ys_before_eye + if sl1xs_before is not None and sl1ys_before is not None: + # if the slit was manually re-adjusted while the eye was in, + # offer to keep the current size instead of restoring the + # pre-eye value + current_sl1xs = dev.sl1xs.user_readback.get() + current_sl1ys = dev.sl1ys.user_readback.get() + expected_sl1xs = sl1xs_before + 0.3 + expected_sl1ys = sl1ys_before + 0.3 + tol = 0.01 # mm (10 microns) + manually_adjusted = not np.isclose( + current_sl1xs, expected_sl1xs, atol=tol + ) or not np.isclose(current_sl1ys, expected_sl1ys, atol=tol) + + if manually_adjusted and self.OMNYTools.yesno( + "sl1xs/sl1ys appear to have been adjusted manually while the " + "eye was in. Keep the current slit size instead of " + "restoring the pre-eye value?" + ): + print("Keeping current slit size, not restoring pre-eye value.") + else: + umv(dev.sl1xs, sl1xs_before, dev.sl1ys, sl1ys_before) + self._sl1xs_before_eye = None + self._sl1ys_before_eye = None + leyey_out = self._get_user_param_safe("leyey", "out") umv(dev.leyey, leyey_out) @@ -267,6 +313,23 @@ class LamNIOpticsMixin: return leyex_in = self._get_user_param_safe("leyex", "in") leyey_in = self._get_user_param_safe("leyey", "in") + + current_leyex = dev.leyex.readback.get() + current_leyey = dev.leyey.readback.get() + + # check if both are close enough (within 0.01) + if np.isclose(current_leyex, leyex_in, atol=0.01) and np.isclose(current_leyey, leyey_in, atol=0.01): + # both already in position -> do nothing + pass + else: + if "sl1xs" in dev and "sl1ys" in dev: + self._sl1xs_before_eye = dev.sl1xs.user_readback.get() + self._sl1ys_before_eye = dev.sl1ys.user_readback.get() + scans.umv(dev.sl1xs, 0.3, dev.sl1ys, 0.3, relative=True) + + if self.csaxs is not None: + self.csaxs.fil_trans(0.05, print_only=False) + umv(dev.leyex, leyex_in, dev.leyey, leyey_in) self.xrayeye_update_frame() diff --git a/csaxs_bec/bec_ipython_client/startup/post_startup.py b/csaxs_bec/bec_ipython_client/startup/post_startup.py index e1981652..26564c71 100644 --- a/csaxs_bec/bec_ipython_client/startup/post_startup.py +++ b/csaxs_bec/bec_ipython_client/startup/post_startup.py @@ -51,7 +51,7 @@ if _args.session.lower() == "lamni": from csaxs_bec.bec_ipython_client.plugins.LamNI import LamNI _session_name = "LamNI" - lamni = LamNI(bec) + lamni = LamNI(bec, csaxs=csaxs) logger.success("LamNI session loaded.") print(r""" ██████╗ ███████╗ ██████╗ ██╗ █████╗ ███╗ ███╗███╗ ██╗██╗