Skip to content

Planar slope silently averages resolution on irregular coordinates #2766

@brendancol

Description

@brendancol

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginput-validationInput validation and error messages

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions