Description
resample assumes a regular, monotonic raster but does not check for it. When the input has irregular spatial coordinates, the function computes inconsistent output geometry.
target_resolution derives input resolution from calc_res() (xrspatial/utils.py:427), which uses (max - min) / (n - 1) across the full extent. The output coordinates are then built from first/last neighbour spacing in _new_coords (xrspatial/resample.py:1460). On an irregular grid these two notions of "resolution" disagree, so the output width and coordinate range no longer match the input center range.
To Reproduce
import numpy as np, xarray as xr
from xrspatial.resample import resample
data = np.arange(9, dtype=float).reshape(3, 3)
agg = xr.DataArray(data, dims=['y', 'x'], coords={'y': [0, 1, 4], 'x': [0, 1, 4]})
out = resample(agg, target_resolution=1.0)
print(out.shape) # (6, 6) -- expected (5, 5)
print(out.x.values) # [0. 1. 2. 3. 4. 5.] -- expands past the input range [0, 4]
With x = [0, 1, 4] and target_resolution=1.0, the output width is 6 and the x coords run [0, 1, 2, 3, 4, 5], expanding beyond the input center range.
Expected behavior
The module only supports regular monotonic rasters. It should validate the spatial coordinates up front and raise a clear ValueError for irregular or non-monotonic coordinates, instead of silently producing inconsistent output geometry.
Severity
Medium/High -- silently wrong output geometry with no error.
Description
resampleassumes a regular, monotonic raster but does not check for it. When the input has irregular spatial coordinates, the function computes inconsistent output geometry.target_resolutionderives input resolution fromcalc_res()(xrspatial/utils.py:427), which uses(max - min) / (n - 1)across the full extent. The output coordinates are then built from first/last neighbour spacing in_new_coords(xrspatial/resample.py:1460). On an irregular grid these two notions of "resolution" disagree, so the output width and coordinate range no longer match the input center range.To Reproduce
With
x = [0, 1, 4]andtarget_resolution=1.0, the output width is 6 and the x coords run[0, 1, 2, 3, 4, 5], expanding beyond the input center range.Expected behavior
The module only supports regular monotonic rasters. It should validate the spatial coordinates up front and raise a clear
ValueErrorfor irregular or non-monotonic coordinates, instead of silently producing inconsistent output geometry.Severity
Medium/High -- silently wrong output geometry with no error.