Repository navigation
Allocate only the occupied bins of radial profiles - #104
Merged
Merged
Conversation
Since #98, radial profiles bin the pixels in steps of the smallest distance between pixel centers, and get_radial_profile accumulated them with np.bincount on the bin index, which allocates every bin from the center to the largest distance: a tiny spacing (non-uniform coordinates, strongly anisotropic pixels) required arrays of several GB for a few pixels. Coincident pixel centers gave a zero step and an obscure error after divisions by zero. Only the bins holding pixels are now accumulated (np.unique with the inverse index, then np.bincount on it): the memory used never exceeds the size of the image, and the results are bit-identical (same bins, same order of accumulation). A bin width that is not positive and finite, non-finite distances (center or coordinates), and coincident pixel centers are refused with explicit errors; these inputs already failed. The contract of radial_profile is unchanged. Closes #103 Assisted-by: Claude Opus 5.5
PierreRaybaut
force-pushed
the
fix/radial-profile-occupied-bins
branch
from
October 26, 2026 08:28
8d7446d to
c175552
Compare
This was referenced Oct 26, 2026
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.
Closes #103
Summary
Since #98,
radial_profilebins the pixels in steps of the smallest distance between pixel centers, andget_radial_profileaccumulated them withnp.bincounton the bin index, which allocates every bin from the center to the largest distance: with a tiny spacing (non-uniform coordinates[0, 1e-8, 1, 2, 3], ordx = 1e-8), about 5 × 10⁸ bins — several GB — for a few dozen pixels. Coincident pixel centers gave a zero step and an obscure error ('list' argument must have no negative elements) after divisions by zero.get_radial_profile: only the bins holding pixels are accumulated (np.unique(..., return_inverse=True), thennp.bincounton the inverse index): memory proportional to the size of the image, whatever the step; results are bit-identical (same bins, same order of accumulation). A bin width that is not positive and finite, and non-finite distances (center or coordinates), are refused with explicitValueErrors._pixel_spacing: coincident centers of neighboring pixels are refused explicitly (Pixel centers coincide along X ...).radial_profileis unchanged (version 2): results are identical, and only inputs that already failed are refused with a clear message.sphinx_intl update).This PR and #102 both edit the Image profiles in physical coordinates release note: the second one merged will be rebased.
Validation
profile_physical_unit_test.py): bit-identity with the former implementation (reimplemented in the test) on uniform, pixel-centered, anisotropic and non-uniform grids, for float, integer and masked data; tiny spacing: traced memory peak below 10 MB (instead of several GB); explicit refusals (coincident centers, bin widths 0, negative, NaN, inf, non-finite centers).--qualification-report: no problem (radial_profilev2 qualified, validation and replay passed).developagainst this branch:profile_app_test.py,provenance_processing_unit_test.py,interactive_processing_test.pypass (52).