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

Implement klargestconncomps #112

Open
wkearn opened this issue Dec 10, 2024 · 2 comments
Open

Implement klargestconncomps #112

wkearn opened this issue Dec 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@wkearn
Copy link
Contributor

wkearn commented Dec 10, 2024

This is a StreamObject method that returns a new StreamObject, with only the edges corresponding to the k largest connected components of the stream network. The MATLAB implementation uses a built-in MATLAB linear algebra function dmperm. This operation might be worth implementing in libtopotoolbox.

This is used in the Getting Started guide section "Derive, modify and plot the stream network."

@wkearn wkearn added the enhancement New feature or request label Dec 10, 2024
@wschwanghart
Copy link

There are probably easier ways to implement this function and avoid dmperm. Probably, it is more straightforward to (1) identify the outlets, (2) label them, (3) traverse the network in upstream direction and label other nodes, (4) create and sort a histogram of the label frequencies. and (5) extract the nodes. dmperm requires that the stream network is stored in a sparse adjacency matrix and is usually used to precondition matrices.

@wkearn
Copy link
Contributor Author

wkearn commented Dec 10, 2024

(1), (2), and (3) are a connected components labeling algorithm and very similar to what is done in drainagebasins but using the stream network rather than the full flow network. With some refactoring we may be able to repurpose the drainagebasins traversal in libtopotoolbox (TopoToolbox/libtopotoolbox#121) to do that.

A histogram could be constructed during the labeling traversal (faster but requires modification of the traversal code), or could be done afterwards using numpy functions. Extracting nodes with a given label should probably be done in Python, because it requires dynamic memory allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants