Skip to content

Commit

Permalink
fix bug in river_centerline_from_hydrography (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkEilander authored Sep 26, 2024
1 parent b72191d commit ffc5658
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 14 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ Distinction is made between new methods (Added), changes to existing methods (Ch
The format is based on `Keep a Changelog`_, and this project adheres to
`Semantic Versioning`_.

unreleased
==========

Added
-----

Changed
-------

Fixed
-----
- fixed a bug in `river_centerline_from_hydrography` in case there is only one river with a single segment


v1.1.0 (05-09-2024)
===================
**This release contains some breaking changes and can only be used in combination with
Expand Down
17 changes: 10 additions & 7 deletions hydromt_sfincs/workflows/flwdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ def river_centerline_from_hydrography(
gdf_riv = gdf_riv[gdf_riv["seglen"] > 0]
if gdf_riv.empty or river_len == 0:
return gdf_riv
# accumulate to get river length from outlet
flwdir = pyflwdir.from_dataframe(gdf_riv.set_index("idx"), ds_col="idx_ds")
gdf_riv["rivdst"] = flwdir.accuflux(gdf_riv["seglen"].values, direction="down")
# get maximum river length from outlet (at headwater segments) for each river segment
gdf_riv["rivlen"] = flwdir.fillnodata(
np.where(flwdir.n_upstream == 0, gdf_riv["rivdst"], 0), 0
)
if gdf_riv.index.size > 1:
# accumulate to get river length from outlet
flwdir = pyflwdir.from_dataframe(gdf_riv.set_index("idx"), ds_col="idx_ds")
gdf_riv["rivdst"] = flwdir.accuflux(gdf_riv["seglen"].values, direction="down")
# get maximum river length from outlet (at headwater segments) for each river segment
gdf_riv["rivlen"] = flwdir.fillnodata(
np.where(flwdir.n_upstream == 0, gdf_riv["rivdst"], 0), 0
)
else:
gdf_riv["rivlen"] = gdf_riv["seglen"]
# filter river network based on total length
gdf_riv = gdf_riv[gdf_riv["rivlen"] >= river_len]
return gdf_riv
Expand Down

0 comments on commit ffc5658

Please sign in to comment.