Skip to content

Commit 51f9f3c

Browse files
author
Cinzia Mazzetti
committed
using generic LddStructureChan and IsUpOfStructureChan
1 parent 8432a7f commit 51f9f3c

8 files changed

+64
-52
lines changed

src/lisflood/Lisflood_dynamic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def splitlanduse(array1, array2=None, array3=None):
191191
# if option['simulatePolders']:
192192
# ChannelToPolderM3=ChannelToPolderM3Old;
193193

194-
# # cmcheck moved to routing.py
194+
# # moved to routing.py
195195
# # Calculate total water storage in river channel
196196
# if option['InitLisflood'] or (not(option['SplitRouting'])):
197197
# # kinematic routing
@@ -224,13 +224,13 @@ def splitlanduse(array1, array2=None, array3=None):
224224

225225
if option['InitLisflood'] or option['repAverageDis']:
226226
self.CumQ += self.ChanQ
227-
#cmcheck we should use ChanQAvg here not ChanQ
227+
#cmcheck - we should use ChanQAvg here not ChanQ
228228
self.avgdis = self.CumQ/self.TimeSinceStart
229229
# to calculate average discharge over the entire simulation
230230

231231
self.DischargeM3Out += np.where(self.AtLastPointC ,self.ChanQ * self.DtSec,0)
232232
# Cumulative outflow out of map
233-
# cmcheck we should use ChanQAvg here not ChanQ
233+
# cmcheck - we should use ChanQAvg here not ChanQ
234234

235235
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236236
# Calculate water level

src/lisflood/hydrological_modules/evapowater.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def initial(self):
6060
maskinfo = MaskInfo.instance()
6161
if option['openwaterevapo']:
6262
LakeMask = loadmap('LakeMask', pcr=True)
63-
# cmcheck
64-
lmask = ifthenelse(LakeMask != 0, self.var.LddStructuresKinematic, 5)
63+
# lmask = ifthenelse(LakeMask != 0, self.var.LddStructuresKinematic, 5)
64+
lmask = ifthenelse(LakeMask != 0, self.var.LddStructuresChan, 5)
6565
LddEva = lddrepair(lmask)
6666
lddC = compressArray(LddEva)
6767
inAr = decompress(np.arange(maskinfo.info.mapC[0], dtype="int32"))
@@ -133,8 +133,6 @@ def dynamic(self):
133133
UpstreamEva = self.var.EWRef * self.var.MMtoM3 * self.var.WaterFraction
134134
# evaporation for loop is amount of water per timestep [cu m]
135135
# Volume of potential evaporation from water surface per time step (conversion to [m3])
136-
137-
# cmcheck
138136
# ChanMIter = self.var.ChanM3Kin.copy()
139137
ChanMIter = self.var.ChanM3.copy()
140138
# for Iteration loop: First value is amount of water in the channel

src/lisflood/hydrological_modules/indicatorcalc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ def dynamic(self):
132132
# EXTERNAL FLOW
133133
wreg = decompress(self.var.WUseRegionC)
134134
# to pcraster map because of the following expression!
135-
self.var.RegionMonthExternalInflowM3 = compressArray(areatotal(cover(ifthen(self.var.WaterRegionInflowPoints != 0, upstream(self.var.LddStructuresKinematic,decompress(self.var.MonthDisM3))),0),wreg))
135+
# self.var.RegionMonthExternalInflowM3 = compressArray(areatotal(cover(ifthen(self.var.WaterRegionInflowPoints != 0, upstream(self.var.LddStructuresKinematic,decompress(self.var.MonthDisM3))),0),wreg))
136+
self.var.RegionMonthExternalInflowM3 = compressArray(areatotal(cover(ifthen(self.var.WaterRegionInflowPoints != 0, upstream(self.var.LddStructuresChan,decompress(self.var.MonthDisM3))),0),wreg))
136137
self.var.RegionMonthAbstractionRequiredAllSourcesM3 = np.take(np.bincount(self.var.WUseRegionC,weights=self.var.MonthAbstractionRequiredAllSourcesM3),self.var.WUseRegionC)
137138
self.var.RegionMonthAbstractionRequiredSurfaceGroundWaterM3 = np.take(np.bincount(self.var.WUseRegionC,weights=self.var.MonthAbstractionRequiredSurfaceGroundWaterM3),self.var.WUseRegionC)
138139
self.var.RegionMonthAbstractionRequiredSurfaceWaterM3 = np.take(np.bincount(self.var.WUseRegionC,weights=self.var.MonthAbstractionRequiredSurfaceWaterM3),self.var.WUseRegionC)

