def addGroup(self,rlz): """ Function to add a group into the database @ In, groupName, string, group name @ In, attributes, dict, dictionary of attributes that must be added as metadata @ In, source, File object, data source (for example, csv file) @ Out, None """ parentID = rlz.get("RAVEN_parentID",[None])[0] prefix = rlz.get("prefix") if prefix is not None: groupName = str(prefix[0] if not utils.isString(prefix) else prefix) else: # this can happen when we want to add sampler generated data (e.g. LimitSurface) in the database groupName = str(len(self.allGroupPaths)) if parentID: #If Hierarchical structure, firstly add the root group if not self.firstRootGroup or parentID == "None": self.__addGroupRootLevel(groupName,rlz) self.firstRootGroup = True self.type = 'DET' else: # Add sub group in the Hierarchical structure self.__addSubGroup(groupName,rlz) else: # Parallel structure (always root level) self.__addGroupRootLevel(groupName,rlz) self.firstRootGroup = True self.type = 'MC' self.h5FileW.attrs['allGroupPaths'] = _dumps(self.allGroupPaths) self.h5FileW.attrs['allGroupEnds'] = _dumps(self.allGroupEnds) self.h5FileW.flush()
def addScalar(self, target, name, value, root=None, pivotVal=None, attrs=None): """ Adds a node entry named "name" with value "value" to "target" node, such as <root> <target> <name>value<name> @ In, target, string, target parameter to add node value to @ In, name, string, name of characteristic of target to add @ In, value, string/float/etc, value of characteristic @ In, root, xml.etree.ElementTree.Element, optional, root to add to @ In, pivotVal, float, optional, unused (for consistency with dynamic mode) @ In, attrs, dict, optional, dictionary of attributes to be stored in the node @ Out, None """ if root is None: root = self.tree.getroot() else: if utils.isString(root): root = self._findTarg(self.tree.getroot(), root) #note: illegal unicode characters are checked for in xmlUtils methods targ = self._findTarg(root, target) if root.tag != target.strip() else root targ.append(xmlUtils.newNode(name, text=value, attrib=attrs))
def addMetaKeys(self, *args): """ Adds keywords to a list of expected metadata keys. @ In, args, list(str), keywords to register @ Out, None """ if any(not utils.isString(a) for a in args): self.raiseAnError('Arguments to addMetaKeys were not all strings:', args) self.metadataKeys = self.metadataKeys.union(set(args))
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.isString(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 addVector(self, target, name, valueDict, root=None, pivotVal=None, attrs=None, valueAttrsDict=None): """ Adds a node entry named "name" with value "value" to "target" node, such as <root> <target> <name> <with_respect_to_name1>value1 <with_respect_to_name2>value2 <with_respect_to_name3>value3 The valueDict should be as {with_respect_to_name1:value1, with_respect_to_name2:value2} For example, if the "name" is sensitivity_coefficients, each entry would be the sensitivity of "target" to "with_respect_to" parameters. @ In, target, string, target parameter to add node value to @ In, name, string, name of characteristic of target to add @ In, valueDict, dict, name:value @ In, root, xml.etree.ElementTree.Element, optional, root to add to @ In, pivotVal, float, optional, unused (for consistency with dynamic mode) @ In, attrs, dict, optional, dictionary of attributes to be stored in the node (name) @ In, valueAttrsDict, dict, optional, dictionary of attributes to be stored along the subnodes identified by the valueDict dictionary @ Out, None """ valAttribsDict = {} if valueAttrsDict is not None: valAttribsDict = valueAttrsDict if root is None: root = self.tree.getroot() else: if utils.isString(root): root = self._findTarg(self.tree.getroot(), root) targ = self._findTarg(root, target) if root.tag != target.strip() else root nameNode = xmlUtils.newNode(name, attrib=attrs) for key, value in valueDict.items(): nameNode.append( xmlUtils.newNode(key, text=value, attrib=valAttribsDict.get(key, None))) targ.append(nameNode)