Skip to content

Commit e7d8ca2

Browse files
authored
Merge pull request #36 from respec/develop, with Unit Testing
Merge Unit testing work from RESPEC
2 parents 1fdd6b6 + 5cff834 commit e7d8ca2

29 files changed

+2452
-3551
lines changed

.gitignore

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ __pycache__/*
3434
htmlcov
3535
.tox
3636
.tox/*
37-
.coverage
38-
.coverage/*
3937

40-
# Translations
41-
*.mo
42-
43-
44-
# Stashes, etc.
45-
.hg
46-
*.tmp*
47-
tests/_LargeFileStash
38+
stats.dat
39+
.ropeproject
40+
.idea
41+
*.ech
42+
*.log
43+
*.hbnhead
44+
*.units.dbf

HSP2/ADCALC.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'''
55

66
from numpy import zeros
7+
from numba import njit
78
from HSP2.utilities import make_numba_dict
89

910
# The clean way to get calculated data from adcalc() into advert() is to use a closure.
@@ -127,7 +128,7 @@ def adcalc_(simlen, delts, nexits, crrat, ks, vol, ADFG, O, VOL, SROVOL, EROVOL,
127128
return
128129

129130

130-
#@jit(nopython=True)
131+
#@njit(cache=True)
131132
def advect(imat, conc, nexits, vols, vol, srovol, erovol, sovol, eovol):
132133
''' Simulate advection of constituent totally entrained in water.
133134
Originally designed to be called as: advect(loop, imat, conc, omat, *ui['adcalcData'])
@@ -140,9 +141,7 @@ def advect(imat, conc, nexits, vols, vol, srovol, erovol, sovol, eovol):
140141
# sovol = SOVOL[loop,:]
141142
# eovol = EOVOL[loop,:]
142143

143-
omat = 0.0
144-
if nexits > 1:
145-
omat = zeros((nexits))
144+
omat = zeros((nexits))
146145
if vol > 0.0: # reach/res contains water
147146
concs = conc
148147
conc = (imat + concs * (vols - srovol)) / (vol + erovol) # material entering during interval, weighted volume of outflow based on conditions at start of ivl (srovol), and weighted volume of outflow based on conditions at end of ivl (erovol)

HSP2/GQUAL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def advqal(isqal,rsed,bsed,depscr,rosed,osed,nexits,rsqals,rbqals,errors):
12451245
if bsed <= 0.0: # no bed sediments at end of interval
12461246
bqal = -1.0e30
12471247
if abs(dsqal) > 0.0 or abs(rbqals > 0.0):
1248-
errors[4] += 1 # ERRMSG4: error-under these conditions these values should be zero
1248+
errors[5] += 1 # ERRMSG4: error-under these conditions these values should be zero
12491249
else: # there is bed sediment at the end of the interval
12501250
rbqal= dsqal + rbqals
12511251
bqal = rbqal / bsed

HSP2/HTRCH.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
0.0026, 0.0026, 0.0027, 0.0027, 0.0028, 0.0028, 0.0027, 0.0026, 0.0024, 0.0023, 0.0022,
3535
0.0021, 0.0021, 0.0020]
3636

37-
ERRMSG = []
37+
ERRMSGS =('HTRCH: Water temperature is above 66 C (150 F) -- In most cases, this indicates an instability in advection','') #ERRMSG0
3838

3939
def htrch(store, siminfo, uci, ts):
4040
'''Simulate heat exchange and water temperature'''
4141

42-
errorsV = zeros(len(ERRMSG), dtype=int)
42+
errorsV = zeros(len(ERRMSGS), dtype=int)
4343

4444
advectData = uci['advectData']
4545
(nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL) = advectData
@@ -172,7 +172,7 @@ def htrch(store, siminfo, uci, ts):
172172

173173
if tw > 66.0:
174174
if adfg < 2:
175-
# errormsg: 'advect:tw problem ',dtw, airtmp
175+
errorsV[0] += 1 # Water temperature is above 66 C (150 F). In most cases, this indicates an instability in advection.
176176
rtw = tw
177177
else:
178178
tw = tws
@@ -369,7 +369,7 @@ def htrch(store, siminfo, uci, ts):
369369
for i in range(nexits):
370370
ts['OHEAT' + str(i+1)] = OHEAT[:, i]
371371

372-
return errorsV, ERRMSG
372+
return errorsV, ERRMSGS
373373

374374
def vapor(tmp):
375375
''' # define vapor function based on temperature (deg c); vapor pressure is expressed in millibars'''

HSP2/IQUAL.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
UNDEFINED: sliqsp
2020
'''
2121

22-
ERRMSG = []
22+
ERRMSGS =('IQUAL: A constituent must be associated with overland flow in order to receive atmospheric deposition inputs','') #ERRMSG0
2323

2424
def iqual(store, siminfo, uci, ts):
2525
''' Simulate washoff of quality constituents (other than solids, Heat, dox, and co2)
@@ -35,7 +35,7 @@ def iqual(store, siminfo, uci, ts):
3535
flags = uci['IQUAL' + iqual + '_FLAGS']
3636
constituents.append(flags['QUALID'])
3737

38-
errorsV = zeros(len(ERRMSG), dtype=int)
38+
errorsV = zeros(len(ERRMSGS), dtype=int)
3939
delt60 = siminfo['delt'] / 60 # delt60 - simulation time interval in hours
4040
simlen = siminfo['steps']
4141
tindex = siminfo['tindex']
@@ -118,6 +118,9 @@ def iqual(store, siminfo, uci, ts):
118118
elif iqadfgc == -1:
119119
ts['IQADCN'] = ts['IQADCN' + str(index) + ' 1']
120120

121+
if QSOFG == 0 and (iqadfgf != 0 or iqadfgc != 0):
122+
errorsV[0] += 1 # error - non-qualof cannot have atmospheric deposition
123+
121124
if 'IQADFX' not in ts:
122125
ts['IQADFX'] = zeros(simlen)
123126
if 'IQADCN' not in ts:
@@ -229,5 +232,5 @@ def iqual(store, siminfo, uci, ts):
229232
IQADDR[loop] = adfxfx
230233
IQADEP[loop] = adtot
231234

232-
return errorsV, ERRMSG
235+
return errorsV, ERRMSGS
233236

HSP2/IWTGAS.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,23 @@ def iwtgas(store, siminfo, uci, ts):
125125
if slico2 >= 0.0: # there is co2 conc of surface lateral inflow
126126
soco2 = slico2 * slifac + soco2 * (1.0 - slifac)
127127

128+
SOHT[loop] = sotmp * suro * EFACTA # compute outflow of heat energy in water - units are deg. c-in./ivl
129+
SODOXM[loop] = sodox * suro * MFACTA # calculate outflow mass of dox - units are mg-in./l-ivl
130+
SOCO2M[loop] = soco2 * suro * MFACTA # calculate outflow mass of co2 - units are mg-in./l-ivl
131+
SOTMP[loop] = (sotmp * 9.0 / 5.0) + 32.0
132+
SODOX[loop] = sodox
133+
SOCO2[loop] = soco2
134+
128135
else:
129136
sotmp = -1.0e30
130137
sodox = -1.0e30
131138
soco2 = -1.0e30
132139

133-
SOHT[loop] = sotmp * suro * EFACTA # compute outflow of heat energy in water - units are deg. c-in./ivl
134-
SODOXM[loop] = sodox * suro * MFACTA # calculate outflow mass of dox - units are mg-in./l-ivl
135-
SOCO2M[loop] = soco2 * suro * MFACTA # calculate outflow mass of co2 - units are mg-in./l-ivl
136-
137-
SOTMP[loop] = (sotmp * 9.0 / 5.0) + 32.0
138-
SODOX[loop] = sodox
139-
SOCO2[loop] = soco2
140+
SOHT[loop] = 0.0
141+
SODOXM[loop] = 0.0
142+
SOCO2M[loop] = 0.0
143+
SOTMP[loop] = sotmp
144+
SODOX[loop] = sodox
145+
SOCO2[loop] = soco2
140146

141147
return errorsV, ERRMSG

HSP2/PQUAL.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
NEED to check all units conversions
1717
'''
1818

19-
ERRMSG = []
19+
ERRMSGS =('PQUAL: A constituent must be associated with overland flow in order to receive atmospheric deposition inputs','') #ERRMSG0
2020

2121
# english system
2222
FACTA = 1.0
@@ -38,7 +38,7 @@ def pqual(store, siminfo, uci, ts):
3838
flags = uci['PQUAL' + pqual + '_FLAGS']
3939
constituents.append(flags['QUALID'])
4040

41-
errorsV = zeros(len(ERRMSG), dtype=int)
41+
errorsV = zeros(len(ERRMSGS), dtype=int)
4242
delt60 = siminfo['delt'] / 60 # delt60 - simulation time interval in hours
4343
simlen = siminfo['steps']
4444
tindex = siminfo['tindex']
@@ -138,6 +138,9 @@ def pqual(store, siminfo, uci, ts):
138138
elif pqadfgc == -1:
139139
ts['PQADCN'] = ts['PQADCN' + str(index) + ' 1']
140140

141+
if QSOFG == 0 and (pqadfgf != 0 or pqadfgc != 0):
142+
errorsV[0] += 1 # error - non-qualof cannot have atmospheric deposition
143+
141144
if 'PQADFX' not in ts:
142145
ts['PQADFX'] = zeros(simlen)
143146
if 'PQADCN' not in ts:
@@ -329,5 +332,5 @@ def pqual(store, siminfo, uci, ts):
329332
PQADDR[loop] = adfxfx
330333
PQADEP[loop] = adtot
331334

332-
return errorsV, ERRMSG
335+
return errorsV, ERRMSGS
333336

HSP2/PSTEMP.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from HSP2.utilities import hoursval, initm, make_numba_dict
1212

1313

14-
ERRMSG = ['SLTMP temperature less than 100C', # MSG0
15-
'ULTMP temperature less than 100C', # MSG1
16-
'LGTMP temperature less than 100C', # MSG2
14+
ERRMSG = ['SLTMP temperature less than -100C', # MSG0
15+
'ULTMP temperature less than -100C', # MSG1
16+
'LGTMP temperature less than -100C', # MSG2
1717
'SLTMP temperature greater than 100C', # MSG3
1818
'ULTMP temperature greater than 100C', # MSG4
1919
'LGTMP temperature greater than 100C'] # MSG5

HSP2/PWATER.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'PWATER: Proute runoff did not converge', #ERRMSG6
2222
'PWATER: UZI highly negative', #ERRMSG7
2323
'PWATER: Reset AGWS to zero', #ERRMSG8
24-
'PWATER: High Water Table code not implimented', #ERRMSG9
24+
'PWATER: High Water Table code not implemented', #ERRMSG9
2525
)
2626

2727
def pwater(store, siminfo, uci, ts):

HSP2/SEDTRN.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
from HSP2.ADCALC import advect
99
from HSP2.utilities import make_numba_dict
1010

11-
ERRMSG = []
11+
ERRMSGS =('SEDTRN: Warning -- bed storage of sediment size fraction sand is empty', #ERRMSG0
12+
'SEDTRN: Warning -- bed storage of sediment size fraction silt is empty', #ERRMSG1
13+
'SEDTRN: Warning -- bed storage of sediment size fraction clay is empty', #ERRMSG2
14+
'SEDTRN: Warning -- bed depth appears excessive', #ERRMSG3
15+
'SEDTRN: Fatal error ocurred in colby method- variable outside valid range- switching to toffaleti method', #ERRMSG4
16+
'SEDTRN: Simulation of sediment requires all 3 "auxiliary flags" (AUX1FG, etc) in section HYDR must be turned on', #ERRMSG5
17+
'SEDTRN: When specifying the initial composition of the bed, the fraction of sand, silt, and clay must sum to a value close to 1.0.') #ERRMSG6
1218

1319
def sedtrn(store, siminfo, uci, ts):
1420
''' Simulate behavior of inorganic sediment'''
1521

16-
errorsV = zeros(len(ERRMSG), dtype=int)
22+
errorsV = zeros(len(ERRMSGS), dtype=int)
1723

1824
simlen = siminfo['steps']
1925
delt = siminfo['delt']
@@ -31,6 +37,9 @@ def sedtrn(store, siminfo, uci, ts):
3137
# table SANDFG
3238
sandfg = ui['SANDFG'] # 1: Toffaleti method, 2:Colby method, 3:old HSPF power function
3339

40+
if ui['AUX3FG'] == 0:
41+
errorsV[5] += 1 # error - sediment transport requires aux3fg to be on
42+
3443
# table SED-GENPARM
3544
bedwid = ui['BEDWID']
3645
bedwrn = ui['BEDWRN']
@@ -99,7 +108,7 @@ def sedtrn(store, siminfo, uci, ts):
99108
clay_bedfr = ui['CLAYFR']
100109
total_bedfr = sand_bedfr + silt_bedfr + clay_bedfr
101110
if abs(total_bedfr - 1.0) > 0.01:
102-
pass # error message: sum of bed sediment fractions is not close enough to 1.0
111+
errorsV[6] += 1 # error message: sum of bed sediment fractions is not close enough to 1.0
103112

104113
# suspended sediment concentrations; table ssed-init
105114
sand_ssed1 = ui['SSED1']
@@ -390,17 +399,20 @@ def sedtrn(store, siminfo, uci, ts):
390399
osed4 += osed1
391400
sand_rssed1 = sand_t_rsed7 = sand_rsed1 + sand_wt_rsed4 # total storage in mg.vol/l
392401
if sand_wt_rsed4 == 0.0: # warn that bed is empty
393-
pass # errmsg
402+
# errmsg
403+
errorsV[0] += 1 # The bed storage of sediment size fraction sand is empty.
394404

395405
osed4 += osed2
396406
silt_rssed2 = silt_t_rsed8 = silt_rsed2 + silt_wt_rsed5 # total storage in mg.vol/l
397407
if silt_wt_rsed5 == 0.0: # warn that bed is empty
398-
pass # errmsg
408+
# errmsg
409+
errorsV[1] += 1 # The bed storage of sediment size fraction silt is empty.
399410

400411
osed4 += osed3
401412
clay_rssed3 = clay_t_rsed9 = clay_rsed3 + clay_wt_rsed6 # total storage in mg.vol/l
402413
if clay_wt_rsed6 == 0.0: # warn that bed is empty
403-
pass # errmsg
414+
# errmsg
415+
errorsV[2] += 1 # The bed storage of sediment size fraction clay is empty.
404416

405417
# find the volume occupied by each fraction of bed sediment- ft3 or m3
406418
volsed = (sand_wt_rsed4 / (sand_rho * 1.0e06)
@@ -418,7 +430,8 @@ def sedtrn(store, siminfo, uci, ts):
418430
volsed = volsed / (1.0 - por) # allow for porosit
419431
beddep = volsed / (len_ * bedwid) # calculate thickness of bed- ft or m
420432
if beddep > bedwrn:
421-
pass # Errormsg: warn that bed depth appears excessive
433+
# Errormsg: warn that bed depth appears excessive
434+
errorsV[3] += 1
422435

423436
svol = vol # svol is volume at start of time step, update for next time thru
424437

@@ -487,7 +500,7 @@ def sedtrn(store, siminfo, uci, ts):
487500
ts['OSED3' + str(i + 1)] = OSED3[:, i]
488501
ts['OSED4' + str(i + 1)] = OSED4[:, i]
489502

490-
return errorsV, ERRMSG
503+
return errorsV, ERRMSGS
491504

492505

493506
def bdexch (avdepm, w, tau, taucd, taucs, m, vol, frcsed, susp, bed):
@@ -644,8 +657,8 @@ def colby(v, db50, fhrad, fsl, tempr):
644657
if vx > v:
645658
break
646659
iv2 = iv1 + 1
647-
yy1 = log10(VG[iv1])
648-
yy2 = log10(VG[iv2])
660+
yy1 = log10(VG[iv1-1])
661+
yy2 = log10(VG[iv2-1])
649662
yyratio = (log10(v) - yy1) / (yy2 - yy1)
650663

651664
tmpr = min(100.0, max(32.0, tempr * 1.8 + 32.0))

0 commit comments

Comments
 (0)