Skip to content

fix: construct resample transform from exact target cell size - #440

Merged
nathanjmcdougall merged 1 commit into
developfrom
438-resample-output-cell-size-drifts-from-requested-value-due-to-ceil-rounding
May 5, 2026
Merged

fix: construct resample transform from exact target cell size#440
nathanjmcdougall merged 1 commit into
developfrom
438-resample-output-cell-size-drifts-from-requested-value-due-to-ceil-rounding

Conversation

@nathanjmcdougall

Copy link
Copy Markdown
Contributor

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

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
@t-t-sonarqube

t-t-sonarqube Bot commented May 5, 2026

Copy link
Copy Markdown

@nathanjmcdougall
nathanjmcdougall merged commit bef6992 into develop May 5, 2026
15 checks passed
@nathanjmcdougall
nathanjmcdougall deleted the 438-resample-output-cell-size-drifts-from-requested-value-due-to-ceil-rounding branch May 5, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resample: output cell size drifts from requested value due to ceil rounding

2 participants