Description
Planar slope assumes uniform cell spacing even when the input coordinates are irregular, and it does so silently. get_dataarray_resolution (in xrspatial/utils.py) falls back to calc_res, which derives a single resolution from the full coordinate span divided by n - 1:
xres = (xrange[-1] - xrange[0]) / (w - 1)
yres = (yrange[-1] - yrange[0]) / (h - 1)
On an irregular grid that collapses all the varying cell widths into one average value, and the user gets no indication it happened.
Reproduce
Take x = [0, 1, 2, 4, 8] with z = x along that axis. The true physical slope is constant, but slope returns varying values because every cell is treated as if it had the averaged width.
Expected
Either the resolution reflects the actual per-cell spacing, or the user is told the grid is irregular and an averaged resolution is being used. The res attribute already gives an explicit override path, which get_dataarray_resolution honors before it ever reaches calc_res.
Proposed fix
When coordinates are present and not evenly spaced (within a tolerance), warn from calc_res so the averaging is visible, and point users at attrs["res"] for an explicit resolution. Regular grids keep their current behavior with no warning. This mirrors the existing resample validation for irregular coordinates (#2663) and the unit-mismatch warning already in utils.py.
Description
Planar
slopeassumes uniform cell spacing even when the input coordinates are irregular, and it does so silently.get_dataarray_resolution(inxrspatial/utils.py) falls back tocalc_res, which derives a single resolution from the full coordinate span divided byn - 1:On an irregular grid that collapses all the varying cell widths into one average value, and the user gets no indication it happened.
Reproduce
Take
x = [0, 1, 2, 4, 8]withz = xalong that axis. The true physical slope is constant, butslopereturns varying values because every cell is treated as if it had the averaged width.Expected
Either the resolution reflects the actual per-cell spacing, or the user is told the grid is irregular and an averaged resolution is being used. The
resattribute already gives an explicit override path, whichget_dataarray_resolutionhonors before it ever reachescalc_res.Proposed fix
When coordinates are present and not evenly spaced (within a tolerance), warn from
calc_resso the averaging is visible, and point users atattrs["res"]for an explicit resolution. Regular grids keep their current behavior with no warning. This mirrors the existingresamplevalidation for irregular coordinates (#2663) and the unit-mismatch warning already inutils.py.