feat(scripts): add detect_orientation.py — offline dp_orient auto-detection#44
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
H5a of the #37 decomposition — the standalone orientation-detection tool. (H5b, the in-pipeline live autodetect, follows.)
What
scripts/detect_orientation.pyreads a recorded scan HDF5 + the model's TRT engine, sweeps all 8 D4 candidates viaptychoml.autodetect_orientation(forward-physics scoring against the engine's baked probe), and writes a JSON snippet with the winningdp_orientto merge into the scan config.Only
dp_orientis auto-detected —patch_flip,x/y_direction,position_swap_xyaren'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.pycovers_read_positions:2×N,N×2, ambiguous2×2→(2,N)convention, and 1-D / bad-shape rejection. The full CLI needs a TRT engine (runs in real model loads);--helpworks without one since the ptychoml import is lazy.Depends on
NSLS2/ptychoml#13 (merged);
pixi.lockbumped.