Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
779 commits
Select commit Hold shift + click to select a range
93f2cba
try to add specactions property to h5 object
Sep 2, 2022
34a83ce
print specactions to see
Sep 2, 2022
d12180a
print specactions to see
Sep 2, 2022
a1f4e7e
tabs not spaces
Sep 2, 2022
87826b7
tabs not spaces
Sep 2, 2022
0205c7e
debug
Sep 2, 2022
ddb3c02
debug
Sep 2, 2022
8213aa4
debug
Sep 2, 2022
ecea36c
debug
Sep 2, 2022
e6a39db
some debug off
Sep 2, 2022
4e30847
Update conda dev environment
aufdenkampe Sep 2, 2022
0198222
Merge branch 'develop' into InorganicNurtientTSNotLoading
aufdenkampe Sep 2, 2022
70d31df
Merge pull request #101 from respec/InorganicNurtientTSNotLoading
PaulDudaRESPEC Sep 6, 2022
c53ab56
Merge pull request #23 from HARPgroup/specl9.2.2022
jdkleiner Sep 7, 2022
6167ea3
specactions work session updates
jdkleiner Sep 7, 2022
20ab56b
run test withdrawal from specactions dictionary
jdkleiner Sep 12, 2022
136556f
set up testcbp
jdkleiner Sep 15, 2022
886abc0
stashed JK work
rburghol Sep 26, 2022
8ab4a0d
change name to be compatible with hdf5 and python tables package
Sep 26, 2022
22e9758
2nd location change name to be compatible with hdf5 and python tables…
Sep 26, 2022
bcbc094
adjust tabs in specl def in csv
Sep 26, 2022
07e6c90
adjust tabs in specl def in csv
Sep 26, 2022
95940cb
shortened specl block for testing
Sep 26, 2022
3a0d3b0
adjusted line header detectors to correct length
Sep 26, 2022
e46b504
debug
Sep 26, 2022
0dfc59e
debug
Sep 26, 2022
96490e1
adjusted string matching for exclusive end of pair, i.e., the 1st 3 c…
Sep 26, 2022
83777cd
adjusted parseTable for exclusive ending, tho this is likely not goin…
Sep 26, 2022
f264a13
debug
Sep 26, 2022
bc92795
update parse reference, maybe?
Sep 26, 2022
73679cf
debug
Sep 26, 2022
0781855
add elifs
Sep 26, 2022
e3c1e8c
correct the match length
Sep 26, 2022
ccd6cc8
indicate enclsosure in IF
Sep 26, 2022
bd95f18
fix add to d
Sep 26, 2022
b922560
clean up if-then draft
Sep 27, 2022
43eb193
debug off
Sep 27, 2022
2541963
newline
rburghol Sep 27, 2022
be77ee6
ignore hdf5 in case someone tests in tree
rburghol Sep 27, 2022
76d4370
Merge pull request #102 from HARPgroup/psa
PaulDudaRESPEC Sep 30, 2022
9ae42b7
try fix to operation being stored as number instead of char
Oct 3, 2022
723830d
Merge branch 'psa' of github.com:HARPgroup/HSPsquared into psa
Oct 3, 2022
7227e35
pass by investigations
jdkleiner Oct 3, 2022
43b802b
OUTDGT, pass-by, hydr h5
jdkleiner Oct 3, 2022
4972094
Merge pull request #28 from HARPgroup/jk0923
jdkleiner Oct 3, 2022
fe04e36
Merge pull request #29 from respec/develop
rburghol Oct 4, 2022
1344e37
add tests
rburghol Oct 7, 2022
136b585
Merge branch 'specl' into psa
rburghol Oct 7, 2022
427a49e
Merge pull request #103 from HARPgroup/psa
PaulDudaRESPEC Oct 11, 2022
37882a3
Merge branch 'develop' of github.com:HARPgroup/HSPsquared into develop
jdkleiner Oct 19, 2022
8889841
SPECL initial PR
jdkleiner Oct 19, 2022
7b0f087
Update 3_DataVisualizationDemo.ipynb
aufdenkampe Oct 24, 2022
e656746
Merge pull request #104 from HARPgroup/specl
PaulDudaRESPEC Jan 11, 2023
06208d8
against develop this time
rburghol Mar 17, 2023
cee7f77
Merge pull request #110 from HARPgroup/hinit
PaulDudaRESPEC Mar 17, 2023
3ffc70e
correct OPNID lengths 8 and 12, make length 10 consistently
PaulDudaRESPEC Mar 17, 2023
c0cbeb3
Fix pip install bug when jupyter lab version restricted to 3.0.*
rburghol Jun 21, 2023
3132b9c
Fix pip install bug when jupyter lab version restricted to 3.0.*
rburghol Jun 21, 2023
98f9486
Fix pip install bug when jupyter lab version restricted to 3.0.*
rburghol Jun 21, 2023
4d1e023
remove extraneous debugging info
Jun 23, 2023
a2bcd05
removed testing code for OUTDGT set in ts
rburghol Jun 26, 2023
970840b
Merge branch 'develop' into fixjup
rburghol Jun 26, 2023
d1ae4b5
Merge pull request #69 from respec/develop
rburghol Jun 28, 2023
f58e4e0
Merge pull request #70 from HARPgroup/fixjup
rburghol Jun 28, 2023
a608414
Merge pull request #114 from HARPgroup/fixjup
PaulDudaRESPEC Jun 29, 2023
cf6342b
cleaned up specl and slimmed, restore OS setting
rburghol Jun 29, 2023
57021ea
Merge pull request #117 from HARPgroup/devfix
PaulDudaRESPEC Jun 29, 2023
137d40e
Merge pull request #75 from respec/develop
rburghol Jun 29, 2023
ebd6c78
Add support for STATE in HYDR, and specl and dynamic scripting for STATE
rburghol Jun 29, 2023
b76865b
add defaults
Jun 29, 2023
5b9ccf2
move comment
Jun 29, 2023
492b3a4
improve comments
Jun 29, 2023
07afbb8
ParseTable.csv -- correction for some UCI field widths
PaulDudaRESPEC Aug 29, 2023
b692c49
Merge pull request #119 from HARPgroup/devstate
PaulDudaRESPEC Aug 29, 2023
4306b26
remove files that were mistakenly committed here
PaulDudaRESPEC Sep 11, 2023
f89b478
implement constand value gener operations
PaulDudaRESPEC Sep 21, 2023
ea282fe
PSTEMP.py, PWATER.py, RQUAL_Class.py, utilities.py
PaulDudaRESPEC Sep 22, 2023
66efe6a
PQUAL.py, IQUAL.py, utilities.py -- small bug fix for proper computat…
PaulDudaRESPEC Sep 25, 2023
e6741f9
HTRCH small fix to conversion factor to better match HSPF
PaulDudaRESPEC Sep 27, 2023
d4ff5d1
HSP2_Driver.py -- add option for different save levels
PaulDudaRESPEC Sep 29, 2023
2bd17dc
first draft of segment expander script
PaulDudaRESPEC Oct 3, 2023
75dc4c3
first draft of segment expander script
PaulDudaRESPEC Oct 3, 2023
09833c1
IQUAL.py and PQUAL.py -- make sure NQUALS is an integer
PaulDudaRESPEC Oct 5, 2023
e6ffe97
SegmentExpander.py -- clear out unused P/I Ids after expansion
PaulDudaRESPEC Oct 5, 2023
3b0af99
utilities.py -- small fixes for get_gener_timeseries
PaulDudaRESPEC Oct 18, 2023
70d743c
HBNOutput.py -- small cleanup
PaulDudaRESPEC Oct 20, 2023
a6a73db
state.py -- modify messages
PaulDudaRESPEC Oct 24, 2023
ae969b0
Merge pull request #120 from respec/develop
PaulDudaRESPEC Oct 24, 2023
f813604
rename so custom code is not used automatically
PaulDudaRESPEC Oct 24, 2023
a9e2bdd
Merge pull request #121 from respec/develop
PaulDudaRESPEC Oct 24, 2023
8ff41fb
first cut at implementing other gener operations
PaulDudaRESPEC Oct 31, 2023
2d523ac
first draft of enhancement to allow output aggregated to daily, month…
PaulDudaRESPEC Nov 1, 2023
5121c90
Update _version.py
phobson Nov 27, 2023
531a6c0
Merge pull request #122 from phobson/patch-1
PaulDudaRESPEC Nov 27, 2023
d500044
small clean-ups to fully implement GENER operations
PaulDudaRESPEC Nov 27, 2023
385d7c3
Added a couple R files to ignore to keep the repo clean when includin…
rburghol Nov 29, 2023
6f0e3ba
Merge pull request #124 from HARPgroup/devignore
PaulDudaRESPEC Dec 1, 2023
edaf42a
Merge pull request #125 from respec/master
PaulDudaRESPEC Dec 15, 2023
1ca03cf
clean up details of ParseTable.csv
PaulDudaRESPEC Dec 15, 2023
86a6e5e
add hdf5 file name to output message
PaulDudaRESPEC Dec 20, 2023
f895dd9
refinements to include multiple canopy layer enhancement
PaulDudaRESPEC Dec 20, 2023
bc3909c
Changed package name from HSPsquared to hsp2 for a better name on pypi.
timcera Jan 18, 2024
5dc3112
Merge pull request #130 from timcera/package_name
PaulDudaRESPEC Jan 18, 2024
7f90ddb
Create python-app.yml
rburghol Feb 12, 2024
92bf071
Update python-app.yml
rburghol Feb 12, 2024
12d80e2
Update python-app.yml
rburghol Feb 12, 2024
dd6416e
Update python-app.yml
rburghol Feb 12, 2024
4b84b2e
Update python-app.yml
rburghol Feb 12, 2024
59247d0
Update python-app.yml
rburghol Feb 26, 2024
7024915
Create python-app1.yml
rburghol Feb 26, 2024
228fb6f
Update python-app.yml
rburghol Feb 26, 2024
dd149a3
Update python-app.yml
rburghol Feb 26, 2024
7d557fa
Update python-app.yml
rburghol Feb 26, 2024
2b8f2bd
delete superfluous workflow
Feb 26, 2024
1ba6520
add actions folder to see if it fixes
Feb 26, 2024
9e779ea
Update python-app.yml
rburghol Feb 26, 2024
72582a5
Update python-app.yml
rburghol Feb 26, 2024
b26d428
disable the custom action yml to see if it still works (as tutorial s…
Feb 26, 2024
5ee2d3a
Merge branch 'master' of github.com:HARPgroup/HSPsquared
Feb 26, 2024
a097fdb
Update python-app.yml
rburghol Feb 26, 2024
609c423
Update python-app.yml
rburghol Feb 26, 2024
263eb38
Update python-app.yml
rburghol Feb 26, 2024
acf78a3
Update python-app.yml
rburghol Feb 26, 2024
c3152c6
add ptest
Feb 26, 2024
3ed9ad4
Merge branch 'master' of github.com:HARPgroup/HSPsquared
Feb 26, 2024
4a6685d
Update python-app.yml
rburghol Feb 26, 2024
7cf9cc2
Update python-app.yml
rburghol Feb 26, 2024
3cdb10d
Update python-app.yml
rburghol Feb 26, 2024
42aee45
Update python-app.yml
rburghol Feb 26, 2024
f8975c4
Update python-app.yml
rburghol Feb 27, 2024
a05260c
Update environment.yml
rburghol Feb 27, 2024
6b2704b
Update environment.yml
rburghol Feb 27, 2024
8a9cba8
Update python-app.yml
rburghol Feb 27, 2024
8d78ac4
Update python-app.yml
rburghol Feb 27, 2024
7ed255a
Create hsp2_dev_env
rburghol Feb 28, 2024
101f5cc
Update python-app.yml
rburghol Feb 28, 2024
37e0420
Update hsp2_dev_env
rburghol Feb 28, 2024
05a3cba
Update hsp2_dev_env
rburghol Feb 28, 2024
cbc26b1
dev environment test yml file
Feb 28, 2024
e36b2ac
Update hsp2-install-dev.yml
rburghol Feb 28, 2024
4cff9f8
Update hsp2-install-dev.yml
rburghol Feb 28, 2024
d045118
Update hsp2-install-dev.yml
rburghol Feb 28, 2024
a7dc209
Update hsp2-install-dev.yml
rburghol Feb 28, 2024
0ad9f20
dont save test h5 files
Feb 28, 2024
1b0bd68
initial set of tests for CI
Feb 28, 2024
0c43a1c
Merge pull request #90 from HARPgroup/testx
rburghol Feb 28, 2024
31746e4
update test file with hsp2 run
Feb 28, 2024
9436df3
add test of hdf5 exists
Feb 28, 2024
5341f76
add test of hdf5 exists
Feb 28, 2024
c64c8cc
rename pytest
Feb 28, 2024
371c1bd
rename pytest call
Feb 28, 2024
d2f5cae
add a failing test
Feb 28, 2024
2070ac2
format
Feb 28, 2024
dd89d8a
disble purposely failing test
Feb 28, 2024
095969c
adding new dev config from dependency_options branch
Feb 29, 2024
a20586b
set py to 3.11 in dev
Feb 29, 2024
771ae5f
info
Feb 29, 2024
6028aff
rename scripts to show install env (i.e. pip / conda)
Feb 29, 2024
99bb5f6
attempt a conda install tester
Feb 29, 2024
6b011a9
attempt a conda install tester
Feb 29, 2024
715af46
attempt a conda install tester
Feb 29, 2024
3dceaad
try looking for hsp2 in the CONDA path
Feb 29, 2024
c9e5a16
call hsp wihtout path
Feb 29, 2024
ad4bb22
Merge pull request #144 from respec/master
PaulDudaRESPEC Mar 5, 2024
2fab619
merge in minor additions
PaulDudaRESPEC Mar 6, 2024
f14ffec
merging in changes from HARPgroup
PaulDudaRESPEC Mar 6, 2024
ffda6b9
Merge branch 'develop' into testx
rburghol Mar 6, 2024
3e71d53
Merge pull request #142 from HARPgroup/testx
PaulDudaRESPEC Mar 6, 2024
b869306
only run tests on 3 branches
Mar 18, 2024
89896aa
Merge pull request #148 from HARPgroup/testx
PaulDudaRESPEC Apr 2, 2024
7f5ed03
Create CONTRIBUTING.md
PaulDudaRESPEC Apr 3, 2024
a213e4a
Update README.md
PaulDudaRESPEC Apr 3, 2024
5b8c4fe
ACIDPH.py is not yet valid python, preserving wip as text
austinorr Apr 19, 2024
a0e06cc
prepare for disabling the jit during tests to enable code coverage
austinorr Apr 19, 2024
ea815b0
tests passing for IWater and PWater under pytest with ~70% code coverage
austinorr Apr 19, 2024
3a410d9
(feat) change to a pyproject.toml to publish to pypi
timcera Apr 22, 2024
511ee65
(ci) update github workflows to work with pyproject.toml.
timcera Apr 23, 2024
cd16f0b
(fix) replaced mando with cltoolbox
timcera Apr 23, 2024
2d5b775
Merge pull request #151 from Geosyntec/ipwater-tests
PaulDudaRESPEC Apr 23, 2024
6612a73
Merge pull request #152 from timcera/pypi_package
PaulDudaRESPEC Apr 23, 2024
e883a44
README.md -- restore this file temporarily while resolving a merge co…
PaulDudaRESPEC Apr 23, 2024
dfca12d
Merge pull request #153 from respec/master
PaulDudaRESPEC Apr 23, 2024
f1b20d6
Delete README.md after resolving merge conflict
PaulDudaRESPEC Apr 23, 2024
08a53c7
misc fixes
timcera Apr 30, 2024
f830d74
fixes for publish.py and pyproject.toml
timcera Apr 30, 2024
781d026
this action does not work, it hangs indefinately
austinorr Apr 30, 2024
f7d361f
this action is not yet needed, should likely be a simple matrix in th…
austinorr Apr 30, 2024
492a3a1
Merge pull request #160 from Geosyntec/cleanup-actions
PaulDudaRESPEC Apr 30, 2024
df97557
OXRX_Class.py -- explicitly set tcginv and len_ to avoid future issue…
PaulDudaRESPEC May 1, 2024
19efe9d
Test10 -- fixed sedment option flag in the UCI
PaulDudaRESPEC May 1, 2024
9de9ad8
utilities.py and io.py -- small improvements to get into the next rel…
PaulDudaRESPEC May 1, 2024
aa76148
Merge pull request #159 from timcera/fix
PaulDudaRESPEC May 3, 2024
4516b2f
readUCI.py -- go back to old way fix_df for now
PaulDudaRESPEC May 3, 2024
099b56a
added pytest to deps and python application ci job
austinorr Apr 29, 2024
23e1b83
tests/test10/HSP2results fails due to df.append in readUCI line 86; p…
austinorr Apr 29, 2024
c1d2a68
rm no-op pytest since there is now an actual test to call
austinorr Apr 29, 2024
bbf7ceb
use this to manually hide personal files; todo: rm all the personal p…
austinorr May 4, 2024
314aa76
(fix) cleanup the utilities.versions function so that it can't fail a…
austinorr May 4, 2024
8262502
add pytest apparatus that works with test10, and hopefully others. mu…
austinorr May 4, 2024
06959de
refactor commands for reuse in test helpers
austinorr May 4, 2024
8e44644
lint pyproject.toml
austinorr May 4, 2024
84d2e11
support pandas versions 1.5-2+
austinorr May 5, 2024
5c1afaa
fix packaging bug that excluded data files for HSP2tools
austinorr May 5, 2024
e2e42f6
parallelize ci tests & lint; test python 3.9-3.12; test pandas<1.5 & …
austinorr May 5, 2024
e32573a
fix test suite to include 3.9
austinorr May 5, 2024
0ef882a
fix quotes for pandas version
austinorr May 5, 2024
8f4da0f
speed up tests not under coverage
austinorr May 5, 2024
d2aaa9a
Merge pull request #156 from Geosyntec/pytest
PaulDudaRESPEC May 6, 2024
5cf36b6
just hsp2/om specific stuff
May 6, 2024
35859d6
just hsp2/om specific stuff
May 6, 2024
c5cb65e
special actions and support files state and om
May 6, 2024
bdfaf47
special actions and support files state and om
May 6, 2024
4e8f0d3
change endings for HYDR.py
May 6, 2024
3f24431
change endings for SEDTRN.py
May 6, 2024
3718393
change endings for main.py
May 6, 2024
3ab1666
change endings for state.py
May 6, 2024
ceae46b
added test10specl.uci
May 7, 2024
4e7d50b
Merge changes that were reverted from https://github.com/respec/HSPsq…
May 7, 2024
acfa1e7
load specific functions instead of blanket import
May 7, 2024
bf7ebe9
load functions for ModelObject and SimTimer
May 7, 2024
657b805
load required functions for state into om
May 7, 2024
c898c9f
load required functions for state/om/specl explicitly into HYDR and S…
May 7, 2024
67d1031
corrected typo in the comment/header line in the specl UCIs
May 7, 2024
ed1d67f
added new UCI test from Paul
May 8, 2024
af9b71e
restored reversion for SEDTRN specl execution, fixed precision mismat…
May 8, 2024
ea60772
tests for spec actions
austinorr May 8, 2024
162c248
Merge pull request #100 from Geosyntec/spec-act
rburghol May 8, 2024
22a0233
better example in comments, no functional change
May 9, 2024
62d3118
Removed global ModelObject class attriutes. Fixed special actions tre…
May 9, 2024
573195a
cleaned up a couple remaining import statements
May 10, 2024
17f32c2
Renamed ModelConstant to ModelVariable since ModelConstant should be …
May 14, 2024
4f38c7a
Deleeted superfluous files
May 14, 2024
7dc3336
Deleted superfluous files
May 14, 2024
b8d07a8
Merge pull request #161 from HARPgroup/develop-spec-lean
PaulDudaRESPEC May 20, 2024
ce49ea2
Move to single python package "hsp2"
timcera May 22, 2024
bc587f8
Merge pull request #166 from timcera/develop
PaulDudaRESPEC May 24, 2024
7424140
remove some unneeded files prior to merging into main, comment out so…
PaulDudaRESPEC May 28, 2024
a86edc0
Merge pull request #167 from respec/develop
PaulDudaRESPEC Jun 19, 2024
249054e
Update pyproject.toml
PaulDudaRESPEC Jun 19, 2024
b0f342e
Merge pull request #169 from timcera/develop
PaulDudaRESPEC Jul 19, 2024
3225f03
Reformat/restyle files according to rules in .pre-commit-config.yaml
timcera Jul 27, 2024
7279e8f
Merge pull request #174 from timcera/ruff
PaulDudaRESPEC Aug 14, 2024
177b75c
Merge branch 'develop' of github.com:HARPgroup/HSPsquared into develop
Mar 6, 2025
8b066c5
Merge branch 'develop' of github.com:HARPgroup/HSPsquared into develop
Mar 7, 2025
2c432ca
add function to grab batches of state values
Mar 7, 2025
054d95c
added demo stuff and some useful functions
Mar 7, 2025
736a0bb
organized files for demo
Mar 7, 2025
5f685aa
enabled equation SPECL component and added demo files for equation/sp…
Mar 8, 2025
009d61b
moved quation loop demo to examples
Mar 8, 2025
c627cee
apply ruff to changed files
Mar 10, 2025
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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tests/GLWACSO/HSP2results/hspp007.uci
tests/test_report_conversion.html

# Omit big files
tests/**/*.h5
tests/**/**/*.h5
tests/testcbp/HSP2results/*.csv

# R files
Expand Down
135 changes: 135 additions & 0 deletions examples/state_specl_ops/compare_eq_to_specl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# if testing manually you may need to os.chdir('./tests/test10specl/HSP2results')
import os
import pandas as pd
import numpy as np
from pandas import read_hdf
import h5py
#from pandas.io.pytables import read_hdf
#from HSP2IO.hdf import HDF5
from pathlib import Path
from src.hsp2.hsp2tools.commands import import_uci, run
from src.hsp2.hsp2tools.HDF5 import HDF5
from src.hsp2.hsp2tools.HBNOutput import HBNOutput

def test_h5_file_exists():
assert os.path.exists('test10.h5')


############# HSPF With SPECIAL ACTION
test_root = Path("tests/test10specl")
test_root.exists()
test_root_hspf = Path(test_root) / "HSPFresults"
hspf_data = HBNOutput(os.path.join(test_root_hspf, 'test10speclR.hbn'))
hspf_data.read_data()
# get RCHRES 5 sedtrn silt
ts_silt_hspf = hspf_data.get_time_series('RCHRES', 5, 'RSEDTOTSILT', 'SEDTRN', 'full')
total_silt_hspf = ts_silt_hspf.mean()
quantile_silt_hspf = np.quantile(ts_silt_hspf,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])

############# HSPF NO SPECL
hspf_nospecl_root = Path("tests/test10/HSPFresults")
hspf_nospecl_data = HBNOutput(os.path.join(hspf_nospecl_root, 'test10R.hbn'))
hspf_nospecl_data.read_data()
ts_silt_nospecl_hspf = hspf_nospecl_data.get_time_series('RCHRES', 5, 'RSEDTOTSILT', 'SEDTRN', 'full')
total_silt_nospecl_hspf = ts_silt_nospecl_hspf.mean()
quantile_silt_nospecl_hspf = np.quantile(ts_silt_nospecl_hspf,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])

############# hsp2 SPECL
# Run and Analyze hsp2 WITH SPECL actions
specl_root = Path("tests/test10specl")
specl_root.exists()
specl_root_hsp2 = Path(specl_root) / "HSP2results"
hsp2_specl_uci = specl_root_hsp2.resolve() / "test10specl.uci"
hsp2_specl_uci.exists()
temp_specl_h5file = specl_root_hsp2 / "test10specl.h5"

# IF we want to run it from python, do this:
# if temp_specl_h5file.exists():
# temp_specl_h5file.unlink()
# load the UCI into the h5 then run it
# import_uci(str(hsp2_specl_uci), str(temp_specl_h5file))
# run(temp_specl_h5file, saveall=True, compress=False)
# Load Data from hdf5 & Analyze
dstore_specl = pd.HDFStore(str(temp_specl_h5file), mode='r')
hsp2_specl_hydr5 = read_hdf(dstore_specl, '/RESULTS/RCHRES_R005/HYDR')
hsp2_specl_sedtrn5 = read_hdf(dstore_specl, '/RESULTS/RCHRES_R005/SEDTRN')
hsp2_specl_rsed5 = hsp2_specl_sedtrn5['RSED5']
quantile_silt_hsp2 = np.quantile(hsp2_specl_rsed5,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_ro_hsp2 = np.quantile(hsp2_specl_hydr5['RO'],[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
total_silt_hsp2 = hsp2_specl_rsed5.mean()
dstore_specl.close()

############# hsp2 w/out SPECL
# Run and Analyze hsp2 without SPECL actions
nospecl_root = Path("tests/test10")
nospecl_root.exists()
nospecl_root_hspf = Path(nospecl_root) / "HSPFresults"
hsp2_nospecl_uci = nospecl_root_hspf.resolve() / "test10.uci"
hsp2_nospecl_uci.exists()
temp_nospecl_h5file = nospecl_root_hspf / "nospecl_case.h5"

# IF we want to run it from python, do this:
#if temp_nospecl_h5file.exists():
# temp_nospecl_h5file.unlink()
# load the UCI into the h5 then run it
#import_uci(str(hsp2_nospecl_uci), str(temp_nospecl_h5file))
#run(temp_nospecl_h5file, saveall=True, compress=False)
# Load Data from hdf5 & Analyze
dstore_nospecl = pd.HDFStore(str(temp_nospecl_h5file), mode='r')
hsp2_nospecl_hydr5 = read_hdf(dstore_nospecl, '/RESULTS/RCHRES_R005/HYDR')
hsp2_nospecl_sedtrn5 = read_hdf(dstore_nospecl, '/RESULTS/RCHRES_R005/SEDTRN')
hsp2_nospecl_rsed5 = hsp2_nospecl_sedtrn5['RSED5']
np.quantile(hsp2_nospecl_rsed5,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
np.quantile(hsp2_nospecl_hydr5['RO'],[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
total_silt_nospecl_hsp2 = hsp2_nospecl_rsed5.mean()
dstore_nospecl.close()


############# hsp2 w/equation replicating SPECL
# Run and Analyze hsp2 WITH SPECL actions
eq_root = Path("tests/test10eq")
eq_root.exists()
eq_root_hsp2 = Path(eq_root) / "HSP2results"
hsp2_eq_uci = eq_root_hsp2.resolve() / "test10eq.uci"
hsp2_eq_uci.exists()
temp_eq_h5file = eq_root_hsp2 / "test10eq.h5"
# IF we want to run it from python, do this:
#if temp_eq_h5file.exists():
# temp_eq_h5file.unlink()

# load the UCI into the h5 then run it
#import_uci(str(hsp2_eq_uci), str(temp_eq_h5file))
#run(temp_eq_h5file, saveall=True, compress=False)
# Load Data from hdf5 & Analyze
dstore_eq_specl = pd.HDFStore(str(temp_eq_h5file), mode='r')
hsp2_eq_hydr5 = read_hdf(dstore_eq_specl, '/RESULTS/RCHRES_R005/HYDR')
hsp2_eq_sedtrn5 = read_hdf(dstore_eq_specl, '/RESULTS/RCHRES_R005/SEDTRN')
hsp2_eq_rsed5 = hsp2_eq_sedtrn5['RSED5']
quantile_silt_eq_hsp2 = np.quantile(hsp2_eq_rsed5,[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
quantile_ro_eq_hsp2 = np.quantile(hsp2_eq_hydr5['RO'],[0.0,0.10,0.5,0.5,0.75,0.9,0.95,1.0])
total_silt_eq_hsp2 = hsp2_eq_rsed5.mean()
dstore_eq_specl.close()

# Calculate the % difference
print("Total Silt ")
print([
{'HSPF no specl': total_silt_nospecl_hspf},
{'HSPF specl': total_silt_hspf},
{'HSP2 specl': total_silt_hsp2}
])
print(
{'HSPF no specl': total_silt_nospecl_hspf}
)
print([
{'HSPF no specl': total_silt_nospecl_hspf},
{'HSP2 no specl': total_silt_nospecl_hsp2},
{'HSP2 eq': total_silt_eq_hsp2},
{'HSP2 specl': total_silt_hsp2}
])
print([
])
pct_dif_specl = round(100.0 * (total_silt_hsp2.mean() - total_silt_hspf.mean()) / total_silt_hsp2.mean(), 3)
pct_dif_nospecl = round(100.0 * (total_silt_nospecl_hsp2.mean() - total_silt_nospecl_hspf.mean()) / total_silt_nospecl_hspf.mean(), 3)
print("Total SiltHSP2 vs. HSPF, % difference = ", pct_dif_specl, "%")
print("No SPECL: Total SiltHSP2 vs. HSPF, % difference = ", pct_dif_nospecl, "%")

75 changes: 75 additions & 0 deletions examples/state_specl_ops/demo_equation_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Must be run from the HSPsquared source directory, the h5 file has already been setup with hsp import_uci test10.uci
# bare bones tester - must be run from the HSPsquared source directory
import os
import numpy
from hsp2.hsp2.main import *
from hsp2.hsp2.om import *
from hsp2.hsp2.state import *
from hsp2.hsp2io.hdf import HDF5
from hsp2.hsp2io.io import IOManager

fpath = "./tests/test10eq/HSP2results/test10eq.h5"
# try also:
# fpath = './tests/testcbp/HSP2results/JL1_6562_6560.h5'
# sometimes when testing you may need to close the file, so try:
# f = h5py.File(fpath,'a') # use mode 'a' which allows read, write, modify
# # f.close()
hdf5_instance = HDF5(fpath)


io_manager = IOManager(hdf5_instance)
uci_obj = io_manager.read_uci()
siminfo = uci_obj.siminfo
opseq = uci_obj.opseq
# Note: now that the UCI is read in and hdf5 loaded, you can see things like:
# - hdf5_instance._store.keys() - all the paths in the UCI/hdf5
# - finally stash specactions in state, not domain (segment) dependent so do it once
# now load state and the special actions
state = init_state_dicts()
state_siminfo_hsp2(uci_obj, siminfo, io_manager, state)
# Add support for dynamic functions to operate on STATE
# - Load any dynamic components if present, and store variables on objects
state_load_dynamics_hsp2(state, io_manager, siminfo)
# Iterate through all segments and add crucial paths to state
# before loading dynamic components that may reference them
state_init_hsp2(state, opseq, activities)
# - finally stash specactions in state, not domain (segment) dependent so do it once
state["specactions"] = uci_obj.specactions # stash the specaction dict in state
om_init_state(state) # set up operational model specific state entries
specl_load_state(state, io_manager, siminfo) # traditional special actions
state_load_dynamics_om(
state, io_manager, siminfo
) # operational model for custom python
# finalize all dynamically loaded components and prepare to run the model
state_om_model_run_prep(state, io_manager, siminfo)

# check dependencies
# get context first (sets up domain in state)
# operation = RCHRES, segment = RCHRES_004, activity = SEDTRN
state_context_hsp2(state, "RCHRES", "R005", "SEDTRN")
ep_list = ["RSED4", "RSED5", "RSED6"]
domain = state['domain']
model_exec_list = model_domain_dependencies(state, state['domain'], ep_list)
rsed4 = state['model_object_cache'][domain + "/" + 'RSED4']
test10eq = state['model_object_cache']['/STATE/test10eq']
RCHRESR005 = state['model_object_cache']['/STATE/test10eq/RCHRES_R005']
RCHRESR005.inputs
hydr_get_ix(state['state_ix'], state['state_paths'], domain)
hvars = hydr_state_vars()
get_domain_state(state['state_paths'], state['state_ix'], domain, hvars)
dep,ivol,o1,o2,o3,ovol1,ovol2,ovol3,prsupy,ro,rovol,sarea,tau,ustar,vol,volev = get_domain_state(state['state_paths'], state['state_ix'], domain, hvars)
sedvars = sedtrn_state_vars()
rsed4,rsed5,rsed6 = get_domain_state(state['state_paths'], state['state_ix'], domain, sedvars)
start = time.time()
model_domain_dependencies(state, state["domain"], ep_list)
iterate_models(
model_exec_list, state["op_tokens"], state["state_ix"], state["dict_ix"], state["ts_ix"], siminfo["steps"], -1)
end = time.time()
print(
len(model_exec_list),
"components iterated over state_ix",
siminfo["steps"],
"time steps took",
end - start,
"seconds",
)
36 changes: 36 additions & 0 deletions examples/state_specl_ops/demo_specl_initialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

##########################################################################################
# LOAD HSP2 RUNTIME CODE AND UCI FILE
##########################################################################################
import os, numpy
from hsp2.hsp2.main import *
from hsp2.hsp2.om import *
from hsp2.hsp2.state import *
from hsp2.hsp2io.hdf import HDF5
from hsp2.hsp2io.io import IOManager
hdf5_instance = HDF5("./tests/test10specl/HSP2results/test10specl.demo.h5")


iomanager = IOManager(hdf5_instance)
uci_obj = iomanager.read_uci()
siminfo = uci_obj.siminfo
opseq = uci_obj.opseq
state = init_state_dicts()
state_siminfo_hsp2(uci_obj, siminfo, iomanager, state)

# Add support for dynamic functions to operate on STATE
state_load_dynamics_hsp2(state, iomanager, siminfo)
state_init_hsp2(state, opseq, activities)
state["specactions"] = uci_obj.specactions # stash the specaction dict in state
om_init_state(state) # set up operational model specific state entries
specl_load_state(state, iomanager, siminfo) # traditional special actions
state_load_dynamics_om(state, iomanager, siminfo)
state_om_model_run_prep(state, iomanager, siminfo)
state_context_hsp2(state, "RCHRES", "R005", "SEDTRN")

domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens = state["domain"], state["state_paths"], state["state_ix"], state["dict_ix"], state["ts_ix"], state["op_tokens"]
ep_list = np.asarray(["RSED1", "RSED2", "RSED3", "RSED4", "RSED5", "RSED6"], dtype='U')
model_exec_list = model_domain_dependencies(state, domain, ep_list, True)
get_domain_state(state_paths, state_ix, domain, ep_list)


31 changes: 31 additions & 0 deletions examples/state_specl_ops/demo_step_specl_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# MUST RUN CODE FROM demo_specl_iniitialize.py before running this.
from hsp2.hsp2.sedtrn_step import step_sedtrn
##########################################################################################
# SAMPLE MAIN LOOP (does not include timestep changes)
##########################################################################################
start = time.time()
numsteps = siminfo['steps'] * 40
for step in range(numsteps):
#step_hydr(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list)
#step_adcalc(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list)
#step_cons(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list)
#step_htrch(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list)
step_sedtrn(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list, step, ep_list)
#step_gqual(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list)
#step_rqual(domain, state_paths, state_ix, dict_ix, ts_ix, op_tokens, model_exec_list)

end = time.time()
print(
len(model_exec_list), "components iterated over state_ix", numsteps,
"time steps took", end - start, "seconds",
)

state['model_root_object'].get_state("/STATE/test10specl.demo/RCHRES_R005/RSED4")
state['model_root_object'].get_state("/STATE/test10specl.demo/RCHRES_R005/RSED5")
state['model_root_object'].get_state("/STATE/test10specl.demo/RCHRES_R005/RSED6")
state['model_root_object'].inputs
state['model_object_cache']['/STATE/test10specl.demo/RCHRES_R005'].inputs
state['model_object_cache']['/STATE/test10specl.demo/RCHRES_R005/RSED6'].inputs
state['model_object_cache']['/STATE/test10specl.demo/SPECACTION2'].inputs
# Show all state var paths and indices
## print(f"{key}: {value}")
8 changes: 6 additions & 2 deletions src/hsp2/hsp2/om.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ def model_order_recursive(


def model_input_dependencies(state, exec_list, only_runnable=False):
# TODO: is this redundant to model_domain_dependencies?
# Cmment in github suggest it is not, and has specific utility
# for timeseries values? https://github.com/HARPgroup/HSPsquared/issues/60#issuecomment-2231668979
mello = exec_list
mtl = []
mel = []
Expand Down Expand Up @@ -633,9 +636,10 @@ def model_domain_dependencies(state, domain, ep_list, only_runnable=False):
endpoint = state["model_object_cache"][domain + "/" + ep]
model_order_recursive(endpoint, state["model_object_cache"], mel, mtl)
mello = mello + mel

# TODO: stash the runnable list (mellorun) as a element in dict_ix for cached access during runtime
mellorun = ModelObject.runnable_op_list(state["op_tokens"], mello)
if only_runnable == True:
mello = ModelObject.runnable_op_list(state["op_tokens"], mello)
mello = mellorun
return mello


Expand Down
37 changes: 19 additions & 18 deletions src/hsp2/hsp2/om_special_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,28 +196,31 @@ def hdf5_load_all(hdf_source):

# njit functions for runtime

"""
# these indices must be adjusted to reflect the number of common op tokens
# SpecialAction has:
# - type of condition (+=, -=, ...)
# - operand 1 (left side)
# - operand 2 (right side)
# @tbd: check if time ops have been set and enable/disable accordingly
# - 2 ops for each time matching switch: state_ix of the time element (year, month, ...) and the state_ix of the constant to match
# - if (state_ix[tix1] <> state_ix[vtix1]): return state_ix[ix1] (don't modify the value)
# - alternative: save the integer timestamp or timestep of the start, and if step/stamp > value, enable
# @tbd: add number of repeats, and save the value of repeats in a register
"""


@njit(cache=True)
def step_special_action(op, state_ix, dict_ix, step):
ix = op[1] # ID of this op
# these indices must be adjusted to reflect the number of common op tokens
# SpecialAction has:
# - type of condition (+=, -=, ...)
# - operand 1 (left side)
# - operand 2 (right side)
# @tbd: check if time ops have been set and enable/disable accordingly
# - 2 ops will be added for each time matching switch, the state_ix of the time element (year, month, ...) and the state_ix of the constant to match
# - matching should be as simple as if (state_ix[tix1] <> state_ix[vtix1]): return state_ix[ix1] (don't modify the value)
# - alternative: save the integer timestamp or timestep of the start, and if step/stamp > value, enable
# @tbd: add number of repeats, and save the value of repeats in a register
ix1 = op[2] # ID of source of data and destination of data
sop = op[3]
ix2 = op[4]
tix = op[5] # which slot is the time comparison in?
if tix in state_ix and step < state_ix[tix]:
return
sop = op[3] # type of conditional comparator
ix2 = op[4] # ID of the other operand
tix = op[5] # which slot is the time to start in?
ctr_ix = op[6] # id of the counter variable
num_ix = op[7] # max times to complete
if tix in state_ix and step < state_ix[tix]:
return
num_done = state_ix[ctr_ix]
num = state_ix[num_ix] # num to complete
if tix in state_ix and num_done >= num:
Expand All @@ -234,9 +237,7 @@ def step_special_action(op, state_ix, dict_ix, step):
elif sop == 5:
result = state_ix[ix1] / state_ix[ix2]

# set value in target
# tbd: handle this with a model linkage? cons: this makes a loop since the ix1 is source and destination

# set value in target. tbd: handle this with a model linkage? pros: dependencies. cons: this makes a loop since the ix1 is source and destination
state_ix[ix1] = result
state_ix[op[1]] = result
return result
Loading