Open rburghol opened 1 year ago
New object loader:
# bare bones tester
import os
os.chdir("C:/usr/local/home/git/HSPsquared")
from HSP2.main import *
from HSP2.om import *
#from HSP2.om_equation import *
state = init_state_dicts()
# set up info and timer
siminfo = {}
siminfo['delt'] = 60
siminfo['tindex'] = date_range("1984-01-01", "2020-12-31", freq=Minute(siminfo['delt']))[1:]
steps = siminfo['steps'] = len(siminfo['tindex'])
# get any pre-loaded objects
model_data = state['model_data']
( ModelObject.op_tokens, ModelObject.model_object_cache) = init_om_dicts()
ModelObject.state_paths, ModelObject.state_ix, ModelObject.dict_ix, ModelObject.ts_ix = state['state_paths'], state['state_ix'], state['dict_ix'], state['ts_ix']
( op_tokens, state_paths, state_ix, dict_ix, model_object_cache, ts_ix) = ( ModelObject.op_tokens, ModelObject.state_paths, ModelObject.state_ix, ModelObject.dict_ix, ModelObject.model_object_cache, ModelObject.ts_ix )
state_context_hsp2(state, 'RCHRES', 'R001', 'HYDR')
print("Init HYDR state context for domain", state['domain'])
hydr_init_ix(state, state['domain'])
# Now, assemble a test dataset
container = False
state_om_model_root_object(state, siminfo)
model_root_object = state['model_root_object']
src_json_node = 'http://deq1.bse.vt.edu/d.dh/node/62'
el_pid = 7405974 # appalachia reservoir on Bens Branch
json_url = src_json_node + "/" + str(el_pid)
# authentication using rest un and pw
jfile = open("/var/www/python/auth.private")
jj = json.load(jfile)
rest_uname = jj[0]['rest_uname']
rest_pass = jj[0]['rest_pw']
basic = HTTPBasicAuth(rest_uname, rest_pass )
# Opening JSON file
jraw = requests.get(json_url, auth=basic)
model_json = jraw.content.decode('utf-8')
# returns JSON object as Dicts
model_data = json.loads(model_json)
model_name = list(model_data.keys())[0]
model = model_object_cache['/STATE/' + model_name]
state['model_data'] = model_data
state_om_model_run_prep(state, False, siminfo)
op_tokens = state['op_tokens']
el_pid = 7113514
to the PID of the facility entity (or river entity) in questionmodel_loader_recursive()
)mjson = model_data['RCHRES_R001']['ARWA Chesdin Withdrawal']['historic_monthly_pct']
state_paths
and hit entermobj = model_object_cache['/STATE/RCHRES_R001/ARWA Chesdin Withdrawal/historic_monthly_pct']
mobj.handle_prop(mjson,'valuetype')
step_model()
function from the command prompt (need to load libraries, not shown below but an example is here ):step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, 1)
test_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step)
debug_tbl_eval(op_tokens, op_tokens[18], state_ix, dict_ix)