flood: make mannings_n DataArray validation lazy-safe (#3503)#3507
Merged
Conversation
_validate_mannings_n_dataarray called np.asarray(mannings_n.values), which materializes the whole roughness raster into host memory: a full graph compute for dask and a full device->host copy for cupy. This ran during validation, before any lazy graph was built, so a large mannings_n raster OOMed the client and defeated lazy evaluation in travel_time() and flood_depth_vegetation(). Validate without .values: - dask-backed: skip the eager value check (cannot inspect values without computing the graph); invalid roughness surfaces as inf/NaN on the lazy path, same as before for non-DataArray inputs. - cupy-backed: reduce on device (cp.isfinite / >0 .all()), transferring only a scalar bool. - numpy: unchanged. Adds regression tests asserting a tripwired dask mannings_n is not materialized during travel_time/flood_depth_vegetation validation.
…e-flood-2026-06-25-01 # Conflicts: # xrspatial/tests/test_flood.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3503.
Problem
_validate_mannings_n_dataarrayinxrspatial/flood.pyvalidated the roughness raster vianp.asarray(mannings_n.values)..valuesmaterializes the whole array into host memory: a full graph compute for dask, a full device-to-host copy for cupy. This happened during validation, before the lazy result graph was built, so a largemannings_nraster OOMed the client and defeated lazy evaluation intravel_time()andflood_depth_vegetation().A 2048x2048 dask
mannings_n(chunks 512) with a per-block tripwire showed all 16 chunks computed during thetravel_time(...)call alone, before any result graph existed.Fix
Validate without
.values:cp.isfinite(data).all(),(data > 0).all()), transferring only a scalar bool instead of the whole array.Tests
mannings_nis not materialized duringtravel_time/flood_depth_vegetationvalidation.Performance context
.values).