Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* 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)
* 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)
Expand Down
46 changes: 21 additions & 25 deletions src/ravenpy/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,34 +613,30 @@ 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],
),
)
)
out.append(cls(name=name, **a))
return out


Expand Down Expand Up @@ -672,7 +668,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))
Expand Down