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

Write a parser for basic SPECL (just setting variables till we decide on our final approach) #24

Closed
Tracked by #5
rburghol opened this issue Sep 2, 2022 · 3 comments
Assignees

Comments

@rburghol
Copy link

rburghol commented Sep 2, 2022

RESPEC issue development here: respec#99

  • use branch psa https://github.com/HARPgroup/HSPsquared/tree/psa
  • just parse, don't do anything. Parse and print out debug info.
  • later merge with specl
  • psa branch now successfully parses the "classic" style of special action, which just sets a state variable value
    • in main.py the variable specactions is populated, and can be viewed as: print(specactions['ACTIONS']['VALUE'])

Testing dataset:

git fetch origin psa
git checkout psa
git pull origin psa
cd [some dir]
wget https://deq1.bse.vt.edu/hsp2/land_spec.tar.gz
tar -xvf land_spec.tar.gz
cd land_spec
hsp2 import_uci hwmA51800.uci hwmA51800.h5
hsp2 run hwmA51800.h5

How Parsing is Done in hsp2

  • All parsing code is in
  • File HSP2tools/data/ParseTable.csv has lines for each supported UCI block
    • Lines are in format `#,section,block,routine,type' and
    • then the next 5 CSV items are the actual column description:
      • name, type_, start, end, default
    • One line per column in the UCI block
    • Ex: 1479,RCHRES,HYDR-PARM1,HYDR,PARAMETERS,OPNID,C,0,11, 1480,RCHRES,HYDR-PARM1,HYDR,PARAMETERS,VCONFG,I,11,14,0
  • Code parseD (and parseD2 and parseD3) support different parse styles (hsp2 is not always consistent maybe?)
    • But all parseX()rely onfield = line[start:end].strip(), where start:endare in standar python array notation where start is the 0-based index and the end is the next non-used number. Ex:"abcdefg"[0:3] = "abc", which is array entries 0, and 2 -- not including entry 3.
@rburghol
Copy link
Author

rburghol commented Sep 2, 2022

Hey @jdkleiner check this out when you get to a place where we want to start loading data.

@rburghol
Copy link
Author

rburghol commented Sep 26, 2022

Testing:

Find and load the h5 file

library("rhdf5")
dir()
[1] "hwmA51800.h5"          "hwmA51800.uci"         "hwmA51800.wdm"
[4] "met_A51800.wdm"        "prad_A51800.wdm"       "pytables-8ng29y_8.tmp"

h5_file_path = "hwmA51800.h5"
fid = H5Fopen(h5_file_path) # Opens the h5 file, fid is a h5 identifier

Look for the SPECL table

  • this works, but shows that the data parsing is off since all are NaN
data_source_table = "/SPEC_ACTIONS/ACTIONS/table"
did = H5Dopen(fid, data_source_table)

# alternative when conversion errors occur data <- H5Dread(did, bit64conversion = "double")
h5read(fid, "/SPEC_ACTIONS/ACTIONS/table")[1:2,]
  index OPERATION RANGE1 RANGE2 DC DS   YR MO DA HR MN D T VARI S1 S2 AC
1     0       NaN      1        DY    1984  1  1 12    2 3 FNO3       +=
2     1       NaN      1        DY    1984  2  1 12    2 3 FNO3       +=
     VALUE TC TS NUM CURLVL
1 0.000000                1
2 0.090044                1

Test the EXT SOURCES table

  • this works fine, indicating that its parsing is sound
> h5read(fid, "/CONTROL/EXT_SOURCES/table")[1:2,]
  index SVOL SVOLNO SMEMN SMEMSB SSYST SGAPST MFACTOR TRAN   TVOL TGRPN  TMEMN
1     0    * TS1000  EVAP     31  ENGL          1.082 SAME PERLND       PETINP
2     1    * TS1001  DEWP     31  ENGL          1.000 SAME PERLND        DTMPG
  TMEMSB TVOLNO COMMENT
1          P001
2          P001

@rburghol
Copy link
Author

  HYDR-INIT
    RCHRES  Initial conditions for HYDR section    ***
    # -  #       VOL     Initial  value  of COLIND *** Initial  value  of OUTDGT
             (ac-ft)     for  each  possible  exit *** for  each  possible  exit
                           EX1  EX2  EX3  EX4  EX5 ***   EX1  EX2  EX3  EX4  EX5
    1            30.       4.0  5.0
    2    5       0.0       4.0
  END HYDR-INIT

HSPF Manual 12.2
image

@rburghol rburghol closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant