def _writeXML(self,output,outputDictionary): """ Defines the method for writing the post-processor to the metadata within a data object @ In, output, DataObject, instance to write to @ In, outputDictionary, dict, dictionary stores importance ranking outputs @ Out, xml, xmlUtils.StaticXmlElement instance, written data in XML format """ if self.dynamic: outputInstance = xmlUtils.DynamicXmlElement('MetricPostProcessor', pivotParam=self.pivotParameter) else: outputInstance = xmlUtils.StaticXmlElement('MetricPostProcessor') if self.dynamic: for key, values in outputDictionary.items(): assert("|" in key) metricName, nodeName = key.split('|') for ts, pivotVal in enumerate(self.pivotValues): if values.shape[0] == 1: outputInstance.addScalar(nodeName, metricName,values[0], pivotVal=pivotVal) else: outputInstance.addScalar(nodeName, metricName,values[ts], pivotVal=pivotVal) else: for key, values in outputDictionary.items(): assert("|" in key) metricName, nodeName = key.split('|') if len(list(values)) == 1: outputInstance.addScalar(nodeName, metricName, values[0]) else: self.raiseAnError(IOError, "Multiple values are returned from metric '", metricName, "', this is currently not allowed") return outputInstance
def writeXML(self, what='all'): """ Called by the OutStreamPrint object to cause the ROM to print itself @ In, what, string, optional, keyword requesting what should be printed @ Out, xml, xmlUtils.StaticXmlElement, written meta """ #determine dynamic or static dynamic = self.supervisedEngine.isADynamicModel # determine if it can handle dynamic data handleDynamicData = self.supervisedEngine.canHandleDynamicData # get pivot parameter pivotParameterId = self.supervisedEngine.pivotParameterId # find some general settings needed for either dynamic or static handling ## get all the targets the ROMs have ROMtargets = self.supervisedEngine.initializationOptions[ 'Target'].split(",") ## establish requested targets targets = ROMtargets if what == 'all' else what.split(',') ## establish sets of engines to work from engines = self.supervisedEngine.supervisedContainer # if the ROM is "dynamic" (e.g. time-dependent targets), then how we print depends # on whether the engine is naturally dynamic or whether we need to handle that part. if dynamic and not handleDynamicData: # time-dependent, but we manage the output (chopped) xml = xmlUtils.DynamicXmlElement('ROM', pivotParam=pivotParameterId) ## pre-print printing engines[0].writeXMLPreamble( xml) #let the first engine write the preamble for s, rom in enumerate(engines): pivotValue = self.supervisedEngine.historySteps[s] #for target in targets: # should be handled by SVL engine or here?? # #skip the pivot param # if target == pivotParameterId: # continue #otherwise, call engine's print method self.raiseAMessage('Printing time-like', pivotValue, 'ROM XML') subXML = xmlUtils.StaticXmlElement( self.supervisedEngine.supervisedContainer[0].printTag) rom.writeXML(subXML, skip=[pivotParameterId]) for element in subXML.getRoot(): xml.addScalarNode(element, pivotValue) #xml.addScalarNode(subXML.getRoot(), pivotValue) else: # directly accept the results from the engine xml = xmlUtils.StaticXmlElement(self.name) ## pre-print printing engines[0].writeXMLPreamble(xml) engines[0].writeXML(xml) return xml
'B').text) if B == 2: results['pass'] += 1 else: print( 'ERROR: StaticXmlElement value failure: "newTarget.newVectorMetric.B = {}"' .format(B)) results['fail'] += 1 except AttributeError: print( 'ERROR: StaticXmlElement could not find newTarget.newVectorMetric.A!') results['fail'] += 1 # test DynamicXmlElement print('') dynamic = xmlUtils.DynamicXmlElement('testRoot', pivotParam='Time') values = {0.1: 1, 0.2: 1, 0.3: 2} for t, v in values.items(): dynamic.addScalar('newTarget', 'newMetric', v, t) try: times = dynamic.getRoot().findall('Time') for node in times: t = float(node.attrib['value']) v = float(node.find('newTarget').find('newMetric').text) if v == values[t]: results['pass'] += 1 else: print( 'ERROR: DynamicXmlElement value failure: "Time {} newTarget.newMetric = {}"' .format(t, v))