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.
Description
Add a function
route
that encapsulates the common structure of routed functions in invest.All our routed functions use a stack or queue to track which pixels can be processed next. There is some logic specific to the routing algorithm that identifies "seed" pixels (pixels that routing can begin from). Seed pixels are pushed to the stack.
There is a second chunk of logic that is applied to each pixel on the stack. This is the core of the routing algorithm. It calculates results and pushes neighboring pixels to the stack when possible. The
route
wrapper separates these chunks of logic into aseed_fn
and aroute_fn
.The
seed_fn
must acceptx
andy
parameters. Other arbitrary parameters are also allowed. It returns a boolean (True
if the pixel at (x, y) meets the criteria for a seed pixel,False
otherwise).The
route_fn
must acceptx
andy
parameters. Other arbitrary parameters are also allowed. It performs calculations and sets values in the target rasters for the pixel (x, y). It returns a list of pixels that can now be pushed to the stack (represented as flat indexes).Checklist