From 96c02b3367adc4efebed678583b931a69711a72f Mon Sep 17 00:00:00 2001 From: Mirko Holler Date: Mon, 26 Oct 2026 14:01:12 +0100 Subject: [PATCH] fix(tomo_params): pin seed=0 in the OMNY fermat position estimate, as flomni/lamni get_omny_fermat_spiral_pos() draws a random sub-step offset per call, so the estimate (and its test against a second call) was not reproducible. Co-Authored-By: Claude Opus 5.5 --- .../bec_widgets/widgets/tomo_params/tomo_params.py | 13 ++++++++++++- .../test_omny_tomo_params_widget_math.py | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py b/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py index 05796e04..f6f377c3 100644 --- a/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py +++ b/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py @@ -2767,6 +2767,11 @@ def _compute_fermat_positions_omny(params: dict[str, Any]) -> tuple[int, int]: estimate can never drift out of sync. cenx/ceny/zshift left at their defaults -- they only shift the final position, never affect the count. + The real scan also draws a fresh random sub-step offset on every call + (see get_omny_fermat_spiral_pos()'s `seed` argument), which can shift + the actual scan-time count by a point or two near the threshold. A + fixed seed is used here only so this estimate is itself reproducible. + Returns: (estimated_count, minimum_required) """ @@ -2778,7 +2783,13 @@ def _compute_fermat_positions_omny(params: dict[str, Any]) -> tuple[int, int]: if step <= 0: return 0, OmnyFermatScan.MIN_POSITIONS positions = OmnyFermatScan.get_omny_fermat_spiral_pos( - -abs(fovx / 2), abs(fovx / 2), -abs(fovy / 2), abs(fovy / 2), step=step, spiral_type=0 + -abs(fovx / 2), + abs(fovx / 2), + -abs(fovy / 2), + abs(fovy / 2), + step=step, + spiral_type=0, + seed=0, ) return len(positions), OmnyFermatScan.MIN_POSITIONS diff --git a/tests/tests_bec_ipython_client/test_omny_tomo_params_widget_math.py b/tests/tests_bec_ipython_client/test_omny_tomo_params_widget_math.py index ef696f7b..1f084cee 100644 --- a/tests/tests_bec_ipython_client/test_omny_tomo_params_widget_math.py +++ b/tests/tests_bec_ipython_client/test_omny_tomo_params_widget_math.py @@ -138,8 +138,10 @@ def test_compute_fermat_positions_omny_matches_scan_class_below_threshold(): count, min_positions = _compute_fermat_positions_omny(params) assert min_positions == OmnyFermatScan.MIN_POSITIONS assert count < min_positions + # _compute_fermat_positions_omny() pins seed=0 for its own reproducibility -- + # match it here rather than drawing an independent random offset. expected = OmnyFermatScan.get_omny_fermat_spiral_pos( - -1.0, 1.0, -1.0, 1.0, step=2.0, spiral_type=0 + -1.0, 1.0, -1.0, 1.0, step=2.0, spiral_type=0, seed=0 ) assert count == len(expected)