Skip to content

Commit

Permalink
Bug correction reservoir wflow_hbv
Browse files Browse the repository at this point in the history
  • Loading branch information
hboisgon committed May 26, 2020
1 parent 0609f05 commit ba5efd3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions wflow/wflow_hbv.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,27 @@ def initial(self):

self.wf_updateparameters()

self.ReserVoirLocs = self.ZeroMap
if hasattr(self, "ReserVoirSimpleLocs") or hasattr(
self, "LakeLocs"
):
self.ReserVoirLocs = self.ZeroMap
self.filter_P_PET = self.ZeroMap + 1.0

if hasattr(self, "ReserVoirSimpleLocs"):
# Check if we have simple and or complex reservoirs
self.ReserVoirSimpleLocs = pcr.nominal(self.ReserVoirSimpleLocs)
self.ReservoirSimpleAreas = pcr.nominal(self.ReservoirSimpleAreas)
tt_simple = pcr.pcr2numpy(self.ReserVoirSimpleLocs, 0.0)
self.nrresSimple = tt_simple.max()
self.ReserVoirLocs = self.ReserVoirLocs + pcr.cover(
pcr.scalar(self.ReserVoirSimpleLocs), 0.0
)
res_area = pcr.cover(pcr.scalar(self.ReservoirSimpleAreas), 0.0)
self.filter_P_PET = pcr.ifthenelse(
pcr.boolean(pcr.cover(res_area, pcr.scalar(0.0))),
res_area * 0.0,
self.filter_P_PET,
)
else:
self.nrresSimple = 0

Expand Down Expand Up @@ -686,6 +698,9 @@ def initial(self):
self.TopoLdd,
)
)

tt_filter = pcr.pcr2numpy(self.filter_P_PET, 1.0)
self.filterResArea = tt_filter.min()

# HBV Soil params
self.FC = self.readtblDefault(
Expand Down Expand Up @@ -899,8 +914,10 @@ def initial(self):
# Alf ranges from 5 to > 60. 5 for hardrock. large values for sediments
# "Noah J. Finnegan et al 2005 Controls on the channel width of rivers:
# Implications for modeling fluvial incision of bedrock"

upstr = pcr.catchmenttotal(1, self.TopoLdd)
if (self.nrresSimple + self.nrlake) > 0:
upstr = pcr.catchmenttotal(1, self.TopoLddOrg)
else:
upstr = pcr.catchmenttotal(1, self.TopoLdd)
Qscale = upstr / pcr.mapmaximum(upstr) * Qmax
W = (
(alf * (alf + 2.0) ** (0.6666666667)) ** (0.375)
Expand Down Expand Up @@ -1285,7 +1302,7 @@ def dynamic(self):
# I nthe origal HBV code
RestEvap = pcr.max(0.0, self.PotEvaporation - self.IntEvap)

if hasattr(self, "ReserVoirComplexLocs"):
if (self.nrresSimple + self.nrlake) > 0 and self.filterResArea == 0:
self.ReserVoirPotEvap = self.PotEvaporation
self.ReserVoirPrecip = self.Precipitation

Expand Down Expand Up @@ -1494,15 +1511,19 @@ def dynamic(self):
# only run the reservoir module if needed

if self.nrresSimple > 0:
self.ReservoirVolume, self.Outflow, self.ResPercFull, self.DemandRelease = simplereservoir(
self.ReservoirVolume, self.Outflow, self.ResPercFull, self.ResPrecip, self.ResEvap, self.DemandRelease = simplereservoir(
self.ReservoirVolume,
self.SurfaceRunoff,
self.ResSimpleArea,
self.ResMaxVolume,
self.ResTargetFullFrac,
self.ResMaxRelease,
self.ResDemand,
self.ResTargetMinFrac,
self.ReserVoirSimpleLocs,
self.ReserVoirPrecip,
self.ReserVoirPotEvap,
self.ReservoirSimpleAreas,
timestepsecs=self.timestepsecs,
)
self.OutflowDwn = pcr.upstream(
Expand Down
2 changes: 1 addition & 1 deletion wflow/wflow_sediment.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def estimate_sedriv_tranport_iter(Q, deltaT, h, x, W, mv = -999):

it = np.ceil(deltaT / np.amin(minTstep))
#Maximum number of iterations
it = max(it, 1000)
it = min(it, 1000)

return it

Expand Down

0 comments on commit ba5efd3

Please sign in to comment.