src/lisflood/hydrological_modules/inflow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def dynamic(self):
125125
# Get inflow hydrograph at each inflow point [m3/s]
126126
QIn = compressArray(QIn)
127127
QIn[np.isnan(QIn)] = 0
128-
#cmcheck
128+
#cmcheck - inflow
129129
self.var.QInM3 = QIn * self.var.DtSec
130130
# Convert to [m3] per time step
131131
self.var.TotalQInM3 += self.var.QInM3
@@ -145,7 +145,7 @@ def dynamic_inloop(self, NoRoutingExecuted):
145145
settings = LisSettings.instance()
146146
option = settings.options
147147

148-
if option['inflow']: #cmcheck
148+
if option['inflow']: #cmcheck - inflow
149149

150150
self.var.QInDt = (self.var.QInM3Old + (NoRoutingExecuted + 1) * self.var.QDelta) * self.var.InvNoRoutSteps
151151
# flow from inlets per sub step

src/lisflood/hydrological_modules/routing.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,20 @@ def initial(self):
109109
# upstream of gauge locations
110110
# Calculate inverse, so we can multiply in dynamic (faster than divide)
111111

112-
self.var.IsChannelPcr = boolean(loadmap('Channels', pcr=True)) #pcr
112+
self.var.IsChannelPcr = boolean(loadmap('Channels', pcr=True)) #pcr map
113113
self.var.IsChannel = np.bool8(compressArray(self.var.IsChannelPcr)) #bool
114114
self.var.IsChannelPcr = boolean(decompress(self.var.IsChannel)) #pcr
115-
116115
# Identify grid cells containing a river channel
116+
117+
self.var.IsChannelKinematic = self.var.IsChannel.copy() #bool
118+
# Identify channel pixels using kinematic or split routing
119+
# (identical to IsChannel, unless MCT wave is used, see below)
120+
117121
self.var.IsStructureChan = np.bool8(maskinfo.in_zero()) #bool
118122
# Initialise map that identifies special inflow/outflow structures (reservoirs, lakes) within the
119123
# channel routing. Set to (dummy) value of zero modified in reservoir and lake
120124
# routines (if those are used)
121125

122-
self.var.IsChannelKinematic = self.var.IsChannel.copy() #bool
123-
# Identify kinematic wave channel pixels
124-
# (identical to IsChannel, unless MCT wave is used, see below)
125126
self.var.IsStructureKinematic = np.bool8(maskinfo.in_zero()) #bool
126127
# Initialise map that identifies special inflow/outflow structures (reservoirs, lakes) within the
127128
# kinematic wave channel routing. Set to (dummy) value of zero modified in reservoir and lake
@@ -231,7 +232,7 @@ def initial(self):
231232
# Area (sq m) of bank full discharge cross section [m2]
232233
# (trapezoid area equation)
233234

234-
#cmcheck
235+
#cmcheck - TotalCrossSectionAreaHalfBankFull is not 1/2 TotalCrossSectionAreaBankFull it's trapezoid
235236
# ChanUpperWidthHalfBankFull = self.var.ChanBottomWidth + 2 * self.var.ChanSdXdY * 0.5 * ChanDepthThreshold
236237
# TotalCrossSectionAreaHalfBankFull = 0.5 * \
237238
# 0.5 * ChanDepthThreshold * (ChanUpperWidthHalfBankFull + self.var.ChanBottomWidth)
@@ -394,7 +395,7 @@ def initial(self):
394395
# Cumulative inflow volume from inflow hydrographs [m3]
395396
self.var.sumDis = maskinfo.in_zero()
396397
self.var.sumIn = maskinfo.in_zero()
397-
# cmcheck non so se sostituita da self.var.sumInWB
398+
# cmcheck - non so se sostituita da self.var.sumInWB
398399
self.var.sumInWB = maskinfo.in_zero()
399400

400401

@@ -470,7 +471,6 @@ def initialSecond(self):
470471
self.var.Beta, self.var.ChanLength, self.var.DtRouting,
471472
alpha_floodplains=self.var.ChannelAlpha2, flagnancheck=flags['nancheck'])
472473

473-
# cmcheck
474474
# ************************************************************
475475
# ***** WATER BALANCE ************
476476
# ************************************************************
@@ -488,15 +488,15 @@ def initialSecond(self):
488488

489489
if not option['InitLisflood'] and option['repMBTs']:
490490
self.var.StorageStepINIT = self.var.ChanM3
491-
DisStructure = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
492-
# cmchek to fix IsUpsOfStructureKinematicC for MCT
491+
# DisStructure = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
492+
DisStructure = np.where(self.var.IsUpsOfStructureChanC, self.var.ChanQ * self.var.DtRouting, 0)
493493
if not(option['SplitRouting']):
494494
# self.var.StorageStepINIT = self.var.ChanM3Kin
495495
# self.var.StorageStepINIT = self.var.ChanM3
496496
if option['simulateReservoirs']:
497497
self.var.StorageStepINIT += self.var.ReservoirStorageIniM3
498-
DisStructure = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
499-
# cmchek to fix IsUpsOfStructureKinematicC for MCT
498+
# DisStructure = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
499+
DisStructure = np.where(self.var.IsUpsOfStructureChanC, self.var.ChanQ * self.var.DtRouting, 0)
500500
if option['simulateLakes']:
501501
self.var.StorageStepINIT += self.var.LakeStorageIniM3
502502
DisStructure += np.where(compressArray(self.var.IsUpsOfStructureLake), 0.5 * self.var.ChanQ * self.var.DtRouting, 0)
@@ -815,18 +815,17 @@ def dynamic(self, NoRoutingExecuted):
815815
if option['simulateReservoirs']:
816816
sum1 =self.var.ChanQ.copy()
817817
StorageStep = StorageStep + self.var.ReservoirStorageM3.copy()
818-
# cmcheck IsUpsOfStructureKinematicC
819-
DisStructureR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
820-
# cmchek to fix IsUpsOfStructureKinematicC for MCT
818+
# DisStructureR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
819+
DisStructureR = np.where(self.var.IsUpsOfStructureChanC, sum1 * self.var.DtRouting, 0)
821820
DischargeM3StructuresR = np.take(np.bincount(self.var.Catchments, weights=DisStructureR), self.var.Catchments)
822821
DischargeM3StructuresR -= self.var.DischargeM3StructuresIni
823822

824823
if not option['InitLisflood']:
825824
if option['simulateLakes']:
826825
sum1 =self.var.ChanQ.copy()
827826
StorageStep = StorageStep + self.var.LakeStorageM3Balance.copy()
828-
DisStructureR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
829-
# cmchek to fix IsUpsOfStructureKinematicC for MCT
827+
# DisStructureR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
828+
DisStructureR = np.where(self.var.IsUpsOfStructureChanC, sum1 * self.var.DtRouting, 0)
830829
DischargeM3StructuresR = np.take(np.bincount(self.var.Catchments, weights=DisStructureR), self.var.Catchments)
831830
maskinfo = MaskInfo.instance()
832831
DisLake = maskinfo.in_zero()
@@ -864,16 +863,16 @@ def dynamic(self, NoRoutingExecuted):
864863
sum1=[]
865864
sum1 =self.var.ChanQ.copy()
866865
StorageStep = StorageStep + self.var.ReservoirStorageM3.copy()
867-
DisStructureSR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
868-
# cmchek to fix IsUpsOfStructureKinematicC for MCT
866+
# DisStructureSR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
867+
DisStructureSR = np.where(self.var.IsUpsOfStructureChanC, sum1 * self.var.DtRouting, 0)
869868
DischargeM3StructuresR = np.take(np.bincount(self.var.Catchments, weights=DisStructureSR), self.var.Catchments)
870869
DischargeM3StructuresR -= self.var.DischargeM3StructuresIni
871870

