diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 170272d2c..3ea352dfd 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -1,6 +1,18 @@
All notable changes to this project will be documented in this file.
We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.
+## v4.5.x.x - 2024-09-12 - [PR#1284](https://github.com/NOAA-OWP/inundation-mapping/pull/1284)
+
+Segments of levelpaths that terminate in waterbodies are removed from the levelpath. If there is a waterbody downstream of the HUC then the outlet reaches may be trimmed such that the outlet no longer reaches the edge of the DEM, which causes a number of cascading issues originating in the pit-filling such that reverse flow in the DEM-derived reaches can result in erroneous flowlines and inundation. This PR stops trimming levelpaths outside of the HUC.
+
+### Changes
+
+- `src/`
+ - `derive_level_paths.py`: Adds WBD as an input to `stream_network.trim_branches_in_waterbodies()`
+ - `stream_network.py`: Selects only segments intersecting the WBD as candidates for removal if they end in waterbodies
+
+
+
## v4.5.6.0 - 2024-08-23 - [PR#1253](https://github.com/NOAA-OWP/inundation-mapping/pull/1253)
Upgrades Python packages and dependencies and fixes backwards incompatibilities with new version of `geopandas`. Major changes include:
diff --git a/src/derive_level_paths.py b/src/derive_level_paths.py
index 36e3fd437..ed822f20e 100755
--- a/src/derive_level_paths.py
+++ b/src/derive_level_paths.py
@@ -179,7 +179,7 @@ def Derive_level_paths(
if out_stream_network_dissolved is not None:
stream_network = stream_network.trim_branches_in_waterbodies(
- branch_id_attribute=branch_id_attribute, verbose=verbose
+ wbd=wbd, branch_id_attribute=branch_id_attribute, verbose=verbose
)
# dissolve by levelpath
diff --git a/src/stream_branches.py b/src/stream_branches.py
index d0f918500..8380bbb9a 100755
--- a/src/stream_branches.py
+++ b/src/stream_branches.py
@@ -584,7 +584,7 @@ def remove_branches_without_catchments(
return self
- def trim_branches_in_waterbodies(self, branch_id_attribute, verbose=False):
+ def trim_branches_in_waterbodies(self, wbd, branch_id_attribute, verbose=False):
"""
Recursively trims the reaches from the ends of the branches if they are in a
waterbody (determined by the Lake attribute).
@@ -645,6 +645,14 @@ def find_upstream_reaches_in_waterbodies(tmp_self, tmp_IDs=[]):
for branch in self[branch_id_attribute].astype(int).unique():
tmp_self = self[self[branch_id_attribute].astype(int) == branch]
+ # load waterbodies
+ if isinstance(wbd, str):
+ wbd = gpd.read_file(wbd)
+
+ # trim only branches in WBD (to prevent outlet from being trimmed)
+ if isinstance(wbd, gpd.GeoDataFrame):
+ tmp_self = gpd.sjoin(tmp_self, wbd)
+
# If entire branch is in waterbody
if all(tmp_self.Lake.values != -9999):
tmp_IDs = tmp_self.From_Node.astype(int)