Skip to content

feat(scripts): add detect_orientation.py — offline dp_orient auto-detection#44

Merged
Garrett Bischof (gwbischof) merged 1 commit into
mainfrom
h5a/detect-orientation-cli
Jun 9, 2026
Merged

feat(scripts): add detect_orientation.py — offline dp_orient auto-detection#44
Garrett Bischof (gwbischof) merged 1 commit into
mainfrom
h5a/detect-orientation-cli

Conversation

@gwbischof

Copy link
Copy Markdown
Collaborator

H5a of the #37 decomposition — the standalone orientation-detection tool. (H5b, the in-pipeline live autodetect, follows.)

What

scripts/detect_orientation.py reads a recorded scan HDF5 + the model's TRT engine, sweeps all 8 D4 candidates via ptychoml.autodetect_orientation (forward-physics scoring against the engine's baked probe), and writes a JSON snippet with the winning dp_orient to merge into the scan config.

Only dp_orient is auto-detected — patch_flip, x/y_direction, position_swap_xy aren't constrained by forward physics, so they stay manual operator preferences (documented in the script + AGENTS.md).

ptychoml reuse

Frame selection uses ptychoml.spatially_diverse_sample (just merged, #13) instead of an inline copy; the orientation sweep + normalization are ptychoml's. The only script-local logic is _read_positions (HDF5 (2,N)/(N,2) shape handling) and the argparse/JSON glue.

Tests

tests/test_detect_orientation.py covers _read_positions: 2×N, N×2, ambiguous 2×2(2,N) convention, and 1-D / bad-shape rejection. The full CLI needs a TRT engine (runs in real model loads); --help works without one since the ptychoml import is lazy.

pixi run test   # 90 passed; the 2 vit_inference/ptycho_holo smoke failures are pre-existing.

Depends on

NSLS2/ptychoml#13 (merged); pixi.lock bumped.

…ection

Standalone CLI that reads a recorded scan HDF5 + the model's TRT engine,
sweeps all 8 D4 candidates via ptychoml.autodetect_orientation (forward-physics
scoring against the engine's baked probe), and writes a JSON snippet with the
winning dp_orient to merge into the scan config. The other orientation knobs
(patch_flip, x/y_direction, position_swap_xy) aren't auto-detected — forward
physics doesn't constrain them — so they stay manual operator preferences.

Frame selection uses ptychoml.spatially_diverse_sample (just merged); the only
script-local logic is _read_positions (HDF5 (2,N)/(N,2) shape handling) and the
argparse/JSON glue. The orientation sweep + sampling live in ptychoml.

tests/test_detect_orientation.py covers _read_positions (2xN, Nx2, ambiguous
2x2 -> 2xN convention, 1-D and bad-shape rejection). The full CLI needs a TRT
engine; --help runs without one (ptychoml import is lazy).

H5a of the #37 decomposition (the in-pipeline live autodetect
is H5b).

Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
@gwbischof Garrett Bischof (gwbischof) merged commit dfec9e3 into main Jun 9, 2026
5 checks passed
@gwbischof Garrett Bischof (gwbischof) deleted the h5a/detect-orientation-cli branch June 9, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant