WIP: Update find_xtal.py post-scan collection position logic (#10) #11

Draft
duan_j wants to merge 1 commits from find-xtal-center-fallback into main
Owner

WIP — not ready to merge.

Closes #10.

What

raster_highest_score now falls back to the geometric grid centre when the
grid is too weak to contain a crystal, instead of collecting at the noisy argmax
cell. So a "nothing in the loop" result is centred and deliberate rather than
data collected on noise.

Guard (grid-wide, OR rule): route to centre when the grid-wide maximum
spots_low_res is below min_low_res_spots or the grid-wide maximum
spots_indexed is below min_spots_indexed (defaults 10.0 and 1, exposed as
tunable parameters).

Returns a CenterOfMassModel at the centre (not None), so both DAQ call sites
work unchanged — the simulated branch (no None check) and the real branch (its
existing None-fallback simply stays dead). No AareDAQ change required.

Single file touched: src/aarecommon/math/find_xtal.py.

Test

uv run python src/aarecommon/math/find_xtal.py prints find_xtal self-check passed
(crystal maps to best cell; all-noise maps to centre; strong-spots-but-unindexed
maps to centre via the OR rule).

Open question (why WIP)

With OR plus min_spots_indexed=1, a grid where nothing indexed anywhere
routes to centre even with strong low-res spots. If that is too aggressive for
crystals that diffract but fail to index, flip the guard to AND (one line).

Generated with Claude Code.

**WIP — not ready to merge.** Closes #10. ## What `raster_highest_score` now falls back to the geometric **grid centre** when the grid is too weak to contain a crystal, instead of collecting at the noisy argmax cell. So a "nothing in the loop" result is centred and deliberate rather than data collected on noise. Guard (grid-wide, **OR** rule): route to centre when the grid-wide maximum spots_low_res is below `min_low_res_spots` **or** the grid-wide maximum spots_indexed is below `min_spots_indexed` (defaults `10.0` and `1`, exposed as tunable parameters). Returns a `CenterOfMassModel` at the centre (not None), so both DAQ call sites work unchanged — the simulated branch (no None check) and the real branch (its existing None-fallback simply stays dead). No AareDAQ change required. Single file touched: `src/aarecommon/math/find_xtal.py`. ## Test `uv run python src/aarecommon/math/find_xtal.py` prints `find_xtal self-check passed` (crystal maps to best cell; all-noise maps to centre; strong-spots-but-unindexed maps to centre via the OR rule). ## Open question (why WIP) With OR plus `min_spots_indexed=1`, a grid where **nothing indexed anywhere** routes to centre even with strong low-res spots. If that is too aggressive for crystals that diffract but fail to index, flip the guard to AND (one line). Generated with Claude Code.
duan_j added 1 commit 2026-07-13 13:19:32 +02:00
WIP: return grid centre when no crystal in raster scan (#10)
CI / lint (push) Failing after 18s
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / lint (pull_request) Failing after 22s
CI / test (3.11) (pull_request) Skipped
CI / test (3.12) (pull_request) Skipped
CI / test (3.13) (pull_request) Skipped
cad77d4cf1
raster_highest_score always returns the argmax cell, which lands on
noise when the loop has no crystal. Add a grid-wide weakness guard:
when max(spots_low_res) < min_low_res_spots OR max(spots_indexed) <
min_spots_indexed, return a CenterOfMassModel at the geometric grid
centre instead of collecting at a noisy cell. Thresholds are tunable
parameters (defaults 10.0 and 1).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Some required checks failed
CI / lint (push) Failing after 18s
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / lint (pull_request) Failing after 22s
CI / test (3.11) (pull_request) Skipped
CI / test (3.12) (pull_request) Skipped
CI / test (3.13) (pull_request) Skipped
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin find-xtal-center-fallback:find-xtal-center-fallback
git checkout find-xtal-center-fallback
Sign in to join this conversation.