872871
if option['simulateLakes']:
873872
sum1 =self.var.ChanQ.copy()
874873
StorageStep = StorageStep + self.var.LakeStorageM3Balance.copy()
875-
DisStructureSR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
876-
# cmchek to fix IsUpsOfStructureKinematicC for MCT
874+
# DisStructureSR = np.where(self.var.IsUpsOfStructureKinematicC, sum1 * self.var.DtRouting, 0)
875+
DisStructureSR = np.where(self.var.IsUpsOfStructureChanC, sum1 * self.var.DtRouting, 0)
877876
DischargeM3StructuresR = np.take(np.bincount(self.var.Catchments, weights=DisStructureSR), self.var.Catchments)
878877
DisLake = maskinfo.in_zero()
879878
np.put(DisLake, self.var.LakeIndex, 0.5 * self.var.LakeInflowCC * self.var.DtRouting)

src/lisflood/hydrological_modules/structures.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,41 @@ def __init__(self, structures_variable):
4343
def initial(self):
4444
""" initial part of the structures module
4545
"""
46-
self.var.LddStructuresKinematic = self.var.LddKinematic #pcr
46+
self.var.LddStructuresKinematic = self.var.LddKinematic #pcr map
4747
LddStructuresKinematicNp = compressArray(self.var.LddStructuresKinematic)
48-
self.var.LddStructuresChan = self.var.LddChan #pcr
48+
# Unmodified version of LddKinematic is needed to connect inflow and outflow points
49+
# of each structure (called LddStructuresKinematic now)
50+
51+
self.var.LddStructuresChan = self.var.LddChan #pcr map
4952
LddStructuresChanNp = compressArray(self.var.LddStructuresChan)
53+
# Unmodified version of LddChan is needed to connect inflow and outflow points
54+
# of each structure (called LddStructuresChan now)
5055

