fix(flomni): re-read tracker signal on the too-low second chance; plan batched single-point tomo
CI for csaxs_bec / test (push) Successful in 3m1s

laser_tracker_check_signalstrength() slept 1 s on a too-low signal and
then compared the same stale value again. Re-read it.

Add docs/plans/flomni-batched-single-point-tomo.md: one armed scan per
batch of angles for single-point tomography (not implemented).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALDnH16dC6iyHjhe5Ey4w9
This commit is contained in:
x12saandClaude Opus 5.5 committed 2026-10-15 19:37:36 +02:00
1 parent f680f9dd18
commit 5454e238a6
3 files changed
+170

No files matched your search

@@ -479,7 +479,10 @@ class RtFlomniController(Controller):
print(f"min signal: {min_signal}")
print(f"signal: {signal}")
if signal < min_signal:
# second chance: re-read after a short wait (the old code
# compared the same stale value again)
time.sleep(1)
signal = self.read_ssi_interferometer(1)
if signal < min_signal:
print(
f"\x1b[91mThe signal of the tracker {signal} is below the minimum required signal of {min_signal}. Readjustment requred!\x1b[0m"
@@ -0,0 +1,145 @@
# Plan: Batched single-point tomography for flOMNI (one armed scan for many angles)
Status: **not implemented** (planned 2026-10-15 during the LamNI beamtime; the
only code change made alongside it is the laser-tracker re-read bug fix, see
§6).
## Goal
flOMNI's single-point tomo mode (`single_point_instead_of_fermat_scan`) takes
one BEC scan per angle: `Flomni.tomo_acquire_at_angle()` rotates `fsamroy`,
moves `rtx/rty/rtz`, checks the laser tracker and then calls `scans.acquire()`.
Every angle therefore pays the full scan open/stage/unstage/close cycle plus
the client round-trip.
Instead: arm the detectors **once per batch of angles**, and inside that one
scan, for each point: rotate, move to the target position, trigger one
acquisition, read out, continue with the next angle.
## Expected saving
From `csaxs_bec/bec_ipython_client/plugins/flomni/AI_docs/FLOMNI_SCAN_OVERHEAD.md`
(flOMNI beamtime 2026-10-07…12, 10,403 fermat scans):
- Scan-to-scan dead time **3.2 s median**, dominated by serial bookkeeping
(end-of-scan polling, close, client round-trip, prepare, open, detector
staging, laser tracker on), not by the rotation (0.6–0.9 s for 1–2° steps).
- In a batched scan a point should cost roughly rotation + rt move + tracker
on-target + exposure. Estimated saving **~2–2.5 s per angle** at small
angular steps (e.g. ~1.5 h on a 2000-angle tomogram).
- The overhead document measured `flomni_fermat_scan`, not `scans.acquire`.
**First step:** measure the current single-point mode per angle (same log
markers as in that document) to confirm the baseline.
## Decisions (agreed 2026-10-15)
1. **Analysis:** one scan containing many angles is fine for the data
analysis. The scan must record, per point, the angle and the rtx/rty/rtz
target positions.
2. **Batching:** configurable batch size; one BEC scan per batch. Limits what
has to be repeated after a failure or an interlock "abort and repeat".
3. **Laser tracker:** checked regularly inside the scan depending on the
angular step: after a rotation once the accumulated rotation since the last
check exceeds a parameter (degrees), and once at the start of each batch.
"toolow" aborts (→ batch repeated), "low" warns, as in the fermat scan.
4. **Shutter:** no extra handling. The trigger via the delay generator (ddg1)
already opens the shutter for each exposure, so it stays closed during
rotation and moves.
5. **Trigger source:** none needed from the RT system or beamline. BEC's
software-triggered step-scan path already arms once for many points:
- Eiger stages `num_points × frames_per_trigger` triggers
(`devices/jungfraujoch/eiger.py:490`);
- ddg1 in `SINGLE_SHOT` sends one software trigger per BEC `trigger`
(`devices/epics/delay_generator_csaxs/ddg_1.py:679`);
- the MCS card handles `software_triggered` scans with `num_points`
(`devices/epics/mcs_card/mcs_card_csaxs.py:383`).
## Design
### Scan plugin `flomni_point_tomo_scan` (new, `csaxs_bec/scans/`)
Software-triggered step scan (`ScanBase`), modelled on `flomni_fermat_scan.py`.
- **Inputs:** `angles` (list), `positions` (list of `[x, y, z]` per angle,
computed on the client), `exp_time`, `frames_per_trigger`,
`tracker_check_every_deg`.
- **prepare_scan:** validate lengths; `update_scan_info(num_points=len(angles),
positions=...)`; store angles/positions in the scan metadata for the
analysis.
- **stage / pre_scan:** `stage_all_devices()` (arms Eiger/MCS once), ddg1 →
`SINGLE_SHOT`, `laser_tracker_on()`, `move_samx_to_scan_region()` for the
first point.
- **scan_core, per point:**
1. rotate `fsamroy` (reuse `flomni_rotation()` incl. its progress report);
skip when already at the angle;
2. move `rtx/rty/rtz` to the target; call `move_samx_to_scan_region()` when
x leaves the current coarse region;
3. if the accumulated rotation exceeds `tracker_check_every_deg`:
**wait for tracker on target** (must happen before the exposure, the
interferometer positions depend on it);
4. trigger **without waiting**; while the exposure runs, **read and judge
the tracker signal strength** (read-only on the RT controller; the
exposure runs through ddg1, so the controller socket is free);
5. wait for the trigger status, `read_monitored_devices()`;
6. "toolow" → raise `ScanAbortion` (the point was taken with a bad signal;
batch is repeated); "low" → alarm WARNING.
- **post_scan / on_exception:** `complete_all_devices()`, ddg1 back to
`SINGLE_SHOT` default, same as the fermat scan.
### Laser tracker changes (`devices/omny/rt/rt_flomni_ophyd.py`)
- Split `laser_tracker_check_signalstrength()` into
`laser_tracker_wait_on_target()` (already separate) and a new read-only
`laser_tracker_signal_status()` that only reads and classifies the signal,
so the scan can call them at different times (steps 3 and 4 above).
- **Polling period of `laser_tracker_wait_on_target()` 0.5 s → 50 ms**
(agreed). Its loop counts iterations (`count == 10` re-enables tracking,
`count > 100` raises), so convert both thresholds to elapsed time
(currently 5 s and 50 s) to keep the behaviour. Benefits every flOMNI scan:
the overhead document measured 0.5 s, or 0.87 s when it has to wait, here.
### Client (`bec_ipython_client/plugins/flomni/flomni.py`)
- New switch on the existing single-point mode, e.g.
`single_point_batched` + `single_point_batch_size`, rather than a new tomo
type. The angle plan (tomo types 1/2/3, sub-tomograms, golden ratio) is
unchanged; only the execution changes.
- Compute per-angle positions exactly as `tomo_acquire_at_angle()` does today
(`get_alignment_offset`, `compute_additional_correction_y(_2)`,
`manual_shift_x/y`, random shift), then submit one
`flomni_point_tomo_scan` per batch.
- **Progress / resume:** advance per completed batch; resume starts at the
first angle of the interrupted batch. Interlock "restart_scan" repeats the
current batch.
- **Projection logs, scilog, reconstruction queue:** one scan number now
covers a batch of angles; record the scan number with its angle range /
angle list.
- Webpage/GUI progress: update per point from the scan's progress report if
possible, else per batch.
## Implementation order
1. Measure the current single-point overhead per angle (baseline).
2. Tracker: `laser_tracker_signal_status()` split + 50 ms polling with
time-based thresholds; tests.
3. Scan plugin with tests (simulated devices, see
`flomni/AI_docs/SIMULATED_ENDSTATIONS.md`).
4. Client batching, progress/resume, logging; tests.
5. Hardware test: short batch (e.g. 10 angles), check data, tracker
behaviour, shutter timing; then compare per-angle time with step 1.
## Open points
- Eiger: confirm no trigger timeout while armed and waiting during a large
rotation (> 20° took up to ~4.8 s in the overhead data).
- Whether a tracker check before *every* exposure is needed at very small
steps, or only on the angular threshold.
- Per-point dead time inside scans (~30–50 ms, overhead document §2) is a
separate issue and not addressed here.
## Done alongside this plan
- `laser_tracker_check_signalstrength()`: the "too low" branch slept 1 s and
then compared the **same** value again, so the intended second chance did
nothing. It now re-reads the signal (`rt_flomni_ophyd.py`), with a test in
`tests/tests_devices/test_rt_flomni.py`.
+22
View File
@@ -98,3 +98,25 @@ def test_feedback_enable_without_reset_raises(rt_flomni):
rt_flomni.feedback_enable_without_reset()
laser_tracker_on.assert_called_once()
assert mock.call(b"l3\n") in rt_flomni.sock.put.mock_calls
@pytest.mark.parametrize(
"first,second,expected", [(10, 10, "toolow"), (10, 200, "ok")]
)
def test_laser_tracker_signalstrength_rereads_after_too_low(rt_flomni, first, second, expected):
"""A too-low signal gets a second chance after 1 s: the signal must be
re-read, not the stale first value compared again."""
rt_flomni.device_manager.devices.rtx.user_parameter.get.side_effect = {
"min_signal": 50,
"low_signal": 100,
}.get
with (
mock.patch.object(rt_flomni, "laser_tracker_check_enabled", return_value=True),
mock.patch.object(rt_flomni, "laser_tracker_wait_on_target"),
mock.patch.object(
rt_flomni, "read_ssi_interferometer", side_effect=[first, second]
) as read_ssi,
mock.patch("csaxs_bec.devices.omny.rt.rt_flomni_ophyd.time.sleep"),
):
assert rt_flomni.laser_tracker_check_signalstrength(verbose=False) == expected
assert read_ssi.call_count == 2