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
[x] How does Python/hsp2use the h5 file data?
Does it set values back to the timeseries in the h5 file?
Are there implicit pass by reference variables, for example in main _hydr_ loop initialization (before the actual timestep loop):
ts['ROVOL'] = ROVOL = zeros(steps)
Initializes the ROVOL in ts, also initializes a local variable ROVOL as a complete array for every step of the model run
Then, ROVOL[step] = rovol / VFACT is the only place in the code where any value storing occurs, suggesting that ts['ROVOL'] is aliased to ROVOL, and therefore, the storage is easy.
For SPECL path must be more explicit, because default method is to set ts[varname] where varname can cause name collisions:
specific BLOCK (low risk): low risk because individual variables in HSPF are quite distinct, with very little overlap between blocks (tho this might be possible)
segment ID: very high risk of overwrite, as for example one may read or apply special actions to multiple rchres or perland segments, and there is no way to discern them.
with save_timeseries knowing that if it gets the name "SPECL", or perhaps a more generic argument value that indicates "full path", it will iterate through the keys and parse them into the path constituents by splitting on "/"
OR, just use direct hdf5 write routine data_frame.to_hdf(self._store, path, format='t', data_columns=True, complevel=complevel)
import numpy as np
from numpy import zeros, any, full, nan, array, int64
steps = 5# adapted from HDRY:steps = int(ui['steps'])
ts['/RESULTS/RCHRES_001/SPECL/Qin'] = zeros[steps]
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
_hydr_
loop initialization (before the actual timestep loop):ts['ROVOL'] = ROVOL = zeros(steps)
ROVOL
as a complete array for every step of the model runROVOL[step] = rovol / VFACT
is the only place in the code where any value storing occurs, suggesting thatts['ROVOL']
is aliased toROVOL
, and therefore, the storage is easy.available_mgd = (Qreach - flowby) / 1.547
/timeseries/rchres_001/rovol
self.state['Qreach'] = ds['/timeseries/rchres_001/rovol']
and have it stay updated automatically? No need to call "getInputs()" method?Writing Referenced
ts
values with sub-componentsWork through
ts
writing. See also:save_timeseries
ts[varname]
where varname can cause name collisions:Qin = ts[
/RESULTS/RCHRES_001/IVOL] + ts[
/RESULTS/RCHRES_002/IVOL]
save_timeseries(store, ts, ui_specl['SAVE'], siminfo, saveall, 'SPECL', null, null)
save_timeseries
knowing that if it gets the name "SPECL", or perhaps a more generic argument value that indicates "full path", it will iterate through the keys and parse them into the path constituents by splitting on "/"hdf5
write routinedata_frame.to_hdf(self._store, path, format='t', data_columns=True, complevel=complevel)
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.])