Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/hsp2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""The Hydrologic Simulation Program - Python (HSP2) watershed model is is a
port of the well-established Hydrological Simulation Program - FORTRAN (HSPF),
re-coded with modern scientific Python and data formats.
"""The Hydrologic Simulation Program - Python (HSP2) watershed model is is a
port of the well-established Hydrological Simulation Program - FORTRAN (HSPF),
re-coded with modern scientific Python and data formats.

Modules:
- HSP2 contains the hydrology and water quality code modules converted from
HSPF, along with the main programs to run HSP2.
- HSP2tools contains supporting software modules such as the code to convert
legacy WDM and UCI files to HDF5 files for HSP2, and to provide additional
new and legacy capabilities.
- HSP2IO is new in v0.10 and contains an abstracted approach to getting data
in and out of HSP2 for flexibility and performance and also to support future
automation and model coupling.
Modules:
- HSP2 contains the hydrology and water quality code modules converted from
HSPF, along with the main programs to run HSP2.
- HSP2tools contains supporting software modules such as the code to convert
legacy WDM and UCI files to HDF5 files for HSP2, and to provide additional
new and legacy capabilities.
- HSP2IO is new in v0.10 and contains an abstracted approach to getting data
in and out of HSP2 for flexibility and performance and also to support future
automation and model coupling.
"""

from importlib.metadata import version, PackageNotFoundError
Expand All @@ -19,5 +19,8 @@
__version__ = version("hsp2")
except PackageNotFoundError:
import os
with open(os.path.join(os.path.dirname(__file__),"../..", "VERSION"), encoding="ascii") as version_file:

with open(
os.path.join(os.path.dirname(__file__), "../..", "VERSION"), encoding="ascii"
) as version_file:
__version__ = version_file.read().strip()
8 changes: 4 additions & 4 deletions src/hsp2/hsp2/ADCALC.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

from numba import njit
from numpy import array, zeros
from numpy import zeros

from hsp2.hsp2.utilities import make_numba_dict

Expand All @@ -18,14 +18,14 @@
ERRMSG = []


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

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

simlen = siminfo["steps"]

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

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

return errorsV, ERRMSG

Expand Down
6 changes: 3 additions & 3 deletions src/hsp2/hsp2/ATEMP.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
from numpy import empty, int64, zeros

from hsp2.hsp2.utilities import LAPSE, hoursval, make_numba_dict
from hsp2.hsp2io.protocols import Category, SupportsReadTS
from hsp2.hsp2io.protocols import SupportsReadTS

ERRMSGS = ()


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

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

ui = make_numba_dict(uci) # Note: all values coverted to float automatically
ui = make_numba_dict(parameters) # Note: all values coverted to float automatically
ui["k"] = siminfo["delt"] * 0.000833 # convert to in/timestep
ui["steps"] = siminfo["steps"]
ui["errlen"] = len(ERRMSGS)
Expand Down
40 changes: 24 additions & 16 deletions src/hsp2/hsp2/CONS.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ERRMSG = []


def cons(io_manager, siminfo, uci, ts):
def cons(io_manager, siminfo, parameters, ts):
"""Simulate behavior of conservative constituents; calculate concentration
of conservative constituents after advection"""

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

advectData = uci["advectData"]
advectData = parameters["advectData"]
(nexits, vol, VOL, SROVOL, EROVOL, SOVOL, EOVOL) = advectData
svol = vol * AFACT

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

ui = make_numba_dict(uci)
ui = make_numba_dict(parameters)
nexits = int(ui["NEXITS"])

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

ncons = 1
if "PARAMETERS" in uci:
if "NCONS" in uci["PARAMETERS"]:
ncons = uci["PARAMETERS"]["NCONS"]
if "PARAMETERS" in parameters:
if "NCONS" in parameters["PARAMETERS"]:
ncons = parameters["PARAMETERS"]["NCONS"]

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

if "FLAGS" in uci:
u = uci["FLAGS"]
if "FLAGS" in parameters:
u = parameters["FLAGS"]
# get atmos dep timeseries
coadfg1 = u["COADFG" + str((index * 2) - 1)]
if coadfg1 > 0:
ts["COADFX"] = initm(
siminfo, uci, coadfg1, "CONS" + str(index) + "_MONTHLY/COADFX", 0.0
siminfo,
parameters,
coadfg1,
"CONS" + str(index) + "_MONTHLY/COADFX",
0.0,
)
elif coadfg1 == -1:
ts["COADFX"] = ts["COADFX" + str(index)]

coadfg2 = u["COADFG" + str(index * 2)]
if coadfg2 > 0:
ts["COADCN"] = initm(
siminfo, uci, coadfg2, "CONS" + str(index) + "_MONTHLY/COADCN", 0.0
siminfo,
parameters,
coadfg2,
"CONS" + str(index) + "_MONTHLY/COADCN",
0.0,
)
elif coadfg2 == -1:
ts["COADCN"] = ts["COADCN" + str(index)]
Expand All @@ -121,7 +129,7 @@ def cons(io_manager, siminfo, uci, ts):
############################################################################

if nexits > 1:
u = uci["SAVE"]
u = parameters["SAVE"]
key1 = name + "_OCON"
for i in range(nexits):
u[f"{key1}{i + 1}"] = u["OCON"]
Expand Down Expand Up @@ -226,12 +234,12 @@ def _cons_(ui, ts):
return


def expand_CONS_masslinks(flags, uci, dat, recs):
def expand_CONS_masslinks(flags, parameters, dat, recs):
if flags["CONS"]:
ncons = 1
if "PARAMETERS" in uci:
if "NCONS" in uci["PARAMETERS"]:
ncons = uci["PARAMETERS"]["NCONS"]
if "PARAMETERS" in parameters:
if "NCONS" in parameters["PARAMETERS"]:
ncons = parameters["PARAMETERS"]["NCONS"]
for i in range(1, ncons + 1):
# ICONS loop for each cons
rec = {}
Expand Down
16 changes: 12 additions & 4 deletions src/hsp2/hsp2/GENER.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
self.ts_input_1 = tsin["ONE"]
if "TWO" in tsin:
self.ts_input_2 = tsin["TWO"]
if not "ONE" in tsin and not "TWO" in tsin:
if "ONE" not in tsin and "TWO" not in tsin:
raise NotImplementedError(f"Invalid SVOL for '{link.SVOLNO}'")

if link.SVOL == "COPY" or link.SVOL == "GENER":
Expand Down Expand Up @@ -153,9 +153,17 @@ def _opcode7(self) -> pd.Series:
def _opcode8(self) -> pd.Series:
# K(1) + K(2) * A + K(3) * A ** 2
# The user supplies the number of terms and the values of coefficients (K)
return ((self.k1 + (self.k2 * self.ts_input_1) + (self.k3 * (self.ts_input_1 ** 2))
+ (self.k4 * (self.ts_input_1 ** 3))) + (self.k5 * (self.ts_input_1 ** 4))
+ (self.k6 * (self.ts_input_1 ** 7)) + (self.k7 * (self.ts_input_1 ** 8)))
return (
(
self.k1
+ (self.k2 * self.ts_input_1)
+ (self.k3 * (self.ts_input_1**2))
+ (self.k4 * (self.ts_input_1**3))
)
+ (self.k5 * (self.ts_input_1**4))
+ (self.k6 * (self.ts_input_1**7))
+ (self.k7 * (self.ts_input_1**8))
)

def _opcode9(self) -> pd.Series:
return np.power(self.k, self.ts_input_1)
Expand Down
Loading