Skip to content

Fix resample interpolation coordinate mapping (#1202)#1204

Merged
brendancol merged 1 commit into
masterfrom
issue-1202
Apr 15, 2026
Merged

Fix resample interpolation coordinate mapping (#1202)#1204
brendancol merged 1 commit into
masterfrom
issue-1202

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Interpolation methods (nearest, bilinear, cubic) in resample() used
    scipy.ndimage.zoom's edge-aligned coordinate formula, which doesn't
    match the block-centered output coordinates produced by _new_coords.
    This caused a systematic half-pixel spatial shift at the raster edges.
  • Replaced scipy.ndimage.zoom with map_coordinates using the
    block-centered formula (o + 0.5) * (N_in / N_out) - 0.5 across all
    four backend paths (numpy, cupy, dask+numpy, dask+cupy).
  • Added tests that verify interpolated values on a linear gradient match
    the output coordinate labels.

Closes #1202

Test plan

  • All 56 existing + new resample tests pass
  • Dask parity tests pass (numpy vs dask+numpy produce identical results)
  • CuPy parity tests pass
  • Linear gradient reproducer from the issue now produces correct values

The interpolation path used scipy.ndimage.zoom's edge-aligned formula
which maps output pixel o to input pixel o*(N_in-1)/(N_out-1). This
pinned the first output pixel to the first input pixel and the last
to the last, creating a systematic half-pixel spatial shift vs. the
block-centered output coordinate metadata.

Switch all four backend paths (numpy, cupy, dask+numpy, dask+cupy)
to use map_coordinates with the block-centered formula:
  input_pixel = (out_pixel + 0.5) * (N_in / N_out) - 0.5

This brings the interpolation path into alignment with both the
aggregation path and the output coordinate labels.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 15, 2026
@brendancol brendancol merged commit dc3379f into master Apr 15, 2026
11 checks passed
@brendancol brendancol deleted the issue-1202 branch May 4, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resample interpolation uses edge-aligned coordinates instead of block-centered

1 participant