Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def verify_input_options(self):
## Load data
f = open(os.path.join(self.path,'options.json'))
data = json.load(f)
f.close()
## Global Options
for o in self.options._input_option_list: #for each global input option
if o == 'CSV_READ' and self.csv_status == 'none':
continue
if self.options.__dict__[o] != data['APM'][o]: #compare APM to GK
print(str(o)+" was not written correctly") #give message if they don't match
## Local Options
for vp in self._parameters:
if vp.type != None: #(FV/MV/SV/CV) not Param or Var
for o in parameter_options[vp.type]['inputs']:
if o not in ['LB','UB']: #TODO: for o in data[vp.name] to avoid this check
if vp.__dict__[o] is not None and not self.like(vp.__dict__[o], data[vp.name][o]):
print(str(vp)+'.'+str(o)+" was not written correctly") #give message if they don't match
for vp in self._variables:
if vp.type != None: #(FV/MV/SV/CV) not Param or Var
for o in variable_options[vp.type]['inputs']:
if o not in ['LB','UB']:
if vp.__dict__[o] is not None and not self.like(vp.__dict__[o], data[vp.name][o]):
print(str(vp)+'.'+str(o)+" was not written correctly") #give message if they don't match
if self.time is not None:
json_data['time'] = self.jsonify(self.time)
#Constants can't and won't change so there's no reason to pass them in the JSON
#constant values must be given in the model file. Changing constant values requires recompiling the model.
# #constants
# if self._constants:
# const_dict = dict()
# for const in self._constants:
# const_dict['value'] = self.jsonify(const.value)
# const_dict[const.name] = const_dict
if self._parameters:
p_dict = dict()
for parameter in self._parameters:
o_dict = dict()
for o in parameter_options[parameter.type]['inputs']+parameter_options[parameter.type]['inout']:
if o == 'VALUE':
o_dict['VALUE'] = self.jsonify(parameter.value)
else:
o_dict[o] = getattr(parameter,o)
o_dict['type'] = parameter.type
p_dict[parameter.name] = o_dict
json_data['parameters'] = p_dict
if self._variables:
p_dict = dict()
for parameter in self._variables:
o_dict = dict()
for o in variable_options[parameter.type]['inputs']+variable_options[parameter.type]['inout']:
if o == 'VALUE':
o_dict['VALUE'] = self.jsonify(parameter.value)
else:
def load_JSON(self):
f = open(os.path.join(self._path,'options.json'))
data = json.load(f)
f.close()
#global (APM) options
for o in self.options._output_option_list+self.options._inout_option_list:
self.options.__dict__[o] = data['APM'][o]
#Variable options (FV/MV/SV/CV)
for vp in self._parameters:
if vp.type != None: #(FV/MV/SV/CV) not Param or Var
for o in parameter_options[vp.type]['outputs']+parameter_options[vp.type]['inout']:
if o == 'VALUE':
continue
elif o == 'PRED': #Pred can be an array of up to 10
if o in data[vp.name]: #single value
vp.__dict__[o] = data[vp.name][o]
else:
try: #fill in an array up to 10 values
pred = []
for i in range(11):
pred.append(data[vp.name][o+'['+str(i)+']'])
except:
pass
finally:
vp.__dict__[o] = pred
elif o == 'DPRED': #Pred can be an array of up to 10
if o in data[vp.name]: #single value
def __setattr__(self, name, value):
if self._initialized:
#ignore cases on global options
name = name.upper()
#only allow user to set input or input/output options:
if name in options[self.type]['inputs']+options[self.type]['inout']:
if name == 'VALUE':
# Extract input array from pandas series if needed
if type(value).__name__ == 'Series':
value = value.values
self.__dict__[name].value = value
else:
self.__dict__[name] = value
#don't allow writing to output properties by default
elif name in options[self.type]['outputs']:
#define outputs by passing list/tuple with 1st element being True
#to override the output writing prevention
try:
if value[0] == True:
self.__dict__[name] = value[1]