fix: construct resample transform from exact target cell size - #440
Merged
nathanjmcdougall merged 1 commit intoMay 5, 2026
Conversation
Raster.resample() now produces output cells with the exact requested cell size, fixing drift that caused downstream NonSquareCellsError. Background: - The original implementation (63355c4, 2025-08-13) computed the output transform via dataset.transform.scale(width/new_width, height/new_height), which introduces rounding error when np.ceil rounds the array dimensions. This was masked by a stored cell_size field on RasterMeta that acted as the source of truth regardless of what the transform said. - In aa699db (2026-02-18), cell_size was refactored from a stored field to a derived property (abs(transform.a)), but the transform computation was left unchanged. The compensating mechanism was removed without fixing the underlying calculation, exposing the drift. - Existing tests never caught this because their fixtures use dimensions (4x4, 2x2) and ratios (x2, /2) where ceil produces exact integers. Fix: construct the Affine transform directly from the target cell size, preserving the original origin. The ceil-rounded array dimensions still ensure full extent coverage, but the metadata is now truthful. Closes #438
b-j-karl
approved these changes
May 5, 2026
|
nathanjmcdougall
deleted the
438-resample-output-cell-size-drifts-from-requested-value-due-to-ceil-rounding
branch
May 5, 2026 00:22
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.

0 New Issues
0 Fixed Issues
0 Accepted Issues
Raster.resample() now produces output cells with the exact requested cell size, fixing drift that caused downstream NonSquareCellsError.
Background:
Fix: construct the Affine transform directly from the target cell size, preserving the original origin. The ceil-rounded array dimensions still ensure full extent coverage, but the metadata is now truthful.
Closes #438