feat(lamni): arrow keys in isolated rotation-center calibration
CI for csaxs_bec / test (push) Failing after 2m58s
CI for csaxs_bec / test (pull_request) Failing after 2m53s

The GUI arrow buttons were enabled during find_rotation_center() but never
polled. In isolated mode they now move lsamx/lsamy via
lamni_move_to_scan_center(angle=0.0); the running shift is subtracted from
the 0 and 180 deg clicks before computing the axis midpoint, so the new
center stays correct when the particle had to be brought into the FOV.
Extended mode now disables the (non-functional) arrow buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
x12saandClaude Opus 5.5 committed 2026-10-12 19:19:35 +02:00
1 parent 0100350dc2
commit 2e877b315e
1 file changed
+84 -9
@@ -764,16 +764,61 @@ class XrayEyeAlign:
ROTATION_CENTER_SAMPLE_TYPES = ("isolated", "extended")
def _collect_click(self, k: int, message: str, label: str = "") -> tuple[float, float]:
def _handle_rotation_center_arrows(self, keep_shutter_open: bool = False):
"""Apply a pending GUI arrow-button move during rotation-center
calibration.
mvx/mvy (um) are accumulated into self._rc_shift (mm, lamni coords,
absolute offset from the configured lsamx/lsamy center) and applied
via lamni_move_to_scan_center with angle=0.0: lsamx/lsamy sit below
the rotation stage, so the move is a plain image translation at any
lsamrot angle (see the math note above). The caller must map each
click back to the configured-center frame using the shift active at
click time.
"""
_mvx = dev.omny_xray_gui.mvx.get()
_mvy = dev.omny_xray_gui.mvy.get()
if _mvx == 0 and _mvy == 0:
return
self._rc_shift[0] += _mvx / 1000
self._rc_shift[1] += _mvy / 1000
self.scans.lamni_move_to_scan_center(
shift_x=self._rc_shift[0], shift_y=self._rc_shift[1], angle=0.0
).wait()
print(
f"[rotation-center] arrow move -- shift from configured center now "
f"({self._rc_shift[0]:.4f}, {self._rc_shift[1]:.4f}) mm"
)
dev.omny_xray_gui.mvx.set(0)
dev.omny_xray_gui.mvy.set(0)
self.update_frame(keep_shutter_open)
def _collect_click(
self,
k: int,
message: str,
label: str = "",
arrows: bool = False,
keep_shutter_open: bool = False,
) -> tuple[float, float]:
"""Wait for the operator to submit a click at GUI step *k*.
If *arrows* is True, GUI arrow-button presses are applied while
waiting (see _handle_rotation_center_arrows()).
Returns the click position in mm (converted via pixel_calibration).
"""
print(f"[rotation-center] step {k}: waiting for submit -- {message}")
if arrows:
# ignore any stale press from before this step
dev.omny_xray_gui.mvx.set(0)
dev.omny_xray_gui.mvy.set(0)
dev.omny_xray_gui.step.set(k)
self.send_message(message)
self.gui.enable_submit_button(True)
while True:
if arrows:
self._handle_rotation_center_arrows(keep_shutter_open)
if dev.omny_xray_gui.submit.get() == 1:
raw_x = getattr(dev.omny_xray_gui, f"xval_x_{k}").get()
raw_y = getattr(dev.omny_xray_gui, f"yval_y_{k}").get()
@@ -1301,7 +1346,9 @@ class XrayEyeAlign:
submitted at 0 deg and again at 180 deg; the midpoint of the two
is the rotation axis' projected position, independent of the
axis tilt (see the module-level math note above). No visual
judgement call and no iteration.
judgement call and no iteration. The GUI arrow buttons work at
both angles (e.g. if the particle starts outside the FOV); their
lsamx/lsamy moves are tracked and subtracted from the clicks.
"extended" -- for a non-isolated/textured sample where the rotation
centre can be visually identified directly. The sample is swept
@@ -1363,19 +1410,47 @@ class XrayEyeAlign:
self.gui.show_crosshair()
if sample_type == "isolated":
# Running arrow-button shift from the configured center (stage is
# there now, see _ensure_at_configured_center above).
self._rc_shift = [0.0, 0.0]
self.movement_buttons_enabled(True, True)
p0 = self._collect_click(1, "Submit particle centre (0 deg).", label="particle @0deg")
p0 = self._collect_click(
1,
"Submit particle centre (0 deg).",
label="particle @0deg",
arrows=True,
keep_shutter_open=keep_shutter_open,
)
s0 = tuple(self._rc_shift)
self._disable_rt_feedback()
self.tomo_rotate(180)
self.update_frame(keep_shutter_open)
self.movement_buttons_enabled(True, True)
p180 = self._collect_click(
2, "Submit the SAME particle's centre (180 deg).", label="particle @180deg"
2,
"Submit the SAME particle's centre (180 deg).",
label="particle @180deg",
arrows=True,
keep_shutter_open=keep_shutter_open,
)
center_x, center_y = (p0[0] + p180[0]) / 2, (p0[1] + p180[1]) / 2
s180 = tuple(self._rc_shift)
self.movement_buttons_enabled(False, False)
# Map both clicks back to the configured-center frame: a shift s
# moves the image by +s_x in x and -s_y in y (same convention as
# _compute_shift_to_fzp). The midpoint is then the axis position
# with the stage at the configured center, so the target below is
# directly the absolute shift from that center.
p0_ref = (p0[0] - s0[0], p0[1] + s0[1])
p180_ref = (p180[0] - s180[0], p180[1] + s180[1])
print(
f"[rotation-center] midpoint of ({p0[0]:.4f},{p0[1]:.4f}) and "
f"({p180[0]:.4f},{p180[1]:.4f}) = ({center_x:.4f},{center_y:.4f}) mm "
"-- this is the rotation axis' current projected position"
f"[rotation-center] arrow shift at 0 deg click: ({s0[0]:.4f},{s0[1]:.4f}) mm, "
f"at 180 deg click: ({s180[0]:.4f},{s180[1]:.4f}) mm"
)
center_x, center_y = (p0_ref[0] + p180_ref[0]) / 2, (p0_ref[1] + p180_ref[1]) / 2
print(
f"[rotation-center] midpoint of ({p0_ref[0]:.4f},{p0_ref[1]:.4f}) and "
f"({p180_ref[0]:.4f},{p180_ref[1]:.4f}) = ({center_x:.4f},{center_y:.4f}) mm "
"-- this is the rotation axis' projected position at the configured center"
)
self._disable_rt_feedback()
self.tomo_rotate(0)
@@ -1392,7 +1467,7 @@ class XrayEyeAlign:
)
self._live_sweep([180, 0])
self.update_frame(keep_shutter_open)
self.movement_buttons_enabled(True, True)
self.movement_buttons_enabled(False, False)
center_x, center_y = self._collect_click(
1,
"Submit the rotation centre.",