Skip to content

Support 3D rasters, expose nodata, document target_resolution tuple in resample #1466

@brendancol

Description

@brendancol

Reason or Problem

Three small API gaps in xrspatial.resample.resample() showed up while auditing API consistency against reproject():

  1. 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.
  2. 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.
  3. 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:

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

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