def addMetaKeys(self,args, params={}): """ Adds keywords to a list of expected metadata keys. @ In, args, list(str), keywords to register @ In, params, dict, optional, {key:[indexes]}, keys of the dictionary are the variable names, values of the dictionary are lists of the corresponding indexes/coordinates of given variable @ Out, None """ if any(not utils.isAString(a) for a in args): self.raiseAnError('Arguments to addMetaKeys were not all strings:',args) self.metadataKeys = self.metadataKeys.union(set(args)) self.metadataParams.update(params)
def _initializeLSpp(self, runInfo, inputs, initDict): """ Method to initialize the LS post processor (create grid, etc.) @ In, runInfo, dict, dictionary of run info (e.g. working dir, etc) @ In, inputs, list, list of inputs @ In, initDict, dict, dictionary with initialization options @ Out, None """ PostProcessor.initialize(self, runInfo, inputs, initDict) self.gridEntity = GridEntities.returnInstance("MultiGridEntity",self,self.messageHandler) self.externalFunction = self.assemblerDict['Function'][0][3] if 'ROM' not in self.assemblerDict.keys(): self.ROM = LearningGate.returnInstance('SupervisedGate','SciKitLearn', self, **{'SKLtype':'neighbors|KNeighborsClassifier',"n_neighbors":1, 'Features':','.join(list(self.parameters['targets'])), 'Target':[self.externalFunction.name]}) else: self.ROM = self.assemblerDict['ROM'][0][3] self.ROM.reset() self.indexes = -1 for index, inp in enumerate(self.inputs): if utils.isAString(inp) or isinstance(inp, bytes): self.raiseAnError(IOError, 'LimitSurface PostProcessor only accepts Data(s) as inputs. Got string type!') if inp.type == 'PointSet': self.indexes = index if self.indexes == -1: self.raiseAnError(IOError, 'LimitSurface PostProcessor needs a PointSet as INPUT!!!!!!') #else: # # check if parameters are contained in the data # inpKeys = self.inputs[self.indexes].getParaKeys("inputs") # outKeys = self.inputs[self.indexes].getParaKeys("outputs") # self.paramType = {} # for param in self.parameters['targets']: # if param not in inpKeys + outKeys: # self.raiseAnError(IOError, 'LimitSurface PostProcessor: The param ' + param + ' not contained in Data ' + self.inputs[self.indexes].name + ' !') # if param in inpKeys: # self.paramType[param] = 'inputs' # else: # self.paramType[param] = 'outputs' if self.bounds == None: dataSet = self.inputs[self.indexes].asDataset() self.bounds = {"lowerBounds":{},"upperBounds":{}} for key in self.parameters['targets']: self.bounds["lowerBounds"][key], self.bounds["upperBounds"][key] = min(dataSet[key].values), max(dataSet[key].values) #self.bounds["lowerBounds"][key], self.bounds["upperBounds"][key] = min(self.inputs[self.indexes].getParam(self.paramType[key],key,nodeId = 'RecontructEnding')), max(self.inputs[self.indexes].getParam(self.paramType[key],key,nodeId = 'RecontructEnding')) if utils.compare(round(self.bounds["lowerBounds"][key],14),round(self.bounds["upperBounds"][key],14)): self.bounds["upperBounds"][key]+= abs(self.bounds["upperBounds"][key]/1.e7) self.gridEntity.initialize(initDictionary={"rootName":self.name,'constructTensor':True, "computeCells":initDict['computeCells'] if 'computeCells' in initDict.keys() else False, "dimensionNames":self.parameters['targets'], "lowerBounds":self.bounds["lowerBounds"],"upperBounds":self.bounds["upperBounds"], "volumetricRatio":self.tolerance ,"transformationMethods":self.transfMethods}) self.nVar = len(self.parameters['targets']) # Total number of variables self.axisName = self.gridEntity.returnParameter("dimensionNames",self.name) # this list is the implicit mapping of the name of the variable with the grid axis ordering self.axisName[i] = name i-th coordinate self.testMatrix[self.name] = np.zeros(self.gridEntity.returnParameter("gridShape",self.name)) # grid where the values of the goalfunction are stored
def convert(cls, value): """ Converts value from string to a listi with string, integer, or float type. @ In, value, string, the value to convert @ Out, convert, list, the converted value """ values = value.split(",") base = utils.partialEval(values[0].strip()) # three possibilities: string, integer, or float if utils.isAString(base): conv = str elif utils.isAnInteger(base): conv = int else: #float conv = float return [conv(x.strip()) for x in values]
utils.isSingleValued(np.nan, nanOk=False), False) checkAnswer('isSingleValued inf ok', utils.isSingleValued(np.inf, nanOk=True), True) checkAnswer('isSingleValued nan ok', utils.isSingleValued(np.nan, nanOk=True), True) checkAnswer('isSingleValued array', utils.isSingleValued([1]), False) checkAnswer('isSingleValued set', utils.isSingleValued((1, )), False) checkAnswer('isSingleValued nparray', utils.isSingleValued(np.array([1])), False) checkAnswer('isSingleValued dict', utils.isSingleValued({1: 2}), False) # isAString # TODO how to get a string (not unicode) after import unicode literals? #checkAnswer('isAString string',utils.isAString(bytes_to_native_str(b'alpha')),True) checkAnswer('isAString strish', utils.isAString('alpha'), True) checkAnswer('isAString unicode', utils.isAString(u'beta'), True) checkAnswer('isAString float', utils.isAString(1.0), False) checkAnswer('isAString int', utils.isAString(1), False) checkAnswer('isAString bool', utils.isAString(True), False) # isAFloatOrInt checkAnswer('isAFloatOrInt 0', utils.isAFloatOrInt(0), True) checkAnswer('isAFloatOrInt 1', utils.isAFloatOrInt(1), True) checkAnswer('isAFloatOrInt 3.14', utils.isAFloatOrInt(3.14), True) checkAnswer('isAFloatOrInt str', utils.isAFloatOrInt('gamma'), False) checkAnswer('isAFloatOrInt bool', utils.isAFloatOrInt(True), False) checkAnswer('isAFloatOrInt nan ok', utils.isAFloatOrInt(np.nan), True) checkAnswer('isAFloatOrInt inf ok', utils.isAFloatOrInt(np.inf), True) checkAnswer('isAFloatOrInt nan not ok', utils.isAFloatOrInt(np.nan,