HARPgroup / HSPsquared

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

Setting data in `ts` and `ui`, pass by reference in python functions #19

Closed rburghol closed 1 year ago

rburghol commented 2 years ago

Overview

The most basic foundation of HSPF Special Actions was the creation of custom state variables, and updating of system state variables. Determine how to do this in hsp2

Writing Referenced ts values with sub-components

Work through ts writing. See also:

initialize the columns... very important

ts = { '/RESULTS/RCHRES_001/SPECL/Qlocal':zeros(steps), '/RESULTS/RCHRES_001/SPECL/Qin':zeros(steps), '/RESULTS/RCHRES_001/SPECL/Qout':zeros(steps) }

now populate some values into the Qlocal variable

ts['/RESULTS/RCHRES_001/SPECL/Qlocal'][3] = 2.0 ts['/RESULTS/RCHRES_001/SPECL/Qlocal'][1] = 7.0

do this calc in direct evaluation

ts['/RESULTS/RCHRES_001/SPECL/Qout'] = ts['/RESULTS/RCHRES_001/SPECL/Qlocal'] + ts['/RESULTS/RCHRES_001/SPECL/Qin']

do calculation using indirect evaluation via eval()

ts['/RESULTS/RCHRES_001/SPECL/Qout'] = eval(\"ts['/RESULTS/RCHRES_001/SPECL/Qlocal'] + ts['/RESULTS/RCHRES_001/SPECL/Qin']\")

print out the result

ts['/RESULTS/RCHRES_001/SPECL/Qout'] array([0., 7., 0., 2., 0.])