Skip to content

Allocate only the occupied bins of radial profiles - #104

Merged
PierreRaybaut merged 1 commit into
developfrom
fix/radial-profile-occupied-bins
Oct 26, 2026
Merged

PierreRaybaut merged 1 commit into
developfrom
fix/radial-profile-occupied-bins

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Contributor

Closes #103

Summary

Since #98, radial_profile bins 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: with a tiny spacing (non-uniform coordinates [0, 1e-8, 1, 2, 3], or dx = 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), then np.bincount on 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 explicit ValueErrors.
  • _pixel_spacing: coincident centers of neighboring pixels are refused explicitly (Pixel centers coincide along X ...).
  • The contract of radial_profile is unchanged (version 2): results are identical, and only inputs that already failed are refused with a clear message.
  • Release note: radial profiles are refused when pixel centers coincide (French translation updated, checked with a gettext build + 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

  • New tests (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).
  • Full suite: 2340 passed; --qualification-report: no problem (radial_profile v2 qualified, validation and replay passed).
  • DataLab develop against this branch: profile_app_test.py, provenance_processing_unit_test.py, interactive_processing_test.py pass (52).

@PierreRaybaut PierreRaybaut added the bug Something isn't working label Oct 26, 2026
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
PierreRaybaut force-pushed the fix/radial-profile-occupied-bins branch from 8d7446d to c175552 Compare October 26, 2026 08:28
@PierreRaybaut
PierreRaybaut merged commit 83900fc into develop Oct 26, 2026
6 checks passed
@PierreRaybaut
PierreRaybaut deleted the fix/radial-profile-occupied-bins branch October 26, 2026 08:33
@ThomasMalletCodra ThomasMalletCodra added this to the v1.4.0 milestone Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants