xrspatial.diagnostics.diagnose#

xrspatial.diagnostics.diagnose(agg: DataArray, tool: str | None = None) DiagnosticReport[source]#

Diagnose a DataArray for common xarray-spatial pitfalls.

Runs a series of heuristic checks to identify potential issues that could lead to incorrect results when using xarray-spatial functions.

Parameters:
  • agg (xr.DataArray) – The input DataArray to diagnose.

  • tool (str, optional) – Name of the xarray-spatial tool you intend to use (e.g., ‘slope’, ‘aspect’, ‘curvature’). When specified, only diagnostics relevant to that tool are run. If None, all diagnostics are run.

Returns:

A report containing any issues found, along with inferred metadata about the DataArray.

Return type:

DiagnosticReport

Examples

>>> import xarray as xr
>>> import numpy as np
>>> from xrspatial.diagnostics import diagnose
>>> # Create a DataArray with lon/lat coordinates but meter elevations
>>> data = np.random.rand(100, 100) * 1000 + 500
>>> da = xr.DataArray(
...     data,
...     dims=['y', 'x'],
...     coords={
...         'y': np.linspace(40.0, 41.0, 100),
...         'x': np.linspace(-105.0, -104.0, 100),
...     }
... )
>>> report = diagnose(da)
>>> print(report)
[WARNING] UNIT_MISMATCH: Input DataArray appears to have coordinates...
>>> if report.has_warnings:
...     print("Consider reprojecting your data!")