From 3524137623328abbcf1daaa58816b0d59981064b Mon Sep 17 00:00:00 2001 From: David Huard Date: Mon, 6 Oct 2025 15:24:11 -0400 Subject: [PATCH 1/4] Make the Reservoir parser more robust to missing optional fields. --- src/ravenpy/config/commands.py | 41 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ravenpy/config/commands.py b/src/ravenpy/config/commands.py index f3f7ab92..f6ac45ea 100644 --- a/src/ravenpy/config/commands.py +++ b/src/ravenpy/config/commands.py @@ -613,32 +613,33 @@ def parse(cls, s) -> list: pat = r":Reservoir\s+(\w+)\s+(.+?):EndReservoir" out = [] + a = {} for name, content in re.findall(pat, s.strip(), re.DOTALL): # Extract parameters - subbasin_id = re.search(r":SubBasinID\s+(\d+)", content).group(1) - hru_id = re.search(r":HRUID\s+(\d+)", content).group(1) - type_ = re.search(r":Type\s+(\w+)", content).group(1) - weir_coefficient = re.search(r":WeirCoefficient\s+([\d.-]+)", content).group(1) - crest_width = re.search(r":CrestWidth\s+([\d.-]+)", content).group(1) - max_depth = re.search(r":MaxDepth\s+([\d.-]+)", content).group(1) - lake_area = re.search(r":LakeArea\s+([\d.-]+)", content).group(1) - seepage_parameters = re.search(r":SeepageParameters\s+([\d.-]+)\s+([\d.-]+)", content).groups() + a["subbasin_id"] = re.search(r":SubBasinID\s+(\d+)", content).group(1) + a["hru_id"] = re.search(r":HRUID\s+(\d+)", content).group(1) + a["type"] = re.search(r":Type\s+(\w+)", content).group(1) + + if m := re.search(r":WeirCoefficient\s+([\d.-]+)", content): + a["weir_coefficient"] = m.group(1) + + if m := re.search(r":CrestWidth\s+([\d.-]+)", content): + a["crest_width"] = m.group(1) + + if m := re.search(r":MaxDepth\s+([\d.-]+)", content): + a["max_depth"] = m.group(1) + + if m := re.search(r":LakeArea\s+([\d.-]+)", content): + a["lake_area"] = m.group(1) + + if m := re.search(r":SeepageParameters\s+([\d.-]+)\s+([\d.-]+)", content): + a["seepage_parameters"] = dict(zip(["k_seep", "h_ref"], m.groups())) # Convert to Reservoir record out.append( cls( name=name, - subbasin_id=subbasin_id, - hru_id=hru_id, - type=type_, - weir_coefficient=weir_coefficient, - crest_width=crest_width, - max_depth=max_depth, - lake_area=lake_area, - seepage_parameters=cls.SeepageParameters( - k_seep=seepage_parameters[0], - h_ref=seepage_parameters[1], - ), + **a ) ) return out @@ -672,7 +673,7 @@ def parse(cls, s) -> list: out = [] for name, content in re.findall(pat, s.strip(), re.DOTALL): - sb_ids = re.split(r"\s+", content.strip()) + sb_ids = re.findall(r"\d+", content) # Convert to SubBasinGroup record out.append(SubBasinGroup(name=name, sb_ids=sb_ids)) From dbc53923b1d53cdbf2af100b81583082fafdeb36 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Oct 2025 19:49:35 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/ravenpy/config/commands.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ravenpy/config/commands.py b/src/ravenpy/config/commands.py index 1d8689ea..35319fdb 100644 --- a/src/ravenpy/config/commands.py +++ b/src/ravenpy/config/commands.py @@ -619,10 +619,10 @@ def parse(cls, s) -> list: a["subbasin_id"] = re.search(r":SubBasinID\s+(\d+)", content).group(1) a["hru_id"] = re.search(r":HRUID\s+(\d+)", content).group(1) a["type"] = re.search(r":Type\s+(\w+)", content).group(1) - + if m := re.search(r":WeirCoefficient\s+([\d.-]+)", content): a["weir_coefficient"] = m.group(1) - + if m := re.search(r":CrestWidth\s+([\d.-]+)", content): a["crest_width"] = m.group(1) @@ -631,17 +631,12 @@ def parse(cls, s) -> list: if m := re.search(r":LakeArea\s+([\d.-]+)", content): a["lake_area"] = m.group(1) - + if m := re.search(r":SeepageParameters\s+([\d.-]+)\s+([\d.-]+)", content): a["seepage_parameters"] = dict(zip(["k_seep", "h_ref"], m.groups())) # Convert to Reservoir record - out.append( - cls( - name=name, - **a - ) - ) + out.append(cls(name=name, **a)) return out From 2f9a6e554f6cdfafa86ee7ca7ecca202dd2e693a Mon Sep 17 00:00:00 2001 From: David Huard Date: Mon, 6 Oct 2025 15:49:40 -0400 Subject: [PATCH 3/4] update changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3505224c..22cc0cfb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Contributors: David Huard (:user:`huard`), Trevor James Smith (:user:`Zeitsperre Fixes ^^^^^ +* Fix `Reservoir` command parser failing when optional fields were missing. (PR #544) * In `nc_specs`, set `dim_names_nc` in the order expected by Raven (x, y, t). Previously, we only made sure that `time` was the last dimension, but did not ensure x and y were in the right order. (PR #533) * Adjusted the `Perform_a_climate_change_impact_study_on_a_watershed.ipynb` notebook to reduce the number of years in the simulation to speed up execution time. (PR #535) * Adjusted a broken test that was overlooked in the previous release (from changes in PR #513). (PR #535) From 8b0b467a17a38fdb0616e55a80276589d7263065 Mon Sep 17 00:00:00 2001 From: David Huard Date: Fri, 10 Oct 2025 17:23:52 -0400 Subject: [PATCH 4/4] Update CHANGELOG.rst Co-authored-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- CHANGELOG.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f49484c6..d2261fc6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,7 +9,6 @@ Contributors: David Huard (:user:`huard`), Trevor James Smith (:user:`Zeitsperre Fixes ^^^^^ - * Fix `Reservoir` command parser failing when optional fields were missing. (PR #544) * Add `GaugedSubBasinGroup` command to `RVH` class. (Issue #546, PR #547) * In `nc_specs`, set `dim_names_nc` in the order expected by Raven (x, y, t). Previously, we only made sure that `time` was the last dimension, but did not ensure x and y were in the right order. (PR #533)