fix(flomni): x-ray eye Ctrl-C handler looked up fsamx by device object; ffzp_info collision position

- start_x_ray_eye_alignment: _get_user_param_safe() needs the device name (dev[name]); with dev.fsamx the
  KeyboardInterrupt handler raised KeyError and fsamx was never returned to its in position
- ffzp_info: the OSA collides at fosaz = 33 - foptz (compute_osa_remaining_space), printed 33 - fosaz

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019aWcwG89wi7oVyrefukXX6
This commit is contained in:
Claude committed 2026-10-24 06:43:17 +00:00
1 parent 1a5b53c031
commit b939793416
3 files changed
+41 -2

No files matched your search

@@ -1852,7 +1852,7 @@ class Flomni(
try:
self.align.align(keep_shutter_open)
except KeyboardInterrupt as exc:
fsamx_in = self._get_user_param_safe(dev.fsamx, "in")
fsamx_in = self._get_user_param_safe("fsamx", "in") # name: dev[...] lookup (a device raised)
if np.isclose(fsamx_in, dev.fsamx.readback.get(), rtol=0, atol=0.5):
print("Stopping alignment. Returning to fsamx in position.")
self.feedback_disable()
@@ -420,7 +420,8 @@ class FlomniOpticsMixin:
print("\nOSA Information:")
print(f" Current fosaz {fosaz_val:.1f}")
print(f" The OSA will collide with a normal OMNY pin at fosaz \033[1m{(33-fosaz_val):.1f}\033[0m")
# collision where compute_osa_remaining_space() = 33 - foptz - fosaz reaches 0 (was 33 - fosaz)
print(f" The OSA will collide with a normal OMNY pin at fosaz \033[1m{(33-foptz_val):.1f}\033[0m")
print(f" Remaining space (right now): \033[1m{remaining_current:.1f}\033[0m")
diff = fosaz_val - fosaz_in # >0: OSA is currently more "in" than nominal -> worse
@@ -139,3 +139,41 @@ def test_heater_down_needs_fsamx_in_within_0_2_mm(monkeypatch, readback, ok):
with pytest.raises(FlomniError):
flomni.move_fheater_down()
assert not moved
class _DevContainer(dict):
"""dict keyed by device name, like bec_lib's DeviceContainer (attribute access too)."""
def __getattr__(self, name):
return self[name]
def test_xray_eye_ctrl_c_returns_fsamx_in(monkeypatch):
"""The KeyboardInterrupt handler passed the device instead of its name: dev[device] raised."""
import csaxs_bec.bec_ipython_client.plugins.flomni.flomni_optics_mixin as optics_module
flomni = _make_flomni()
fsamx = types.SimpleNamespace(
user_parameter={"in": -1.14}, readback=types.SimpleNamespace(get=lambda: -1.3)
)
fake_dev = _DevContainer(fsamx=fsamx)
monkeypatch.setitem(builtins.__dict__, "dev", fake_dev)
monkeypatch.setattr(flomni_module, "dev", fake_dev, raising=False)
monkeypatch.setattr(optics_module, "dev", fake_dev, raising=False)
moved = []
monkeypatch.setattr(flomni_module, "umv", lambda *a: moved.append(a), raising=False)
flomni.OMNYTools = types.SimpleNamespace(yesno=lambda *a, **k: True)
flomni.feedback_disable = lambda: None
class _Align:
def __init__(self, *a):
pass
def align(self, keep_shutter_open):
raise KeyboardInterrupt
monkeypatch.setattr(flomni_module, "XrayEyeAlign", _Align)
with pytest.raises(KeyboardInterrupt):
flomni.start_x_ray_eye_alignment()
assert moved == [(fsamx, -1.14)]