Reason or Problem
Three small API gaps in xrspatial.resample.resample() showed up while auditing API consistency against reproject():
- 3D rasters are rejected.
_validate_raster is called with the default ndim=2, so (band, y, x) inputs raise, even though reproject() accepts the same shape. Multi-band imagery has to be looped manually.
- No
nodata parameter. Integer rasters with sentinel values (e.g. -9999) cannot be resampled correctly without first converting to float and replacing the sentinel with NaN. reproject() already has a nodata keyword and falls back to _FillValue/nodata attrs.
- The
target_resolution docstring is wrong. The code at lines 801-803 already accepts a (res_y, res_x) tuple, but the docstring only documents float.
Proposal
Update resample() to:
- Accept 3D rasters (
band, y, x). Loop over the leading dim and stack the per-band 2D results. Output dims and non-spatial coords match the input.
- Add a
nodata=None keyword. When set, replace input pixels equal to nodata with NaN before resampling. When None, fall back to agg.attrs['_FillValue'], then agg.attrs['nodata']. Output uses NaN as the sentinel regardless.
- Fix the
target_resolution docstring to float or (float, float).
Value
Brings resample() in line with reproject() for multi-band and integer-sentinel inputs. No behavior change for existing 2D float callers.
Reason or Problem
Three small API gaps in
xrspatial.resample.resample()showed up while auditing API consistency againstreproject():_validate_rasteris called with the defaultndim=2, so(band, y, x)inputs raise, even thoughreproject()accepts the same shape. Multi-band imagery has to be looped manually.nodataparameter. Integer rasters with sentinel values (e.g.-9999) cannot be resampled correctly without first converting to float and replacing the sentinel with NaN.reproject()already has anodatakeyword and falls back to_FillValue/nodataattrs.target_resolutiondocstring is wrong. The code at lines 801-803 already accepts a(res_y, res_x)tuple, but the docstring only documentsfloat.Proposal
Update
resample()to:band, y, x). Loop over the leading dim and stack the per-band 2D results. Output dims and non-spatial coords match the input.nodata=Nonekeyword. When set, replace input pixels equal tonodatawith NaN before resampling. When None, fall back toagg.attrs['_FillValue'], thenagg.attrs['nodata']. Output uses NaN as the sentinel regardless.target_resolutiondocstring tofloat or (float, float).Value
Brings
resample()in line withreproject()for multi-band and integer-sentinel inputs. No behavior change for existing 2D float callers.