Skip to content

Enhance image processing and orientation detection in holoptycho#37

Draft
Himanshu Goel (himanshugoel2797) wants to merge 3 commits into
NSLS2:mainfrom
himanshugoel2797:main
Draft

Enhance image processing and orientation detection in holoptycho#37
Himanshu Goel (himanshugoel2797) wants to merge 3 commits into
NSLS2:mainfrom
himanshugoel2797:main

Conversation

@himanshugoel2797

Copy link
Copy Markdown
Contributor
  • Updated ImagePreprocessorOp to include configurable geometry and normalization parameters for output branches.
  • Introduced auto-detection of dp_orient in the new detect_orientation.py script.
  • Modified PtychoApp to support new orientation parameters and normalization settings.
  • Improved handling of patch flipping in SaveViTResult for better output consistency.

Very preliminary developments.

- Updated ImagePreprocessorOp to include configurable geometry and normalization parameters for output branches.
- Introduced auto-detection of dp_orient in the new detect_orientation.py script.
- Modified PtychoApp to support new orientation parameters and normalization settings.
- Improved handling of patch flipping in SaveViTResult for better output consistency.
- Added h5py dependency to pixi.toml for HDF5 file handling.
- Introduced `dump_scan_h5.py` script to export Tiled scans to HDF5 format, including preprocessing steps and metadata attributes.
- Updated `config_from_tiled.py` to auto-detect `panda_upsample` and `vit_normalization`, enhancing scan configuration.
- Enhanced argument parsing in `replay_from_tiled.py` to allow configuration of parallel fetch workers for improved performance.
- Improved error handling during frame fetching to retry on transient HTTP timeouts.
- Adjusted default number of workers for tiled fetches to optimize throughput and prevent connection timeouts.
@himanshugoel2797 Himanshu Goel (himanshugoel2797) marked this pull request as ready for review June 1, 2026 20:05
Garrett Bischof (gwbischof) added a commit to NSLS2/ptychoml that referenced this pull request Jun 5, 2026
Move the generic ViT patch-placement algorithms out of
holoptycho/mosaic_stitch.py into a new ptychoml.stitch module so they can
be shared instead of duplicated. Three placement strategies:

- place_patches_fourier_shift / stitch_batch_into: sub-pixel Fourier-shift
- stitch_batch_livestitch_into: nearest-integer + touched bounding box
- stitch_batch_nearest: plain nearest-integer, edge-clamped

Pure numpy + scipy.fft; depends only on fourier_shift from preprocess.
Exported via __init__ __all__, covered by tests/test_stitch.py (12 cases:
placement, accumulation, counts footprint, livestitch bbox, edge clamping,
up-down flip, fourier-vs-nearest parity, per-batch associativity), and
documented in README + AGENTS.md.

First step of breaking NSLS2/holoptycho#37 into focused PRs: holoptycho
will re-export these under their original names (zero behavior change).

Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
Garrett Bischof (gwbischof) added a commit that referenced this pull request Jun 8, 2026
ptychoml renamed PtychoViTInference's 'data_is_shifted' parameter to
'fftshift' (None = auto-detect DC via detect_dc_at_corner). holoptycho main
still called PtychoViTInference(data_is_shifted=...), which raises TypeError
against the pinned ptychoml (the bump in #38 crossed the rename) — the ViT op
would crash on its first batch. Smoke tests missed it: the vit_inference
import dies earlier on TILED_BASE_URL, and CI envs skip holoscan entirely.

Rename PtychoViTInferenceOp's param data_is_shifted -> fftshift and pass
fftshift= to the session; drop data_is_shifted=True in ptycho_holo.py and let
it default to None (auto-detect), matching PR #37's end-to-end DC handling
that pairs with this PR's preprocess_diffraction(fftshift=fftshift_dp=None).

Adds tests/test_vit_session_contract.py to pin the holoptycho<->ptychoml call
contract so a future rename fails in CI instead of on the beamline.

Co-authored-by: Himanshu Goel <4122621+himanshugoel2797@users.noreply.github.com>
@gwbischof Garrett Bischof (gwbischof) marked this pull request as draft June 9, 2026 17:27
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