Description
Three metadata gaps in xrspatial/resample.py found by the metadata propagation audit. These are the same issues PR #1462 fixed in xrspatial/reproject.
The end of resample() carries input attrs forward and overwrites res, but three other attrs stay stale:
-
transform describes the old grid. If the input had a rasterio 6-tuple transform, the output keeps the input value even though the cell size and origin have changed. Downstream code reading transform instead of res gets the wrong affine.
-
_FillValue keeps the input sentinel. Resample currently outputs float32 with NaN as the missing-data sentinel. If the input had _FillValue=-9999, the output still claims -9999 when no -9999 exists in the data: the missing pixels are NaN.
-
nodatavals (the rasterio plural form) keeps the same stale sentinel for the same reason.
Other attrs (crs, crs_wkt, scales, offsets, units, long_name) are correct unchanged because resample does not change CRS, datatype scaling, or units.
Proposal
At the end of resample():
- If
'transform' in agg.attrs, emit a fresh rasterio 6-tuple (res_x, 0.0, left, 0.0, -res_y, top) computed from the new edge coordinates.
- If
'_FillValue' in agg.attrs, set _FillValue = float('nan') to match the actual sentinel in the output.
- If
'nodatavals' in agg.attrs, replace each entry with NaN.
Don't fabricate attrs that weren't on the input. Same gating approach as PR #1462.
Tests
- 4x4 raster with
transform=(1.0, 0.0, 100.0, 0.0, -1.0, 200.0), scale_factor=0.5 produces output transform == (2.0, 0.0, 100.0, 0.0, -2.0, 200.0).
_FillValue=-9999 on input produces output _FillValue of NaN.
nodatavals=(-9999,) on input produces nodatavals=(nan,).
- Absent
transform/_FillValue stays absent.
References
Description
Three metadata gaps in
xrspatial/resample.pyfound by the metadata propagation audit. These are the same issues PR #1462 fixed inxrspatial/reproject.The end of
resample()carries input attrs forward and overwritesres, but three other attrs stay stale:transformdescribes the old grid. If the input had a rasterio 6-tupletransform, the output keeps the input value even though the cell size and origin have changed. Downstream code readingtransforminstead ofresgets the wrong affine._FillValuekeeps the input sentinel. Resample currently outputs float32 with NaN as the missing-data sentinel. If the input had_FillValue=-9999, the output still claims-9999when no-9999exists in the data: the missing pixels are NaN.nodatavals(the rasterio plural form) keeps the same stale sentinel for the same reason.Other attrs (
crs,crs_wkt,scales,offsets,units,long_name) are correct unchanged because resample does not change CRS, datatype scaling, or units.Proposal
At the end of
resample():'transform' in agg.attrs, emit a fresh rasterio 6-tuple(res_x, 0.0, left, 0.0, -res_y, top)computed from the new edge coordinates.'_FillValue' in agg.attrs, set_FillValue = float('nan')to match the actual sentinel in the output.'nodatavals' in agg.attrs, replace each entry with NaN.Don't fabricate attrs that weren't on the input. Same gating approach as PR #1462.
Tests
transform=(1.0, 0.0, 100.0, 0.0, -1.0, 200.0),scale_factor=0.5produces outputtransform == (2.0, 0.0, 100.0, 0.0, -2.0, 200.0)._FillValue=-9999on input produces output_FillValueof NaN.nodatavals=(-9999,)on input producesnodatavals=(nan,).transform/_FillValuestays absent.References
reproject()andmerge().