Skip to content

Commit

Permalink
Update routing_product.py
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
lou-a authored and Zeitsperre committed Sep 30, 2024
1 parent 4fe8045 commit 31bd68d
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/ravenpy/extractors/routing_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# )
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 31bd68d

Please sign in to comment.