Skip to content

planar aspect() does not warn on degree/meter unit mismatch like slope() does #2839

@brendancol

Description

@brendancol

Description

aspect() with the default method='planar' silently produces wrong results when given a lat/lon raster (coordinates in degrees) with elevation values in meters. The planar path in xrspatial/aspect.py calls get_dataarray_resolution(agg) directly, without first checking whether the horizontal units (degrees) match the vertical units (meters).

slope() already guards against this. Its planar path calls warn_if_unit_mismatch(agg) before computing resolution, so the user gets a UserWarning when degrees and meters are mixed. Aspect divides elevation differences by cell size the same way slope does, so it has the same problem, just without the warning.

Expected behavior

Aspect's planar path should call the same warn_if_unit_mismatch() helper that slope uses, before computing resolution, so users get warned when horizontal units don't match vertical units.

Steps to reproduce

Call aspect() on a DataArray with degree-based lat/lon coordinates and meter elevation values. slope() warns; aspect() does not.

Scope

One-line behavior fix plus a test. It reuses slope's existing helper and import. The other aspect findings (dask memory guard, name leak, z_unit error message) are tracked separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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