Skip to content

Commit

Permalink
Merge pull request #102 from HARPgroup/psa
Browse files Browse the repository at this point in the history
Looks like a significant step towards getting Special Actions implemented!
  • Loading branch information
PaulDudaRESPEC authored Sep 30, 2022
2 parents 9caff7b + ab608e0 commit 504f3ec
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ tests/GLWACSO/HSP2results/hspp007.hdf
tests/GLWACSO/HSPFresults/hspf006.HBN
tests/GLWACSO/HSP2results/hspp007.uci
tests/test_report_conversion.html
tests/land_spec/hwmA51800.h5
3 changes: 2 additions & 1 deletion HSP2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def main(io_manager:IOManager, saveall:bool=False, jupyterlab:bool=True) -> None
uci = uci_obj.uci
siminfo = uci_obj.siminfo
ftables = uci_obj.ftables
specactions = uci_obj.specactions
monthdata = uci_obj.monthdata

start, stop = siminfo['start'], siminfo['stop']
Expand Down Expand Up @@ -392,4 +393,4 @@ def get_flows(io_manager:SupportsReadTS, ts, flags, uci, segment, ddlinks, ddmas
df.to_hdf(h2name, '/FLOWEXPANSION', format='t', data_columns=True)
'''
'''
1 change: 1 addition & 0 deletions HSP2/uci.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self) -> None:
self.siminfo = {}
self.opseq = DataFrame()
self.ftables = {}
self.specactions = {}
self.monthdata = None


Expand Down
4 changes: 3 additions & 1 deletion HSP2IO/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def read_uci(self) -> UCI:
"""
uci = UCI()

print("Called read_uci()")
for path in self._store.keys(): # finds ALL data sets into HDF5 file
op, module, *other = path[1:].split(sep='/', maxsplit=3)
s = '_'.join(other)
Expand Down Expand Up @@ -72,6 +72,8 @@ def read_uci(self) -> UCI:
for i in range(int(start), int(stop)+1): uci.ddgener[module][f'G{i:03d}'] = row[2]
elif op == 'FTABLES':
uci.ftables[module] = self._store[path]
elif op == 'SPEC_ACTIONS':
uci.specactions[module] = self._store[path]
elif op == 'MONTHDATA':
if not uci.monthdata: uci.monthdata = {}
uci.monthdata[f'{op}/{module}'] = self._store[path]
Expand Down
23 changes: 22 additions & 1 deletion HSP2tools/data/ParseTable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2394,4 +2394,25 @@
2330,GENER,OPCODE,GENER,OPCODES,OPNID,C,0,10,0
2331,GENER,OPCODE,GENER,OPCODES,OPCODE,I,11,16,0
2332,GENER,PARM,GENER,INFO,OPNID,C,0,10,0
2332,GENER,PARM,GENER,INFO,K,R,11,21,0.0E0
2332,GENER,PARM,GENER,INFO,K,R,11,21,0.0E0
2333,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,OPTYP,C,0,8,na
2334,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,RANGE1,C,8,11,na
2335,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,RANGE2,C,11,15,na
2336,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,DC,C,15,17,na
2337,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,DS,C,17,18,na
2338,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,YR,C,20,24,na
2339,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,MO,C,25,27,na
2340,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,DA,C,28,30,na
2341,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,HR,C,31,33,na
2342,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,MN,C,34,36,na
2343,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,D,C,36,38,2
2344,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,T,I,38,40,3
2345,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,VARI,C,42,48,na
2346,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,S1,C,48,51,na
2347,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,S2,C,51,54,na
2348,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,S3,C,54,55,na
2349,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,AC,C,57,60,na
2350,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,VALUE,R,60,70,0
2351,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,TC,C,71,73,na
2352,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,TS,C,74,77,na
2353,SPEC-ACTIONS,ACTIONS,SPEC-ACTIONS,SPEC-ACTIONS,NUM,C,77,80,na
54 changes: 54 additions & 0 deletions HSP2tools/readUCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def readUCI(uciname, hdfname):
if line[0:6] == 'IMPLND': operation(info, getlines(f),'IMPLND')
if line[0:6] == 'RCHRES': operation(info, getlines(f),'RCHRES')
if line[0:10] == 'MONTH-DATA': monthdata(info, getlines(f))
if line[0:12] == 'SPEC-ACTIONS': specactions(info, getlines(f))

colnames = ('AFACTR', 'MFACTOR', 'MLNO', 'SGRPN', 'SMEMN', 'SMEMSB',
'SVOL', 'SVOLNO', 'TGRPN', 'TMEMN', 'TMEMSB', 'TRAN', 'TVOL',
Expand Down Expand Up @@ -452,6 +453,59 @@ def ftables(info, llines):
lst.append(parseD(line, parse['FTABLES','FTABLE']))


def specactions(info, llines):
store, parse, path, *_ = info
lines = iter(llines)
# Notes:
# - Only "classic" special actions are handled here.
# - Other type of SA are recognized by the parser, but not stored in hdf5
# - The CURLVL code is a place-holder. This has not been thought through.
# - Each type of actions "head_[action type]" should include an "CURLVL"
# column to match with conditional expression if applicable
# - The value of CURLVL matches with an expression
sa_actions = [] # referred to as "classic" in old HSPF code comments
head_actions = ['OPERATION','RANGE1','RANGE2','DC','DS','YR','MO','DA','HR','MN','D','T','VARI', 'S1','S2','AC','VALUE','TC','TS','NUM', 'CURLVL']
sa_mult = []
head_mult = []
sa_uvquan = []
head_uvquan = []
sa_conditional = []
head_conditional = []
sa_distrb = []
head_distrb = []
sa_uvname = []
head_uvname = []
sa_if = []
head_if = []
in_if = False # are we in an if block?
curlvl = 0
for line in lines:
if line[2:5] == 'MULT':
sa_mult.append(line)
elif line[2:8] == 'UVQUAN':
sa_uvquan.append(line)
elif line[2:13] == 'CONDITIONAL':
sa_conditional.append(line)
elif line[2:8] == 'DISTRB':
sa_distrb.append(line)
elif line[2:8] == 'UVNAME':
sa_uvname.append(line)
# This CURLVL code is a place-holder. This has not been thought through.
elif line[0:2] == 'IF':
sa_if.append(line)
curlvl = len(sa_if)
elif line[0:7] == 'END IF':
sa_if.append(line)
curlvl = curlvl - 1
else:
# ACTIONS block
d = parseD(line, parse['SPEC-ACTIONS','ACTIONS'])
d['CURLVL'] = curlvl
sa_actions.append(d.copy())
if sa_actions:
dfftable = DataFrame(sa_actions, columns=head_actions).replace('na','')
dfftable.to_hdf(store, f'/SPEC_ACTIONS/ACTIONS', data_columns=True)

def ext(info, lines):
store, parse, path, *_ = info
lst = []
Expand Down
Loading

0 comments on commit 504f3ec

Please sign in to comment.