Skip to content

Refresh transform and nodata attrs on resample output#1472

Merged
brendancol merged 1 commit intomainfrom
issue-1465
May 4, 2026
Merged

Refresh transform and nodata attrs on resample output#1472
brendancol merged 1 commit intomainfrom
issue-1465

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1465.

Follow-up to #1462 covering the same three metadata items in xrspatial/resample.py.

Changes

At the end of resample(), refresh three attrs that the prior code carried forward unchanged from the input:

  • transform. Re-emit the rasterio 6-tuple (res_x, 0.0, left, 0.0, -res_y, top) from the new edge coordinates. _new_coords now returns the edge values it already computed internally so the caller can use them. The new transform is only emitted when the input had one.
  • _FillValue. Resample currently outputs float32 with NaN as the missing-data sentinel. If the input declared _FillValue=-9999, we now overwrite it with NaN so the metadata matches the data. Gated on '_FillValue' in agg.attrs.
  • nodatavals. Same treatment for the rasterio plural form: each entry is replaced with NaN when the input had the key.

Other attrs (crs, crs_wkt, scales, offsets, units, long_name) are correct unchanged because resample does not touch CRS, dtype scaling, or units.

Tests

Added six tests in TestMetadataPropagation:

  • transform=(1.0, 0.0, 100.0, 0.0, -1.0, 200.0) on a 4x4 raster, after scale_factor=0.5, produces transform=(2.0, 0.0, 100.0, 0.0, -2.0, 200.0)
  • absent transform stays absent
  • _FillValue=-9999 becomes NaN on output
  • absent _FillValue stays absent
  • nodatavals=(-9999,) becomes (nan,)
  • other attrs (crs, crs_wkt, units, long_name, scales, offsets) round-trip unchanged

Test plan

  • pytest xrspatial/tests/test_resample.py -x (68 passed)

At the end of resample(), refresh three attrs that the prior code
carried forward unchanged from the input:

- transform: re-emit the rasterio 6-tuple (res_x, 0.0, left, 0.0,
  -res_y, top) from the new edge coordinates. _new_coords now returns
  the edge values it already computed so the caller can use them.
  Gated on 'transform' in agg.attrs.
- _FillValue: resample outputs float32 with NaN as the missing-data
  sentinel; replace the input value with NaN so metadata matches the
  data. Gated on '_FillValue' in agg.attrs.
- nodatavals: same treatment for the rasterio plural form.

Other attrs (crs, crs_wkt, scales, offsets, units, long_name) round
trip unchanged because resample does not touch CRS, dtype scaling, or
units.

Six new tests in TestMetadataPropagation cover refresh, absence, and
preservation of unrelated attrs.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 4, 2026
@brendancol brendancol merged commit 1dd1223 into main May 4, 2026
11 checks passed
@brendancol brendancol deleted the issue-1465 branch May 5, 2026 03:45
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.

Refresh transform and nodata attrs on resample output

1 participant