From b5a163b6af6aca5150e4ef59fd6e50be59c8774d Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 27 Aug 2026 13:40:11 +0200 Subject: [PATCH] fix: supply max image with not enough spots --- src/aarecommon/math/find_xtal.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/aarecommon/math/find_xtal.py b/src/aarecommon/math/find_xtal.py index 7a5413c..5f5ec19 100644 --- a/src/aarecommon/math/find_xtal.py +++ b/src/aarecommon/math/find_xtal.py @@ -326,9 +326,6 @@ def raster_highest_score(images, min_low_res_spots: float = 10.0) -> CenterOfMas collecting at a noisy cell, so a 'nothing here' result is centred and deliberate rather than random noise. - spots_indexed is deliberately not part of the guard: indexing was dropped - from the crystal score (w_indexed=0.00), so a crystal that diffracts but - fails to index must still be targeted, not routed to centre. """ score_array = compute_crystal_score_array(images) max_low_res = max((getattr(img, "spots_low_res", 0) or 0 for img in images), default=0) @@ -340,7 +337,9 @@ def raster_highest_score(images, min_low_res_spots: float = 10.0) -> CenterOfMas ) # get_com_mm maps index i -> (i+0.5)*step, so index (N-1)/2 is the true # geometric centre of the grid for both odd and even N (and N==1). - return CenterOfMassModel(n_x=(n_nx - 1) / 2.0, n_y=(n_ny - 1) / 2.0) + y_pos = (n_ny - 1) / 2.0 + x_pos = (n_nx - 1) / 2.0 + return CenterOfMassModel(n_x=x_pos, n_y=y_pos, max_image=int(y_pos*n_nx+x_pos)) return _to_com_model(_max_cell(score_array), images, "Highest score") @@ -360,7 +359,7 @@ def has_sufficient_low_res_spots(result_array: np.ndarray, min_spots_low_res: fl def compute_crystal_score_array( - scan_results: list, w_bkg: float = 0.25, w_low_res: float = 0.75, w_indexed: float = 0.00 + scan_results: list, w_bkg: float = 0.01, w_low_res: float = 0.99, w_indexed: float = 0.00 ) -> np.ndarray: """Combine bkg (25%), spots_low_res (75%), and spots_indexed (00%) into a 0–100 score.