Skip to content

Radial profiles may allocate huge arrays with tiny pixel spacings #103

Closed

Description

@PierreRaybaut

Problem

Since #93 (#98), radial_profile bins the pixels by their distance to the center in steps equal to the smallest distance between neighboring pixel centers (_pixel_spacing), and get_radial_profile accumulates them with np.bincount on the bin index. np.bincount allocates one entry per possible bin, from 0 to the largest one, whether it holds pixels or not:

  • with a tiny spacing (non-uniform coordinates such as [0, 1e-8, 1, 2, 3], or strongly anisotropic pixels such as dx = 1e-8, dy = 1), a radius of about 5 gives about 5 × 10⁸ bins: two arrays of several GB for a few dozen pixels, and possibly the exhaustion of the available memory;
  • pixel centers that coincide (duplicated coordinates, accepted by ImageObj.set_coords) give a zero step: the computation fails with an obscure error ('list' argument must have no negative elements, after divisions by zero).

The bins holding no pixel are already left out of the profile, so that allocating them is useless.

Proposal

  • get_radial_profile: accumulate only the bins holding pixels (np.unique(..., return_inverse=True), then np.bincount on the inverse index): memory proportional to the number of pixels, whatever the step, with bit-identical results (same bins, same order of accumulation); a step that is not positive and finite, or a center that is not finite, is refused with an explicit ValueError;
  • _pixel_spacing: pixel centers that coincide along an axis are refused with an explicit ValueError (these inputs already failed);
  • the contract of radial_profile is unchanged (version 2): results are identical, and only inputs that already failed are refused with a clear message.

Tests: bit-identity with the former implementation on uniform, anisotropic and non-uniform images, bounded memory with a tiny spacing, explicit refusals.

Reported by an independent review of Sigima 1.4 (unreleased).

Activity

  1. added a commit that references this issue on Oct 26, 2026
    c175552
  2. PierreRaybaut commented on Oct 26, 2026

    @PierreRaybaut
    ContributorAuthor

    Fixed by #104 (merged into develop).

  3. added this to the v1.4.0 milestone on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions