Skip to content

Commit

Permalink
load functions for ModelObject and SimTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgholzer authored and Burgholzer committed May 7, 2024
1 parent 8396388 commit c882806
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
25 changes: 6 additions & 19 deletions HSP2/om_model_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
It handles all Dict management functions, but provides for no runtime execution of it's own.
All runtime exec is done by child classes.
"""
from HSP2.state import *
from HSP2.om import *
from HSP2.state import set_state, get_state_ix
from HSP2.om import get_exec_order, is_float_digit
from pandas import Series, DataFrame, concat, HDFStore, set_option, to_numeric
from pandas import Timestamp, Timedelta, read_hdf, read_csv
from numpy import pad
from numpy import pad, asarray, zeros, int32
from numba import njit

class ModelObject:
state_ix = {} # Shared Dict with the numerical state of each object
Expand Down Expand Up @@ -75,15 +76,15 @@ def runnable_op_list(op_tokens, meo, debug = False):
for ix in meo:
if ix in run_ops.keys():
rmeo.append(ix)
rmeo = np.asarray(rmeo, dtype="i8")
rmeo = asarray(rmeo, dtype="i8")
return rmeo

@staticmethod
def model_format_ops(ops):
if (ModelObject.ops_data_type == 'ndarray'):
ops = pad(ops,(0,ModelObject.max_token_length))[0:ModelObject.max_token_length]
else:
ops = np.asarray(ops, dtype="i8")
ops = asarray(ops, dtype="i8")
return ops

def format_ops(self):
Expand Down Expand Up @@ -363,20 +364,6 @@ def step(self, step):
# easier to understand demonstrations
step_one(self.op_tokens, self.op_tokens[self.ix], self.state_ix, self.dict_ix, self.ts_ix, step)
#step_model({self.op_tokens[self.ix]}, self.state_ix, self.dict_ix, self.ts_ix, step)

def dddstep_model(op_tokens, state_ix, dict_ix, ts_ix, step):
for i in op_tokens.keys():
if op_tokens[i][0] == 1:
state_ix[i] = step_equation(op_tokens[i], state_ix)
elif op_tokens[i][0] == 2:
state_ix[i] = exec_tbl_eval(op_tokens[i], state_ix, dict_ix)
elif op_tokens[i][0] == 3:
step_model_link(op_tokens[i], state_ix, ts_ix, step)
elif op_tokens[i][0] == 4:
return False
elif op_tokens[i][0] == 5:
step_sim_timer(op_tokens[i], state_ix, dict_ix, ts_ix, step)
return

"""
The class ModelConstant is for storing constants. It must be loaded here because ModelObject calls it.
Expand Down
7 changes: 4 additions & 3 deletions HSP2/om_sim_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
It is also used to make an implicit parent child link to insure that an object is loaded
during a model simulation.
"""
from HSP2.state import *
from HSP2.om import *
from HSP2.state import set_state
from HSP2.om import ModelObject
from HSP2.om_model_object import ModelObject
from pandas import DataFrame, DatetimeIndex
from numba import njit
from numpy import int64

class SimTimer(ModelObject):
def __init__(self, name, container, siminfo):
Expand Down Expand Up @@ -57,7 +58,7 @@ def dti_to_time_array(self, siminfo):
dt = siminfo['delt']
# sim timer is special, one entry for each time component for each timestep
# convert DateIndex to numbers [int(i) for i in dateindex.year]
tdi = { 0: dateindex.astype(np.int64), 1:[float(i) for i in dateindex.year], 2:[float(i) for i in dateindex.month], 3:[float(i) for i in dateindex.day], 4:[float(i) for i in dateindex.hour], 5:[float(i) for i in dateindex.minute], 6:[float(i) for i in dateindex.second], 7:[float(i) for i in dateindex.weekday], 8:[float(dt) for i in dateindex], 9:[float(i) for i in dateindex.day_of_year], 10:[float(i) for i in dateindex.daysinmonth], 11:[float(dt * 60.0) for i in dateindex] }
tdi = { 0: dateindex.astype(int64), 1:[float(i) for i in dateindex.year], 2:[float(i) for i in dateindex.month], 3:[float(i) for i in dateindex.day], 4:[float(i) for i in dateindex.hour], 5:[float(i) for i in dateindex.minute], 6:[float(i) for i in dateindex.second], 7:[float(i) for i in dateindex.weekday], 8:[float(dt) for i in dateindex], 9:[float(i) for i in dateindex.day_of_year], 10:[float(i) for i in dateindex.daysinmonth], 11:[float(dt * 60.0) for i in dateindex] }
#tdi = { 0:dateindex.year, 1:dateindex.month, 2:dateindex.day, 3:dateindex.hour, 4:dateindex.minute, 5:dateindex.second }
tid = DataFrame(tdi)
h = 1 # added to increase row count for debug testing.
Expand Down

0 comments on commit c882806

Please sign in to comment.