Refresh transform and nodata attrs on resample output#1472
Merged
brendancol merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
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.
This was referenced May 5, 2026
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.
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_coordsnow 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, afterscale_factor=0.5, producestransform=(2.0, 0.0, 100.0, 0.0, -2.0, 200.0)transformstays absent_FillValue=-9999becomes NaN on output_FillValuestays absentnodatavals=(-9999,)becomes(nan,)crs,crs_wkt,units,long_name,scales,offsets) round-trip unchangedTest plan
pytest xrspatial/tests/test_resample.py -x(68 passed)