Skip to content

Refresh transform and nodata attrs on resample output #1465

@brendancol

Description

@brendancol

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:

  1. 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.

  2. _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.

  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI design and consistencyenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions