Skip to content

flood: travel_time/flood_depth_vegetation skip mannings_n DataArray validation #1437

@brendancol

Description

@brendancol

Description

travel_time and flood_depth_vegetation accept mannings_n as either a scalar or a DataArray. The scalar path enforces mannings_n > 0, but the DataArray path performs no validation.

A mannings_n DataArray containing zeros, negative values, or NaN/Inf passes through and produces silently wrong output:

  • mannings_n = 0 -> infinite velocity / zero travel time.
  • mannings_n < 0 -> negative travel time.
  • mannings_n = NaN -> NaN propagates.

xrspatial/flood.py:418-423 (travel_time) and xrspatial/flood.py:852-857 (flood_depth_vegetation) are the affected sites.

Expected behavior

When mannings_n is a DataArray, its values are also required to be finite and strictly positive. The check matches the scalar path semantics.

Proposed fix

After accepting n_data = mannings_n.data, lazily eager-check the DataArray:

if not np.all(np.isfinite(mannings_n.values) & (mannings_n.values > 0)):
    raise ValueError("mannings_n DataArray must contain finite, strictly positive values")

For dask-backed inputs, use .values only when the array is small or push the check inside the chunk function. Practical approach: check via (mannings_n > 0) xarray ops without forcing eager compute when possible, but for the public API this validation is acceptable to require materialisation of a small mannings raster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginput-validationInput validation and error messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions