Fixes #733: add cost_distance() for weighted proximity#859
Open
brendancol wants to merge 3 commits intomasterfrom
Open
Fixes #733: add cost_distance() for weighted proximity#859brendancol wants to merge 3 commits intomasterfrom
brendancol wants to merge 3 commits intomasterfrom
Conversation
…ce Dijkstra New cost_distance() function computes minimum accumulated traversal cost through a friction surface to reach the nearest target pixel, the raster equivalent of GRASS r.cost / ArcGIS Cost Distance. Supports numpy and dask+numpy backends, 4/8-connectivity, max_cost truncation for dask scalability, and xr.Dataset input via @supports_dataset. Includes 19 tests and an example notebook comparing cost_distance with proximity.
4 tasks
…rechunk The existing dask proximity path rechunked the entire raster into one chunk when max_distance was unbounded, defeating dask's out-of-core purpose. This adds a two-phase scipy.spatial.cKDTree approach: Phase 1 streams chunks to collect target coordinates, Phase 2 queries the tree per-chunk via map_blocks. Exact results, memory proportional to targets not raster size. Supports EUCLIDEAN and MANHATTAN metrics; GREAT_CIRCLE/ALLOCATION/DIRECTION fall back to the existing single-chunk path. Gracefully degrades when scipy is absent.
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.
Summary
cost_distance()function that computes minimum accumulated traversal cost through a friction surface to reach the nearest target pixel (raster equivalent of GRASSr.cost/ ArcGIS Cost Distance)max_costtruncation for dask scalability,target_valuesfiltering, andxr.Datasetinput via@supports_datasetAlgorithm
edge_cost = geo_distance * avg_frictionmax_costexceededDask strategy
For finite
max_cost, computesmax_radius = max_cost / (f_min * cellsize)and uses this asdepthforda.map_overlap— exact within the cost budget. Falls back to single-chunk for unbounded or very large radii.Files changed
xrspatial/cost_distance.py— module with heap, Dijkstra kernel, numpy/dask wrappers, public APIxrspatial/tests/test_cost_distance.py— 19 tests (uniform friction, analytic case, barriers, multiple sources, max_cost truncation, dask/numpy equivalence, connectivity, validation errors)examples/user_guide/9_Cost_Distance.ipynb— example notebook comparingcost_distancewithproximityacross 7 scenariosxrspatial/__init__.py— exportcost_distanceTest plan
pytest xrspatial/tests/test_cost_distance.py -v— 19/19 passpytest xrspatial/tests/test_proximity.py -v— 24/24 pass (no regressions)max_costtruncation produces NaN beyond budget