Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop eq #178

Merged
merged 9 commits into from
Dec 3, 2024
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
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies:
- jupyter-lsp-python
- jupyterlab-lsp # Docs at https://github.com/krassowski/jupyterlab-lsp

# Operational Model (om)
- pyparsing

# PIP install requirements only if it is not possible with conda
# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
Expand Down
3 changes: 3 additions & 0 deletions environment_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ dependencies:
# - dask # for future performance enhancements
- cltoolbox

# Operational Model (om)
- pyparsing

# Interactivity & Visualization via Jupyter Notebooks (optional,
# but required for tutorials)
- jupyterlab # also installs classic Jupyter notbook
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ dependencies = [
"numba",
"numpy<2.0",
"pandas",
"tables"
"tables",
"pyparsing"
]
authors = [
{name = "RESPEC, Inc", email = "[email protected]"}
Expand Down
60 changes: 30 additions & 30 deletions src/hsp2/hsp2/HYDR.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
"""Copyright (c) 2020 by RESPEC, INC.
Author: Robert Heaphy, Ph.D.
License: LGPL2
Conversion of no category version of HSPF HRCHHYD.FOR into Python
Conversion of no category version of HSPF HRCHHYD.FOR into Python"""

Development Notes:
""" Development Notes:
Categories not implimented in this version
Irregation only partially implimented in this version
Only English units currently supported
FTABLE can come from WDM or UCI file based on FTBDSN 1 or 0
"""

from math import log10, sqrt

from numba import njit, types
from numba.typed import Dict, List
from numpy import any, arange, array, asarray, full, int64, nan, zeros
from numpy import zeros, any, full, nan, array, int64, arange, asarray
from pandas import DataFrame

from hsp2.hsp2.om import model_domain_dependencies, pre_step_model, step_model
from math import sqrt, log10
from numba import njit, types
from numba.typed import List
from hsp2.hsp2.utilities import initm, make_numba_dict

# the following imports added by rb to handle dynamic code and special actions
from hsp2.hsp2.state import hydr_get_ix, hydr_init_ix
from hsp2.hsp2.utilities import initm, make_numba_dict
from hsp2.hsp2.state import hydr_get_ix, hydr_init_ix, hydr_state_vars
from hsp2.hsp2.om import pre_step_model, step_model, model_domain_dependencies
from numba.typed import Dict


ERRMSGS = (
"HYDR: SOLVE equations are indeterminate", # ERRMSG0
Expand Down Expand Up @@ -164,25 +165,14 @@ def hydr(io_manager, siminfo, uci, ts, ftables, state):
# must split dicts out of state Dict since numba cannot handle mixed-type nested Dicts
state_ix, dict_ix, ts_ix = state["state_ix"], state["dict_ix"], state["ts_ix"]
state_paths = state["state_paths"]
ep_list = [
"DEP",
"IVOL",
"O1",
"O2",
"O3",
"OVOL1",
"OVOL2",
"OVOL3",
"PRSUPY",
"RO",
"ROVOL",
"SAREA",
"TAU",
"USTAR",
"VOL",
"VOLEV",
]
model_exec_list = model_domain_dependencies(state, state_info["domain"], ep_list)
ep_list = (
hydr_state_vars()
) # define all eligibile for state integration in state.py
# note: calling dependencies with 4th arg = True grabs only "runnable" types, which can save time
# in long simulations, as iterating through non-runnables like Constants consumes time.
model_exec_list = model_domain_dependencies(
state, state_info["domain"], ep_list, True
)
model_exec_list = asarray(model_exec_list, dtype="i8") # format for use in numba
op_tokens = state["op_tokens"]
#######################################################################################
Expand Down Expand Up @@ -216,7 +206,8 @@ def hydr(io_manager, siminfo, uci, ts, ftables, state):
uci["PARAMETERS"]["ROS"] = ui["ROS"]
for i in range(nexits):
uci["PARAMETERS"]["OS" + str(i + 1)] = ui["OS" + str(i + 1)]

# copy back (modified) operational element data
state["state_ix"], state["dict_ix"], state["ts_ix"] = state_ix, dict_ix, ts_ix
return errors, ERRMSGS


Expand Down Expand Up @@ -875,3 +866,12 @@ def expand_HYDR_masslinks(flags, uci, dat, recs):
rec["SVOL"] = dat.SVOL
recs.append(rec)
return recs


def hydr_load_om(state, io_manager, siminfo):
for i in hydr_state_vars():
state["model_data"][seg_name][i] = {
"object_class": "ModelVariable",
"name": i,
"value": 0.0,
}
48 changes: 26 additions & 22 deletions src/hsp2/hsp2/SEDTRN.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
License: LGPL2
"""

from math import exp, log10

from numpy import array, zeros, where, int64, asarray
from math import log10, exp
from numba import njit, types
from numba.typed import Dict
from numpy import array, asarray, int64, where, zeros

from hsp2.hsp2.ADCALC import advect
from hsp2.hsp2.om import model_domain_dependencies, pre_step_model, step_model
from hsp2.hsp2.utilities import make_numba_dict

# the following imports added to handle special actions
from hsp2.hsp2.state import sedtrn_get_ix, sedtrn_init_ix
from hsp2.hsp2.utilities import make_numba_dict
from hsp2.hsp2.state import sedtrn_get_ix, sedtrn_init_ix, sedtrn_state_vars
from hsp2.hsp2.om import pre_step_model, step_model, model_domain_dependencies
from numba.typed import Dict

ERRMSGS = (
"SEDTRN: Warning -- bed storage of sediment size fraction sand is empty", # ERRMSG0
Expand Down Expand Up @@ -110,18 +108,22 @@ def sedtrn(io_manager, siminfo, uci, ts, state):
# # It appears necessary to load this here, instead of from main.py, otherwise,
# # _hydr_() does not recognize the function state_step_hydr()?
# if (hsp2_local_py != False):
# from hsp2_local_py import state_step_hydr
# from hsp2_local_py import state_step_hydr
# else:
# from hsp2.hsp2.state_fn_defaults import state_step_hydr
# from hsp2.hsp2.state_fn_defaults import state_step_hydr
# must split dicts out of state Dict since numba cannot handle mixed-type nested Dicts
# initialize the sedtrn paths in case they don't already reside here
sedtrn_init_ix(state, state["domain"])
state_ix, dict_ix, ts_ix = state["state_ix"], state["dict_ix"], state["ts_ix"]
state_paths = state["state_paths"]
op_tokens = state["op_tokens"]
# Aggregate the list of all SEDTRN end point dependencies
ep_list = ["RSED4", "RSED5", "RSED6"]
model_exec_list = model_domain_dependencies(state, state_info["domain"], ep_list)
ep_list = (
sedtrn_state_vars()
) # define all eligibile for state integration in state.py
model_exec_list = model_domain_dependencies(
state, state_info["domain"], ep_list, True
)
model_exec_list = asarray(model_exec_list, dtype="i8") # format for use in
#######################################################################################

Expand Down Expand Up @@ -274,11 +276,11 @@ def _sedtrn_(
HRAD = ts["HRAD"]
TWID = ts["TWID"]

if not "ISED1" in ts:
if "ISED1" not in ts:
ts["ISED1"] = zeros(simlen)
if not "ISED2" in ts:
if "ISED2" not in ts:
ts["ISED2"] = zeros(simlen)
if not "ISED3" in ts:
if "ISED3" not in ts:
ts["ISED3"] = zeros(simlen)

ISED1 = ts["ISED1"] # if present, else ISED is identically zero; sand
Expand Down Expand Up @@ -799,11 +801,13 @@ def bdexch(avdepm, w, tau, taucd, taucs, m, vol, frcsed, susp, bed):
return depmas - scrmas, susp, bed # net deposition or scour, susp, bed


""" Sediment Transport in Alluvial Channels, 1963-65 by Bruce Colby.
This report explains the following empirical algorithm."""


@njit(cache=True)
def colby(v, db50, fhrad, fsl, tempr):
"""Sediment Transport in Alluvial Channels, 1963-65 by Bruce Colby.
This report explains the following empirical algorithm."""
# Colby's method to calculate the capacity of the flow to transport sand.
# Colby's method to calculate the capacity of the flow to transport sand.
#
# The colby method has the following units and applicable ranges of variables.
# average velocity.............v.......fps.........1-10 fps
Expand Down Expand Up @@ -875,10 +879,10 @@ def colby(v, db50, fhrad, fsl, tempr):
F[1, 10], F[2, 10], F[3, 10], F[4, 10], F[5, 10] = 1.0, 1.4, 4.9, 22.0, 120.0

# T = array([[-999, -999, -999, -999, -999, -999, -999, -999],
# [-999, 1.2, 1.15, 1.10, 0.96, 0.90, 0.85, 0.82],
# [-999, 1.35, 1.25, 1.12, 0.92, 0.86, 0.80, 0.75],
# [-999, 1.60, 1.40, 1.20, 0.89, 0.80, 0.72, 0.66],
# [-999, 2.00, 1.65, 1.30, 0.85, 0.72, 0.63, 0.55]]).T # Temperature adjustment, Figure 24
# [-999, 1.2, 1.15, 1.10, 0.96, 0.90, 0.85, 0.82],
# [-999, 1.35, 1.25, 1.12, 0.92, 0.86, 0.80, 0.75],
# [-999, 1.60, 1.40, 1.20, 0.89, 0.80, 0.72, 0.66],
# [-999, 2.00, 1.65, 1.30, 0.85, 0.72, 0.63, 0.55]]).T # Temperature adjustment, Figure 24

T = zeros((8, 5))
T[0, 0], T[0, 1], T[0, 2], T[0, 3], T[0, 4] = -999, -999, -999, -999, -999
Expand Down
29 changes: 15 additions & 14 deletions src/hsp2/hsp2/SPECL.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"""

from numba import njit
from pandas import DataFrame, date_range


def specl_load_actions(state, io_manager, siminfo):
def specl_load_om(state, io_manager, siminfo):
if "ACTIONS" in state["specactions"]:
dc = state["specactions"]["ACTIONS"]
for ix in dc.index:
Expand All @@ -36,25 +35,27 @@ def specl_load_actions(state, io_manager, siminfo):


def specl_load_state(state, io_manager, siminfo):
specl_load_actions(state, io_manager, siminfo)
specl_load_om(state, io_manager, siminfo)
# others defined below, like:
# specl_load_uvnames(state, io_manager, siminfo)
# ...
return


"""
# the code specl() is deprecated in favor of execution inside OM
# see om_special_action.py for example of object support and runtime functions for classic ACTIONS
CALL: specl(ui, ts, step, state_info, state_paths, state_ix, specactions)
store is the Pandas/PyTable open store
siminfo is a dictionary with simulation level infor (OP_SEQUENCE for example)
ui is a dictionary with RID specific HSPF UCI like data
ts is a dictionary with RID specific timeseries
state is a dictionary with value of variables at ts[step - 1]
specl_actions is a dictionary with all SPEC-ACTIONS entries
"""


@njit
def specl(ui, ts, step, state_info, state_paths, state_ix, specactions):
"""
# the code specl() is deprecated in favor of execution inside OM
# see om_special_action.py for example of object support and runtime functions for classic ACTIONS
CALL: specl(ui, ts, step, state_info, state_paths, state_ix, specactions)
store is the Pandas/PyTable open store
siminfo is a dictionary with simulation level infor (OP_SEQUENCE for example)
ui is a dictionary with RID specific HSPF UCI like data
ts is a dictionary with RID specific timeseries
state is a dictionary with value of variables at ts[step - 1]
specl_actions is a dictionary with all SPEC-ACTIONS entries
"""
# ther eis no need for _specl_ because this code must already be njit
return
Loading
Loading