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.
Description
travel_timeandflood_depth_vegetationacceptmannings_nas either a scalar or a DataArray. The scalar path enforcesmannings_n > 0, but the DataArray path performs no validation.A
mannings_nDataArray 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) andxrspatial/flood.py:852-857(flood_depth_vegetation) are the affected sites.Expected behavior
When
mannings_nis 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:For dask-backed inputs, use
.valuesonly 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.