feat(preprocess): add spatially_diverse_sample for representative scan subsets#13
Merged
Merged
Conversation
…n subsets Bucket a 2-D scan's bounding box into a ~sqrt(n_target) grid and pick one random point per occupied cell, so a subset covers the whole scan area instead of clustering (a uniform random sample can clump where coincidental symmetry would mis-score an orientation). Returns sorted indices; optional seeded rng for reproducibility. Extracted from holoptycho/scripts/detect_orientation.py (_spatially_diverse_sample) so the orientation-detection CLI imports it; it's a generic position-sampling utility, not orientation-specific. Tested in tests/test_preprocess.py: all-when-target>=n, sorted/in-range, one-per-occupied-cell, spread-not-cluster (far corners always chosen, dense cluster contributes few), and seeded determinism. 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.
Adds
spatially_diverse_sample(x, y, n_target, rng=None)toptychoml.preprocess.Why
Bucket a 2-D scan's bounding box into a
√n_target × √n_targetgrid and pick one random point per occupied cell, so a subset covers the scan area instead of clustering. (A uniform random sample can clump in one region, where coincidentally symmetric structure could make a wrong orientation score well — this guarantees coverage.) Returns sorted indices; pass a seededrngfor reproducibility.Extracted from holoptycho's
scripts/detect_orientation.py(_spatially_diverse_sample) so the orientation-detection CLI can import it. It's a generic position-sampling utility — not orientation-specific (reusable for normalization sampling, QC, etc.) — pure numpy, no I/O.Tests
tests/test_preprocess.py(+5): returns-all whenn_target ≥ n, sorted/in-range, one-per-occupied-cell, spread-not-cluster (100-point corner cluster + 3 lone far corners → all far corners chosen, cluster contributes ≤ a few), and seeded determinism.First of the H5 PRs (the orientation-detection CLI imports this); the in-pipeline live autodetect and the CLI itself follow in holoptycho.