respec / HSPsquared

Hydrologic Simulation Program Python (HSPsquared)
GNU Affero General Public License v3.0
43 stars 17 forks source link

Error when running hydro only RCHRES simulation #91

Closed rburghol closed 2 years ago

rburghol commented 2 years ago

Update: This is redundant to PR #88 which fixes the issue by continue when specific flags for RQUAL are missing or set to 1.

Overview

Currently, testing with hydrology only UCI from Chesapeake Bay watershed model fails due to missing blocks. Two errors are fixed:

  1. Lines at beginning of if activity == 'RQUAL' that stash copy of module flags in ui['FLAGS'] fails because it looks like ui['FLAGS'] does not get auto-populated when parsing a WDM without any RQUAL flags enabled.
  2. A 2nd error occurs because current code appears to invoke the RQUAL subroutine regardless of whether it is required, and if not set, the function rqual() is hard-wired to expect values that do not exist in the uci blocks passed to it.

Proposed Fix

Testing

Details

Continued testing with UCI & WDM files from the Chesapeake Bay watershed model (enhanced hspf 11.0). Running a hydro only simulation, hsp2 bails, and I think it is because it expects an "ADCALC" block and several other blocks, when processing activity RQUAL in main.py.

Obviously hydro-only is a bit of an edge case, but, nevertheless a robust simulation would handle this, and model development can be enhanced when one can run hydrology only till it gets sorted, then enable quality components. I thought I would post up here in case someone has already experienced this and can tell me that I am actually off base with my assumption of why it is crashing.

My debugging approach is to simply start adding some conditionals such that it checks the contents of the array returned by uci() before trying to access specific elements. For what it's worth, here are the messages:

Lines 149-151

                        if activity == 'RQUAL':
                            # RQUAL inputs:
                            ui['advectData'] = uci[(operation, 'ADCALC', segment)]['adcalcData']
                            if flags['HYDR']:
                                ui['PARAMETERS']['LKFG'] = uci[(operation, 'HYDR', segment)]['PARAMETERS']['LKFG']

Detailed run output below.

2022-06-14 16:44:38.40   Processing started for file OR1_7700_7980.h5; saveall=False
2022-06-14 16:44:38.92   Simulation Start: 1984-01-01 00:00:00, Stop: 2020-01-01 00:00:00
2022-06-14 16:44:38.92      RCHRES R001 DELT(minutes): 60
2022-06-14 16:44:43.08         HYDR
2022-06-14 16:44:45.59         RQUAL
Traceback (most recent call last):
  File "/home/rob/.local/bin/hsp2", line 11, in <module>
    load_entry_point('HSPsquared', 'console_scripts', 'hsp2')()
  File "/opt/model/HSPsquared/HSP2tools/HSP2_CLI.py", line 56, in main
    mando.main()
  File "/home/rob/.local/lib/python3.8/site-packages/mando/core.py", line 208, in __call__
    return self.execute(sys.argv[1:])
  File "/home/rob/.local/lib/python3.8/site-packages/mando/core.py", line 204, in execute
    return command(*a)
  File "/opt/model/HSPsquared/HSP2tools/HSP2_CLI.py", line 22, in run
    hsp2main(hdfname, saveall=saveall, jupyterlab=jupyterlab)
  File "/opt/model/HSPsquared/HSP2/main.py", line 149, in main
    ui['advectData'] = uci[(operation, 'ADCALC', segment)]['adcalcData']
KeyError: 'adcalcData'
rburghol commented 2 years ago

Update: This is redundant to PR https://github.com/respec/HSPsquared/pull/88 which fixes the issue by continue when specific flags for RQUAL are missing or set to 1.