-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related issue #9 This adds a function to leverage the MNSI information and group upstream basins into meaningful groups that can be pre-dissolved. Pre-dissolving will allow for less total in the final dissolve.
- Loading branch information
Showing
3 changed files
with
166 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .delineate import subset_network |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import geopandas as gpd | ||
|
||
|
||
def subset_network(gdf: gpd.GeoDataFrame, linkid: int) -> gpd.GeoDataFrame: | ||
"""Subset a basins (gdf) to include only elements upstream of linkid | ||
Args: | ||
gdf (gpd.GeoDataFrame): and GeoDataFrame representation of the | ||
basins dataset where the stream reach with linkid resides. | ||
linkid (int): The global unique identifier for the stream | ||
network of interest | ||
Returns: | ||
gpd.GeoDataFrame: Subsetted GeoDataFrame containing all basins | ||
upstream of the basin corresponding to linkno | ||
""" | ||
# ID target basins from linkno and extract critical mnsi info | ||
# this is assuming the gdf has already set index to streamID | ||
target_basin = gdf.loc[linkid] | ||
root_id = target_basin["ROOT_ID"] | ||
discover_time = target_basin["DISCOVER_TIME"] | ||
finish_time = target_basin["FINISH_TIME"] | ||
|
||
# subset using modified nest set index logic, further documented in README | ||
return gdf.loc[ | ||
(gdf["ROOT_ID"] == root_id) | ||
& (gdf["DISCOVER_TIME"] >= discover_time) | ||
& (gdf["FINISH_TIME"] <= finish_time) | ||
] |
This file contains 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