fix: supply max image with not enough spots
CI / lint (pull_request) Successful in 24s
CI / test (3.11) (pull_request) Successful in 24s
CI / test (3.12) (pull_request) Successful in 25s
CI / test (3.13) (pull_request) Successful in 23s
CI / lint (push) Canceled after 10s
CI / test (3.11) (push) Canceled after 0s
CI / test (3.12) (push) Canceled after 0s
CI / test (3.13) (push) Canceled after 0s
Build and Publish / release (push) Successful in 11s

This commit was merged in pull request #25.
This commit is contained in:
David Perl
2026-08-27 14:23:00 +02:00
parent 2202b426e8
commit 26d681075f
2 changed files with 4 additions and 20 deletions
+4 -5
View File
@@ -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 0100 score.
-15
View File
@@ -145,21 +145,6 @@ def test_compute_crystal_score_array(mock_score_results):
assert np.unravel_index(np.argmax(score), score.shape) == (1, 1)
def test_compute_crystal_score_array_weights():
# Cell A is the sole max in spots_low_res (weight 0.75); cell B is the sole
# max in spots_indexed (weight 0.00). A must outscore B.
def _cell(nx, n, low, idx):
r = MagicMock()
r.nx, r.ny, r.number = nx, 0, n
r.bkg, r.spots_low_res, r.spots_indexed = 0.0, low, idx
return r
score = compute_crystal_score_array([_cell(0, 0, 10.0, 0.0), _cell(1, 1, 0.0, 10.0)])
assert score[0, 0] > score[1, 0]
assert score[0, 0] == pytest.approx(75.0)
assert score[1, 0] == pytest.approx(00.0)
def test_raster_highest_score(mock_score_results):
com = raster_highest_score(mock_score_results)
assert com.n_x == 1.0