5156
settings = LisSettings.instance()
5257
option = settings.options
5358
if not option['InitLisflood']:
5459
# not done in Init Lisflood
55-
IsUpsOfStructureKinematic = downstream(
60+
IsUpsOfStructureKinematic = downstream( #pcr map
5661
self.var.LddKinematic,
5762
cover(boolean(decompress(self.var.IsStructureKinematic)), boolean(0))
5863
)
59-
IsUpsOfStructureChan = downstream(
64+
# Downstream assigns to result the expression value of the neighbouring downstream cell
65+
# Over is used to cover missing values on an expression with values taken from one or more different expression(s)
66+
# Decompress is numpy2pcr
67+
# Find location of pixels immediately upstream of a structure on the LddKinematic
68+
69+
IsUpsOfStructureChan = downstream( #pcr map
6070
self.var.LddChan,
6171
cover(boolean(decompress(self.var.IsStructureChan)), boolean(0))
6272
)
73+
# Find location of pixels immediately upstream of a structure on the LddChan
74+
75+
self.var.IsUpsOfStructureKinematicC = compressArray(IsUpsOfStructureKinematic) #np compressed array
76+
# Location of pixels immediately upstream of a structure on the LddKinematic
77+
self.var.IsUpsOfStructureChanC = compressArray(IsUpsOfStructureChan) #np compressed array
78+
# Location of pixels immediately upstream of a structure on the LddChan
6379

64-
# Get all pixels just upstream of kinematic structure locations
65-
self.var.IsUpsOfStructureKinematicC = compressArray(IsUpsOfStructureKinematic) #np
66-
# Unmodified version of LddKinematic is needed to connect inflow and outflow points
67-
# of each structure (called LddStructuresKinematic now)
68-
self.var.IsUpsOfStructureChanC = compressArray(IsUpsOfStructureChan) #np
69-
# Unmodified version of LddChan is needed to connect inflow and outflow points
70-
# of each structure (called LddStructuresChan now)
71-
72-
self.var.LddKinematic = lddrepair(ifthenelse(IsUpsOfStructureKinematic, 5, self.var.LddKinematic))
73-
# Cells just upstream of each structure are treated as pits in the kinematic wave channel routing
74-
self.var.LddChan = lddrepair(ifthenelse(IsUpsOfStructureChan, 5, self.var.LddChan))
75-
# Cells just upstream of each structure are treated as pits in the kinematic wave channel routing
80+
self.var.LddKinematic = lddrepair(ifthenelse(IsUpsOfStructureKinematic, 5, self.var.LddKinematic)) #pcr map
81+
# Update LddKinematic by adding a pit in the pixel immediately upstream of a structure
82+
self.var.LddChan = lddrepair(ifthenelse(IsUpsOfStructureChan, 5, self.var.LddChan)) #pcr map
83+
# Update LddChan by adding a pit in the pixel immediately upstream of a structure

src/lisflood/hydrological_modules/waterabstraction.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,16 @@ def initial(self):
159159
pitWuse2 = ifthen(pitWuseMax == self.var.UpArea, WUseRegion)
160160
# search outlets in the inland water regions by using the maximum upstream area as criterium
161161

162-
pitWuse3 = downstream(self.var.LddStructuresKinematic, WUseRegion)
162+
# pitWuse3 = downstream(self.var.LddStructuresKinematic, WUseRegion)
163+
pitWuse3 = downstream(self.var.LddStructuresChan, WUseRegion)
163164
pitWuse3b = ifthen(pitWuse3 != WUseRegion, WUseRegion)
164165
# search point where ldd leaves a water region
165166

166167
pitWuse = cover(pitWuse1b, pitWuse2, pitWuse3b, nominal(0))
167168
# join all sources of pits
168169

169-
LddWaterRegion = lddrepair(ifthenelse(pitWuse == 0, self.var.LddStructuresKinematic, 5))
170+
# LddWaterRegion = lddrepair(ifthenelse(pitWuse == 0, self.var.LddStructuresKinematic, 5))
171+
LddWaterRegion = lddrepair(ifthenelse(pitWuse == 0, self.var.LddStructuresChan, 5))
170172
# create a Ldd with pits at every water region outlet
171173
# this results in a interrupted ldd, so water cannot be transfered to the next water region
172174
lddC = compressArray(LddWaterRegion)
@@ -185,8 +187,10 @@ def initial(self):
185187
# outflowpoints to calculate upstream inflow for balances and Water Exploitation Index
186188
# both inland outflowpoints to downstream subbasin, and coastal outlets
187189

190+
# WaterRegionInflow1 = boolean(
191+
# upstream(self.var.LddStructuresKinematic, cover(scalar(self.var.WaterRegionOutflowPoints), 0)))
188192
WaterRegionInflow1 = boolean(
189-
upstream(self.var.LddStructuresKinematic, cover(scalar(self.var.WaterRegionOutflowPoints), 0)))
193+
upstream(self.var.LddStructuresChan, cover(scalar(self.var.WaterRegionOutflowPoints), 0)))
190194
self.var.WaterRegionInflowPoints = ifthen(WaterRegionInflow1, boolean(1))
191195
# inflowpoints to calculate upstream inflow for balances and Water Exploitation Index
192196
else:

src/lisflood/hydrological_modules/waterbalance.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def initial(self):
8989
#DisStructure = cover(ifthen(
9090
# self.var.IsUpsOfStructureKinematic, self.var.ChanQ * self.var.DtRouting), scalar(0.0))
9191

92-
DisStructure = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
92+
# DisStructure = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
93+
DisStructure = np.where(self.var.IsUpsOfStructureChanC, self.var.ChanQ * self.var.DtRouting, 0)
9394

9495
# Discharge upstream of structure locations (coded as pits) in [m3/time step]
9596
# Needed for mass balance error calculations (see comment to calculation of WaterInit below)
@@ -232,7 +233,8 @@ def dynamic(self):
232233
# for this double counting)
233234
# new 12.11.09 PB
234235
# added cumulative transmission loss
235-
DisStru = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
236+
# DisStru = np.where(self.var.IsUpsOfStructureKinematicC, self.var.ChanQ * self.var.DtRouting, 0)
237+
DisStru = np.where(self.var.IsUpsOfStructureChanC, self.var.ChanQ * self.var.DtRouting, 0)
236238
DischargeM3Structures = np.take(np.bincount(self.var.Catchments, weights=DisStru), self.var.Catchments)
237239

238240
# on the last time step lakes and reservoirs calculated with the previous routing results

0 commit comments

Comments
 (0)