Skip to content

Commit eb844a7

Browse files
committed
Refactor "uci" names.
* In some places "uci" would describe "parameters" and in other places would describe "model". Changed as appropriate. * Applied "ruff check --fix ." safe fixes. * Applied "ruff format .".
1 parent ab1ef2a commit eb844a7

40 files changed

+672
-512
lines changed

src/hsp2/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
"""The Hydrologic Simulation Program - Python (HSP2) watershed model is is a
2-
port of the well-established Hydrological Simulation Program - FORTRAN (HSPF),
3-
re-coded with modern scientific Python and data formats.
1+
"""The Hydrologic Simulation Program - Python (HSP2) watershed model is is a
2+
port of the well-established Hydrological Simulation Program - FORTRAN (HSPF),
3+
re-coded with modern scientific Python and data formats.
44
5-
Modules:
6-
- HSP2 contains the hydrology and water quality code modules converted from
7-
HSPF, along with the main programs to run HSP2.
8-
- HSP2tools contains supporting software modules such as the code to convert
9-
legacy WDM and UCI files to HDF5 files for HSP2, and to provide additional
10-
new and legacy capabilities.
11-
- HSP2IO is new in v0.10 and contains an abstracted approach to getting data
12-
in and out of HSP2 for flexibility and performance and also to support future
13-
automation and model coupling.
5+
Modules:
6+
- HSP2 contains the hydrology and water quality code modules converted from
7+
HSPF, along with the main programs to run HSP2.
8+
- HSP2tools contains supporting software modules such as the code to convert
9+
legacy WDM and UCI files to HDF5 files for HSP2, and to provide additional
10+
new and legacy capabilities.
11+
- HSP2IO is new in v0.10 and contains an abstracted approach to getting data
12+
in and out of HSP2 for flexibility and performance and also to support future
13+
automation and model coupling.
1414
"""
1515

1616
from importlib.metadata import version, PackageNotFoundError
@@ -19,5 +19,8 @@
1919
__version__ = version("hsp2")
2020
except PackageNotFoundError:
2121
import os
22-
with open(os.path.join(os.path.dirname(__file__),"../..", "VERSION"), encoding="ascii") as version_file:
22+
23+
with open(
24+
os.path.join(os.path.dirname(__file__), "../..", "VERSION"), encoding="ascii"
25+
) as version_file:
2326
__version__ = version_file.read().strip()

src/hsp2/hsp2/ADCALC.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
from numba import njit
11-
from numpy import array, zeros
11+
from numpy import zeros
1212

1313
from hsp2.hsp2.utilities import make_numba_dict
1414

@@ -18,14 +18,14 @@
1818
ERRMSG = []
1919

2020

21-
def adcalc(io_manager, siminfo, uci, ts):
21+
def adcalc(io_manager, siminfo, parameter, ts):
2222
"""Prepare to simulate advection of fully entrained constituents"""
2323

2424
errorsV = zeros(len(ERRMSG), dtype=int)
2525

2626
simlen = siminfo["steps"]
2727

28-
ui = make_numba_dict(uci)
28+
ui = make_numba_dict(parameter)
2929
nexits = int(ui["NEXITS"]) # table type GEN-INFO
3030
ui["simlen"] = siminfo["steps"]
3131
ui["delts"] = siminfo["delt"] * 60.0 # delts is the simulation interval in seconds
@@ -55,7 +55,7 @@ def adcalc(io_manager, siminfo, uci, ts):
5555
SOVOL[:, i] = ts["SOVOL" + str(i + 1)]
5656
EOVOL[:, i] = ts["EOVOL" + str(i + 1)]
5757

58-
uci["adcalcData"] = (nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL)
58+
parameter["adcalcData"] = (nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL)
5959

6060
return errorsV, ERRMSG
6161

src/hsp2/hsp2/ATEMP.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
from numpy import empty, int64, zeros
88

99
from hsp2.hsp2.utilities import LAPSE, hoursval, make_numba_dict
10-
from hsp2.hsp2io.protocols import Category, SupportsReadTS
10+
from hsp2.hsp2io.protocols import SupportsReadTS
1111

1212
ERRMSGS = ()
1313

1414

15-
def atemp(io_manager: SupportsReadTS, siminfo, uci, ts):
15+
def atemp(io_manager: SupportsReadTS, siminfo, parameters, ts):
1616
"""high level driver for air temperature module"""
1717

1818
ts["LAPSE"] = hoursval(siminfo, LAPSE, lapselike=True)
1919

20-
ui = make_numba_dict(uci) # Note: all values coverted to float automatically
20+
ui = make_numba_dict(parameters) # Note: all values coverted to float automatically
2121
ui["k"] = siminfo["delt"] * 0.000833 # convert to in/timestep
2222
ui["steps"] = siminfo["steps"]
2323
ui["errlen"] = len(ERRMSGS)

src/hsp2/hsp2/CONS.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
ERRMSG = []
2727

2828

29-
def cons(io_manager, siminfo, uci, ts):
29+
def cons(io_manager, siminfo, parameters, ts):
3030
"""Simulate behavior of conservative constituents; calculate concentration
3131
of conservative constituents after advection"""
3232

@@ -40,7 +40,7 @@ def cons(io_manager, siminfo, uci, ts):
4040
# si units conversion constants, 1 hectare is 10000 sq m
4141
AFACT = 1000000.0
4242

43-
advectData = uci["advectData"]
43+
advectData = parameters["advectData"]
4444
(nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL) = advectData
4545
svol = vol * AFACT
4646

@@ -51,7 +51,7 @@ def cons(io_manager, siminfo, uci, ts):
5151
ts["SOVOL" + str(i + 1)] = SOVOL[:, i]
5252
ts["EOVOL" + str(i + 1)] = EOVOL[:, i]
5353

54-
ui = make_numba_dict(uci)
54+
ui = make_numba_dict(parameters)
5555
nexits = int(ui["NEXITS"])
5656

5757
ui["simlen"] = siminfo["steps"]
@@ -63,13 +63,13 @@ def cons(io_manager, siminfo, uci, ts):
6363
# conactive = ui['CONACTIVE'] # dict
6464

6565
ncons = 1
66-
if "PARAMETERS" in uci:
67-
if "NCONS" in uci["PARAMETERS"]:
68-
ncons = uci["PARAMETERS"]["NCONS"]
66+
if "PARAMETERS" in parameters:
67+
if "NCONS" in parameters["PARAMETERS"]:
68+
ncons = parameters["PARAMETERS"]["NCONS"]
6969

7070
for index in range(ncons):
7171
icon = str(index + 1)
72-
parms = uci["CONS" + icon]
72+
parms = parameters["CONS" + icon]
7373
conid = parms["CONID"] # string name of the conservative constituent
7474
con = parms["CON"] # initial concentration of the conservative
7575
concid = parms[
@@ -92,21 +92,29 @@ def cons(io_manager, siminfo, uci, ts):
9292
# COADFG2 = ui['COADFG2'] # table-type cons-ad-flags
9393
# COADCN = getit() # flag: COADFG; monthly COACNM; value COADCN
9494

95-
if "FLAGS" in uci:
96-
u = uci["FLAGS"]
95+
if "FLAGS" in parameters:
96+
u = parameters["FLAGS"]
9797
# get atmos dep timeseries
9898
coadfg1 = u["COADFG" + str((index * 2) - 1)]
9999
if coadfg1 > 0:
100100
ts["COADFX"] = initm(
101-
siminfo, uci, coadfg1, "CONS" + str(index) + "_MONTHLY/COADFX", 0.0
101+
siminfo,
102+
parameters,
103+
coadfg1,
104+
"CONS" + str(index) + "_MONTHLY/COADFX",
105+
0.0,
102106
)
103107
elif coadfg1 == -1:
104108
ts["COADFX"] = ts["COADFX" + str(index)]
105109

106110
coadfg2 = u["COADFG" + str(index * 2)]
107111
if coadfg2 > 0:
108112
ts["COADCN"] = initm(
109-
siminfo, uci, coadfg2, "CONS" + str(index) + "_MONTHLY/COADCN", 0.0
113+
siminfo,
114+
parameters,
115+
coadfg2,
116+
"CONS" + str(index) + "_MONTHLY/COADCN",
117+
0.0,
110118
)
111119
elif coadfg2 == -1:
112120
ts["COADCN"] = ts["COADCN" + str(index)]
@@ -121,7 +129,7 @@ def cons(io_manager, siminfo, uci, ts):
121129
############################################################################
122130

123131
if nexits > 1:
124-
u = uci["SAVE"]
132+
u = parameters["SAVE"]
125133
key1 = name + "_OCON"
126134
for i in range(nexits):
127135
u[f"{key1}{i + 1}"] = u["OCON"]
@@ -226,12 +234,12 @@ def _cons_(ui, ts):
226234
return
227235

228236

229-
def expand_CONS_masslinks(flags, uci, dat, recs):
237+
def expand_CONS_masslinks(flags, parameters, dat, recs):
230238
if flags["CONS"]:
231239
ncons = 1
232-
if "PARAMETERS" in uci:
233-
if "NCONS" in uci["PARAMETERS"]:
234-
ncons = uci["PARAMETERS"]["NCONS"]
240+
if "PARAMETERS" in parameters:
241+
if "NCONS" in parameters["PARAMETERS"]:
242+
ncons = parameters["PARAMETERS"]["NCONS"]
235243
for i in range(1, ncons + 1):
236244
# ICONS loop for each cons
237245
rec = {}

src/hsp2/hsp2/GENER.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878
self.ts_input_1 = tsin["ONE"]
7979
if "TWO" in tsin:
8080
self.ts_input_2 = tsin["TWO"]
81-
if not "ONE" in tsin and not "TWO" in tsin:
81+
if "ONE" not in tsin and "TWO" not in tsin:
8282
raise NotImplementedError(f"Invalid SVOL for '{link.SVOLNO}'")
8383

8484
if link.SVOL == "COPY" or link.SVOL == "GENER":
@@ -153,9 +153,17 @@ def _opcode7(self) -> pd.Series:
153153
def _opcode8(self) -> pd.Series:
154154
# K(1) + K(2) * A + K(3) * A ** 2
155155
# The user supplies the number of terms and the values of coefficients (K)
156-
return ((self.k1 + (self.k2 * self.ts_input_1) + (self.k3 * (self.ts_input_1 ** 2))
157-
+ (self.k4 * (self.ts_input_1 ** 3))) + (self.k5 * (self.ts_input_1 ** 4))
158-
+ (self.k6 * (self.ts_input_1 ** 7)) + (self.k7 * (self.ts_input_1 ** 8)))
156+
return (
157+
(
158+
self.k1
159+
+ (self.k2 * self.ts_input_1)
160+
+ (self.k3 * (self.ts_input_1**2))
161+
+ (self.k4 * (self.ts_input_1**3))
162+
)
163+
+ (self.k5 * (self.ts_input_1**4))
164+
+ (self.k6 * (self.ts_input_1**7))
165+
+ (self.k7 * (self.ts_input_1**8))
166+
)
159167

160168
def _opcode9(self) -> pd.Series:
161169
return np.power(self.k, self.ts_input_1)

0 commit comments

Comments
 (0)