Closed rburghol closed 8 months ago
tests\test10\HSP2results
import h5py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# read in results hdf5 file
filename = 'test10.h5'
h5 = h5py.File(filename, 'r')
# extract results table from hdf5 as pandas dataframe
df = pd.DataFrame(np.array(h5['RESULTS']['RCHRES_R001']['HYDR']['table']))
# print all column names
print(list(df.columns.values))
# simple line plot
df.plot(kind='line',
x='index',
y=['OVOL1','IVOL'])
plt.show()
Overview (RFC)
This issue provides background information for pull request #119 which hs now been merged.
This PR contains code that:
develop
branch after STATE data PR #119river_model.h5
, automatically load code contained in local directory namedriver_model.py
.h5
file..state_step_hydr()
can modify STATE variables during the timestep execution of theHYDR/_hydr_
functions. See Dynamic Modifiers below.HYDR/_hydr_
function by callingstate_step_hydr()
if defined in the model run directory.@njit
function that supports the code. For example, using the dynjamic code in_hydr_()
shown below adds about 6-8 seconds for each and every model run, regardless of whether or not the dynamic code has been changed. Perhaps there is a better way?Tasks
Supported Functions & Special Variables
pre_step()
: things that happen at the beginning of the code loop, after normal data loading has occurredstep()
: things that happen during the computational portion of a model time-stepstate_step_hydr(state_ix, dict_ix, ts_ix, hydr_ix, step)
post_step()
: things that happen after a timestep is completed (ex: logging)get_ix
: a special function to retrieve local variable names with an implied path to the current domain )state_pre_step_[operation]()
state_step_[operation]()
state_post_step_[operation]()
state
: this is a multi-typed dict (not numba compatible) that is used to pass all the other Dicts related to statestate['domain']
: the current path to the/STATE/[operation]/[segment]
, this gets reset each time we switch segment or operationstate_paths
: this is the path that contains pointers from the full hdf5 paths for state variables to the corresponding unique integer key for thestate_ix
Dict.state_paths['domain']
= special entry instate_paths
that contains the integer key for the current/STATE/[operation]/[segment]
. This permitshydr_ix
: this is created automatically to hold shortcuts to HYDR variables for the current domain for brevity and fast code exec.state
dictionary inmain.py
- sets up basic sharednumba Dict
entries to pass to routines (includesstate_paths
,state_ix
,dict_ix
,ts_ix
,operation
,segment
, ...)state
as argument to operation function,def hydr(io_manager, siminfo, uci, ts, ftables, state):
state_ix, dict_ix, ts_ix, state_info, state_paths
as arguments to operationnumba
functionstate
becausenumba
cannot take mixed type Dictdef _hydr_(ui, ts, COLIND, OUTDGT, rowsFT, funct, Olabels, OVOLlabels, state_info, state_paths, state_ix, dict_ix, ts_ix)
state_ix, dict_ix, ts_ix, state_info, state_paths
as arguments when calling operationnumba
functionstate_step_[operation]
call if definedstate_step_[operation]
(optional, performance) Provide_get_ix
function for variables that wish to access state variable changes in the loopDynamic Loading of Code
state_step_hydr(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, hydr_ix, step)
Testing
statey
test10
test10.py
, editing the functionstate_step_hydr()
to explore interacting with state._hydr_()
has support implemented for STATE functions.IVOL
andOUTDGT
modifications are passed fromstate_ix
back into_hydr_
Code 1: Set a dynamic withdrawal in RCHRES R001. See also https://github.com/respec/HSPsquared/blob/99c0e629d88d0665bb45f10250691b2f0679967e/tests/test10/HSP2results/test10.py