From 80b9d95cbb6b22c92b8383b5e0635a5dd69de4c1 Mon Sep 17 00:00:00 2001 From: lou-a Date: Mon, 30 Sep 2024 15:27:25 -0400 Subject: [PATCH] Update routing_product.py Modified routing_product.py to correctly set the river length to zero and set default values for reach attributes in sub-basins with no channel routing (i.e., sub-basins with lakes or headwater basins). --- src/ravenpy/extractors/routing_product.py | 35 ++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/ravenpy/extractors/routing_product.py b/src/ravenpy/extractors/routing_product.py index 1505f570..6837e6eb 100644 --- a/src/ravenpy/extractors/routing_product.py +++ b/src/ravenpy/extractors/routing_product.py @@ -148,7 +148,13 @@ def _extract_subbasin(self, row, is_lake, subbasin_ids) -> dict: riv_length_field = ( "Rivlen" if self.routing_product_version == "1.0" else "RivLength" ) - river_length_in_kms = 0 if is_lake else round(row[riv_length_field] / 1000, 5) + # Correctly setting the river length to zero for sub-basins with no channel routing, such as sub-basins with lakes or headwater basins + if row[riv_length_field] > 1.0: + river_length_in_kms = round(row[riv_length_field] / 1000, 5) + else: + river_length_in_kms = 0 + if is_lake: + river_length_in_kms = 0 # river_slope = max( # row["RivSlope"], RoutingProductShapefileExtractor.MAX_RIVER_SLOPE # ) @@ -192,15 +198,24 @@ def _extract_reservoir(row) -> dict: @staticmethod def _extract_channel_profile(row) -> dict: subbasin_id = int(row["SubId"]) - slope = max(row["RivSlope"], BasinMakerExtractor.MAX_RIVER_SLOPE) - - # SWAT: top width of channel when filled with water; bankfull width W_bnkfull - channel_width = max(row["BkfWidth"], 1) - # SWAT: depth of water in channel when filled to top of bank - channel_depth = max(row["BkfDepth"], 1) - channel_elev = row["MeanElev"] - floodn = row["FloodP_n"] - channeln = row["Ch_n"] + + # Correctly defining the reach attributes for sub-basins with no channel routing (i.e., lakes or headwater basins) + if row["RivLength"] > 1.0: + slope = max(row["RivSlope"], BasinMakerExtractor.MAX_RIVER_SLOPE) + # SWAT: top width of channel when filled with water; bankfull width W_bnkfull + channel_width = max(row["BkfWidth"], 1) + # SWAT: depth of water in channel when filled to top of bank + channel_depth = max(row["BkfDepth"], 1) + channel_elev = row["MeanElev"] + floodn = row["FloodP_n"] + channeln = row["Ch_n"] + else: + slope = 0.12345 + channeln = 0.12345 + floodn = 0.12345 + channel_width = 0.12345 + channel_depth = 0.12345 + channel_elev = row["MeanElev"] # channel profile calculations are based on theory SWAT model is based on # see: https://swat.tamu.edu/media/99192/swat2009-theory.pdf