Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
dpred = []
for i in range(1,11):
pred.append(data[vp.name][o+'['+str(i)+']'])
except:
pass
finally:
vp.__dict__[o] = dpred
else: #everything besides value, dpred and pred
vp.__dict__[o] = data[vp.name][o]
for vp in self._variables:
if vp.type != None: #(FV/MV/SV/CV) not Param or Var
for o in variable_options[vp.type]['outputs']+variable_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
else: #everything besides value and pred
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
#print all global options
file_content = self.options.getOverridesString()
#cycle through all Params and Vars to find set options
with open(os.path.join(self._path,filename), 'w+') as f:
f.write(file_content)
#check for set options of each Var and Param
for vp in self._parameters:
for o in parameter_options[vp.type]['inputs']+parameter_options[vp.type]['inout']:
if o == 'VALUE':
continue
else: #everything else is an option
if vp.__dict__[o] is not None:
f.write(vp.name+'.'+o+' = '+str(vp.__dict__[o])+'\n')
for vp in self._variables:
for o in variable_options[vp.type]['inputs']+variable_options[vp.type]['inout']:
if o == 'VALUE':
continue
else: #everything else is an option
if vp.__dict__[o] is not None:
f.write(vp.name+'.'+o+' = '+str(vp.__dict__[o])+'\n')
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]