Skip to content

Commit

Permalink
Implement split and lateralflush
Browse files Browse the repository at this point in the history
  • Loading branch information
Scriptbash committed Feb 2, 2023
1 parent 186a590 commit 0d2f1f5
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 180 deletions.
97 changes: 69 additions & 28 deletions qraven/modules/hydrologicproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ def addprocess(self):

combo_proc = QComboBox()
combo_alg = QComboBox()
combo_from = QComboBox()
combo_from = QComboBox()
combo_from2 = QComboBox()
combo_from2.setEnabled(False)
combo_to = QComboBox()

combo_to2 = QComboBox()
combo_to2.setEnabled(False)

chk_isconditional = QCheckBox()

combo_basedtype = QComboBox()
Expand All @@ -34,14 +38,16 @@ def addprocess(self):
table.setCellWidget(currentRow, 0, combo_proc) #Sets the new combobox in the first column and in the new row
table.setCellWidget(currentRow, 1, combo_alg)
table.setCellWidget(currentRow, 2, combo_from)
table.setCellWidget(currentRow, 3, combo_to)
table.setCellWidget(currentRow, 4, chk_isconditional)
table.setCellWidget(currentRow, 5, combo_basedtype)
table.setCellWidget(currentRow, 6, combo_comparison)
table.setCellWidget(currentRow, 7, txt_hrutype)
table.setCellWidget(currentRow, 8, chk_mixingrate)
table.setCellWidget(currentRow, 9, spin_pct)
table.setCellWidget(currentRow, 10, chk_interbasin)
table.setCellWidget(currentRow, 3, combo_from2)
table.setCellWidget(currentRow, 4, combo_to)
table.setCellWidget(currentRow, 5, combo_to2)
table.setCellWidget(currentRow, 6, chk_isconditional)
table.setCellWidget(currentRow, 7, combo_basedtype)
table.setCellWidget(currentRow, 8, combo_comparison)
table.setCellWidget(currentRow, 9, txt_hrutype)
table.setCellWidget(currentRow, 10, chk_mixingrate)
table.setCellWidget(currentRow, 11, spin_pct)
table.setCellWidget(currentRow, 12, chk_interbasin)

table.resizeColumnsToContents() #Resizes the width of the column automatically
combo_proc.currentIndexChanged.connect(lambda:setProcAlg(self,currentRow)) #Updates the algorithm combobox if the process changes
Expand All @@ -57,14 +63,17 @@ def removeprocess(self):
def setProcAlg(self,row):
#print('Went into the algs')
table = self.dlg.table_hydroprocess

combo_proc = table.cellWidget(row, 0)
combo_alg = table.cellWidget(row, 1) #Sets the new combobox in the first column and in the new row
combo_from = table.cellWidget(row, 2)
combo_to = table.cellWidget(row, 3)
chk_mixingrate = table.cellWidget(row, 8)
spin_pct = table.cellWidget(row, 9)
chk_interbasin = table.cellWidget(row, 10)
combo_from2 = table.cellWidget(row, 3)
combo_to2 = table.cellWidget(row, 5)
chk_mixingrate = table.cellWidget(row, 10)
spin_pct = table.cellWidget(row, 11)
chk_interbasin = table.cellWidget(row, 12)

combo_from2.setEnabled(False)
combo_to2.setEnabled(False)
combo_alg.setEnabled(True)
spin_pct.setEnabled(False)
chk_interbasin.setChecked(False)
Expand All @@ -75,6 +84,8 @@ def setProcAlg(self,row):
# index = self.dlg.table_hydroprocess.indexAt(currentWidget.pos())
# widgetRow = index.row()
combo_alg.clear()
combo_from2.clear()
combo_to2.clear()
combo_alg.addItem('')

# if isinstance(currentWidget, QComboBox):
Expand Down Expand Up @@ -142,11 +153,14 @@ def setProcAlg(self,row):
elif selectedProc == 'Abstraction':
combo_alg.addItems(abstractionAlg)
elif selectedProc == 'Split':
combo_to2.setEnabled(True)
combo_alg.addItems(splitAlg)
chk_mixingrate.setEnabled(True)
elif selectedProc == 'Convolve':
combo_alg.addItems(convolutionAlg)
elif selectedProc == 'LateralFlush':
combo_from2.setEnabled(True)
combo_to2.setEnabled(True)
combo_alg.addItems(lateralflushAlg)
elif selectedProc == 'LateralEquilibrate':
combo_alg.addItems(lateralequilibrateAlg)
Expand Down Expand Up @@ -235,9 +249,13 @@ def setStorage(self,selectedProc, row):
combo_proc = table.cellWidget(row, 0)
combo_alg = table.cellWidget(row, 1)
combo_from = table.cellWidget(row, 2)
combo_to = table.cellWidget(row, 3)
combo_from2 = table.cellWidget(row,3)
combo_to = table.cellWidget(row, 4)
combo_to2 = table.cellWidget(row,5)
combo_from.clear()
combo_to.clear()
combo_from2.clear()
combo_to2.clear()



Expand Down Expand Up @@ -393,9 +411,24 @@ def setStorage(self,selectedProc, row):
#toredirectflow = self.dlg.table_hydroprocess.cellWidget(widgetRow-1,3).currentText()
combo_from.addItems(tmpanyCompartment)
combo_to.addItems(tmpanyCompartment)
elif selectedProc == 'Flush' or selectedProc == "Overflow" or selectedProc == 'Split' or selectedProc == 'LateralFlush' or selectedProc == 'LateralEquilibrate':
elif selectedProc == 'LateralFlush':
hrugroups = [x.strip() for x in self.dlg.txt_defhru.toPlainText().split(',')]
combo_from2.addItem('')
combo_to2.addItem('')
combo_from2.addItems(statevariables)
combo_to2.addItems(statevariables)
if hrugroups[0] !='':
combo_from.addItems(hrugroups)
combo_to.addItems(hrugroups)
else:
combo_from.addItem('HRUs undefined')
combo_to.addItem('HRUs undefined')

elif selectedProc == 'Flush' or selectedProc == "Overflow" or selectedProc == 'Split' or selectedProc == 'LateralEquilibrate':
if selectedProc == 'LateralEquilibrate':
tmpanyCompartment.append('AllHRUs')
elif selectedProc == 'Split':
combo_to2.addItems(tmpanyCompartment)
combo_from.addItems(tmpanyCompartment)
combo_to.addItems(tmpanyCompartment)
# table.setCellWidget(row, 2, combo_from) #Set the combobox for the from compartment
Expand All @@ -410,10 +443,10 @@ def enableConditionalProc(self,row):

table = self.dlg.table_hydroprocess

chk_isConditional = table.cellWidget(row, 4)
combo_basedtype = table.cellWidget(row, 5)
combo_comparison = table.cellWidget(row, 6)
txt_hrutype = table.cellWidget(row, 7)
chk_isConditional = table.cellWidget(row, 6)
combo_basedtype = table.cellWidget(row, 7)
combo_comparison = table.cellWidget(row, 8)
txt_hrutype = table.cellWidget(row, 9)

combo_basedtype.clear()
combo_comparison.clear()
Expand All @@ -435,8 +468,8 @@ def enableMixingRate(self, row):
# currentWidget = self.dlg.sender()
# index = self.dlg.table_hydroprocess.indexAt(currentWidget.pos())
# widgetRow = index.row()
chk_mixingrate = table.cellWidget(row, 8)
spin_pct = table.cellWidget(row, 9)
chk_mixingrate = table.cellWidget(row, 10)
spin_pct = table.cellWidget(row, 11)

spin_pct.setSingleStep(0.1)
spin_pct.setMaximum(1.0)
Expand All @@ -460,22 +493,26 @@ def getHydroProcess(self):
for col in range(cols):
currentWidget = table.cellWidget(row,col)
if isinstance(currentWidget, QComboBox):
processesList.append(currentWidget.currentText())
if col == 3:
if currentWidget.currentText() != '': #It is lateralflush and requires "To" keyword
processesList.append(currentWidget.currentText()+' To ')
else:
processesList.append(currentWidget.currentText())
elif isinstance(currentWidget, QCheckBox):
if currentWidget.isChecked():
if col == 4:
if col == 6:
processesList.append('condTrue') #The checkbox is Conditional
elif col == 8:
processesList.append('mixTrue') #The checkbox is Mixing rate
elif col == 10:
processesList.append('mixTrue') #The checkbox is Mixing rate
elif col == 12:
#processesList.append('interbasinTrue') #The checkbox is Interbasin
processesList.insert(-5,'interbasinTrue')
else:
processesList.append('False')
elif isinstance(currentWidget, QLineEdit):
processesList.append(currentWidget.text().upper())
elif isinstance(currentWidget, QDoubleSpinBox):
if table.cellWidget(row,8).isChecked() or table.cellWidget(row,0).currentText() == 'LateralEquilibrate':
if table.cellWidget(row,10).isChecked() or table.cellWidget(row,0).currentText() == 'LateralEquilibrate':
#processesList.append("{:.1f}".format(currentWidget.value()))
processesList.insert(-5,"{:.1f}".format(currentWidget.value()))
else:
Expand Down Expand Up @@ -649,6 +686,10 @@ def getHydroProcess(self):
fromConvolution = []
fromCropheatunit = ['CROP_HEAT_UNIT','']
toCropheatunit = ['CROP_HEAT_UNIT','']
statevariables = ['SURFACE_WATER','ATMOSPHERE','ATMOS_PRECIP','PONDED_WATER','SOIL','GROUNDWATER',
'CANOPY','CANOPY_SNOW','TRUNK','ROOT','DEPRESSION','WETLAND','LAKE_STORAGE','SNOW',
'SNOW_LIQ','GLACIER','GLACIER_ICE']
statevariables.sort()

anyCompartment = list(set().union(
fromPrecip,toPrecip,fromCanevp,toCanevp,fromSoilevap,toSoilevap,
Expand Down
10 changes: 5 additions & 5 deletions qraven/modules/templates/awbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def loadAwbm(self):
combo_alg.setCurrentText("PRECIP_RAVEN")
combo_from = table.cellWidget(0,2)
combo_from.setCurrentText("ATMOS_PRECIP")
combo_to = table.cellWidget(0,3)
combo_to = table.cellWidget(0,4)
combo_to.setCurrentText("MULTIPLE")

combo_proc = table.cellWidget(1,0)
Expand All @@ -39,7 +39,7 @@ def loadAwbm(self):
combo_alg.setCurrentText("SNOBAL_SIMPLE_MELT")
combo_from = table.cellWidget(1,2)
combo_from.setCurrentText("SNOW")
combo_to = table.cellWidget(1,3)
combo_to = table.cellWidget(1,4)
combo_to.setCurrentText("PONDED_WATER")

combo_proc = table.cellWidget(2,0)
Expand All @@ -48,7 +48,7 @@ def loadAwbm(self):
combo_alg.setCurrentText("INF_AWBM")
combo_from = table.cellWidget(2,2)
combo_from.setCurrentText("PONDED_WATER")
combo_to = table.cellWidget(2,3)
combo_to = table.cellWidget(2,4)
combo_to.setCurrentText("MULTIPLE")

combo_proc = table.cellWidget(3,0)
Expand All @@ -57,7 +57,7 @@ def loadAwbm(self):
combo_alg.setCurrentText("SOILEVAP_AWBM")
combo_from = table.cellWidget(3,2)
combo_from.setCurrentText("MULTIPLE")
combo_to = table.cellWidget(3,3)
combo_to = table.cellWidget(3,4)
combo_to.setCurrentText("ATMOSPHERE")

combo_proc = table.cellWidget(4,0)
Expand All @@ -66,7 +66,7 @@ def loadAwbm(self):
combo_alg.setCurrentText("BASE_LINEAR")
combo_from = table.cellWidget(4,2)
combo_from.setCurrentText("SOIL[3]")
combo_to = table.cellWidget(4,3)
combo_to = table.cellWidget(4,4)
combo_to.setCurrentText("SURFACE_WATER")


Expand Down
30 changes: 15 additions & 15 deletions qraven/modules/templates/canshield.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("FREEZE_DEGREE_DAY")
combo_from = table.cellWidget(0,2)
combo_from.setCurrentText("SNOW_LIQ")
combo_to = table.cellWidget(0,3)
combo_to = table.cellWidget(0,4)
combo_to.setCurrentText("SNOW")

combo_proc = table.cellWidget(1,0)
Expand All @@ -40,7 +40,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("PRECIP_RAVEN")
combo_from = table.cellWidget(1,2)
combo_from.setCurrentText("ATMOS_PRECIP")
combo_to = table.cellWidget(1,3)
combo_to = table.cellWidget(1,4)
combo_to.setCurrentText("MULTIPLE")

combo_proc = table.cellWidget(2,0)
Expand All @@ -49,7 +49,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("CANEVP_MAXIMUM")
combo_from = table.cellWidget(2,2)
combo_from.setCurrentText("CANOPY")
combo_to = table.cellWidget(2,3)
combo_to = table.cellWidget(2,4)
combo_to.setCurrentText("ATMOSPHERE")

combo_proc = table.cellWidget(3,0)
Expand All @@ -58,7 +58,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("SUBLIM_MAXIMUM")
combo_from = table.cellWidget(3,2)
combo_from.setCurrentText("CANOPY_SNOW")
combo_to = table.cellWidget(3,3)
combo_to = table.cellWidget(3,4)
combo_to.setCurrentText("ATMOSPHERE")

combo_proc = table.cellWidget(4,0)
Expand All @@ -67,7 +67,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("SNOBAL_TWO_LAYER")
combo_from = table.cellWidget(4,2)
combo_from.setCurrentText("MULTIPLE")
combo_to = table.cellWidget(4,3)
combo_to = table.cellWidget(4,4)
combo_to.setCurrentText("MULTIPLE")

combo_proc = table.cellWidget(5,0)
Expand All @@ -76,7 +76,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("ABST_FILL")
combo_from = table.cellWidget(5,2)
combo_from.setCurrentText("PONDED_WATER")
combo_to = table.cellWidget(5,3)
combo_to = table.cellWidget(5,4)
combo_to.setCurrentText("DEPRESSION")

combo_proc = table.cellWidget(6,0)
Expand All @@ -85,7 +85,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("OPEN_WATER_EVAP")
combo_from = table.cellWidget(6,2)
combo_from.setCurrentText("DEPRESSION")
combo_to = table.cellWidget(6,3)
combo_to = table.cellWidget(6,4)
combo_to.setCurrentText("ATMOSPHERE")

combo_proc = table.cellWidget(7,0)
Expand All @@ -94,7 +94,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("INF_HBV")
combo_from = table.cellWidget(7,2)
combo_from.setCurrentText("PONDED_WATER")
combo_to = table.cellWidget(7,3)
combo_to = table.cellWidget(7,4)
combo_to.setCurrentText("MULTIPLE")

combo_proc = table.cellWidget(8,0)
Expand All @@ -103,7 +103,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("LAKEREL_LINEAR")
combo_from = table.cellWidget(8,2)
combo_from.setCurrentText("LAKE_STORAGE")
combo_to = table.cellWidget(8,3)
combo_to = table.cellWidget(8,4)
combo_to.setCurrentText("SURFACE_WATER")

combo_proc = table.cellWidget(9,0)
Expand All @@ -112,7 +112,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("SOILEVAP_ROOT")
combo_from = table.cellWidget(9,2)
combo_from.setCurrentText("SOIL[0]")
combo_to = table.cellWidget(9,3)
combo_to = table.cellWidget(9,4)
combo_to.setCurrentText("ATMOSPHERE")

combo_proc = table.cellWidget(10,0)
Expand All @@ -121,7 +121,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("PERC_GAWSER_CONSTRAIN")
combo_from = table.cellWidget(10,2)
combo_from.setCurrentText("SOIL[0]")
combo_to = table.cellWidget(10,3)
combo_to = table.cellWidget(10,4)
combo_to.setCurrentText("SOIL[1]")

combo_proc = table.cellWidget(11,0)
Expand All @@ -130,7 +130,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("PERC_GAWSER_CONSTRAIN")
combo_from = table.cellWidget(11,2)
combo_from.setCurrentText("SOIL[1]")
combo_to = table.cellWidget(11,3)
combo_to = table.cellWidget(11,4)
combo_to.setCurrentText("SOIL[2]")

combo_proc = table.cellWidget(12,0)
Expand All @@ -139,7 +139,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("BASE_THRESH_POWER")
combo_from = table.cellWidget(12,2)
combo_from.setCurrentText("SOIL[0]")
combo_to = table.cellWidget(12,3)
combo_to = table.cellWidget(12,4)
combo_to.setCurrentText("SURFACE_WATER")

combo_proc = table.cellWidget(13,0)
Expand All @@ -148,7 +148,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("BASE_THRESH_POWER")
combo_from = table.cellWidget(13,2)
combo_from.setCurrentText("SOIL[1]")
combo_to = table.cellWidget(13,3)
combo_to = table.cellWidget(13,4)
combo_to.setCurrentText("SURFACE_WATER")

combo_proc = table.cellWidget(14,0)
Expand All @@ -157,7 +157,7 @@ def loadCanshield(self):
combo_alg.setCurrentText("BASE_THRESH_POWER")
combo_from = table.cellWidget(14,2)
combo_from.setCurrentText("SOIL[2]")
combo_to = table.cellWidget(14,3)
combo_to = table.cellWidget(14,4)
combo_to.setCurrentText("SURFACE_WATER")

table.resizeColumnsToContents() #Resizes the width of the column automatically
Expand Down
Loading

0 comments on commit 0d2f1f5

Please sign in to comment.