Fix resample interpolation coordinate mapping (#1202)#1204
Merged
brendancol merged 1 commit intomasterfrom Apr 15, 2026
Merged
Conversation
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.
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.
Summary
resample()usedscipy.ndimage.zoom's edge-aligned coordinate formula, which doesn'tmatch the block-centered output coordinates produced by
_new_coords.This caused a systematic half-pixel spatial shift at the raster edges.
scipy.ndimage.zoomwithmap_coordinatesusing theblock-centered formula
(o + 0.5) * (N_in / N_out) - 0.5across allfour backend paths (numpy, cupy, dask+numpy, dask+cupy).
the output coordinate labels.
Closes #1202
Test plan