Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not assign drainage basins to invalid pixels #161

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

wkearn
Copy link
Contributor

@wkearn wkearn commented Jan 21, 2025

This PR fixes a problem with drainage basins which would lead to pixels that are not part of the flow network such as NaNs in the DEM being assigned to their own drainage basin.

The problem was that sinks, outlets and invalid pixels are all assigned placeholder edges by flow_routing_d8_carve that point from them to -1. We were using this placeholder edge to detect when to create a new drainage basin. This works for the sinks and outlets, but also creates a drainage basin for the invalid pixels. This PR switches this behavior to 1. skip these placeholder edges and 2. test whether the target pixel has not yet been assigned to a drainage basin. This matches the behavior of the MATLAB implementation, leaving invalid pixels with a 0 label for their drainage basin.

This is part of some changes I am planning to the representation of flow networks in libtopotoolbox that should eventually remove those placeholder edges.

edge_count is currently equal to the number of pixels, but that might
change in the future.
The placeholder edges from src -> -1 denote sinks, outlets, and
invalid pixels (i.e. NaNs). By initializing drainage basins when tgt <
0, we create drainage basins at the sinks and outlets but also at the
invalid pixels. This commit changes this behavior to create a new
basin only upon reaching a valid edge src->tgt where tgt does not yet
belong to a drainage basin.
@wkearn wkearn merged commit 01b7e5e into TopoToolbox:main Jan 21, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant