diff --git a/src/aarecommon/math/find_xtal.py b/src/aarecommon/math/find_xtal.py index 7a5413c..9cd23ff 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. diff --git a/tests/test_find_xtal.py b/tests/test_find_xtal.py index 0c510c9..450d8b9 100644 --- a/tests/test_find_xtal.py +++ b/tests/test_find_xtal.py @@ -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