def updateModelResultsXMLFieldInfo(filename, newFieldResult, prettyPrint=True): """Update an existing XML record of a :class:`.ModelResult` with info about a particular fieldResult.""" assert filename != "" xmlDoc = etree.parse(filename) root = xmlDoc.getroot() # Because we just grabbed a reference to the root, the find will # look relative to the root fieldResultsNode = xmlDoc.find( fields.FieldComparisonResult.XML_INFO_LIST_TAG) # It may not exist, if there were no field results already, # in which case grab existing if fieldResultsNode is None: fieldResultsNode = etree.SubElement( root, fields.FieldComparisonResult.XML_INFO_LIST_TAG) else: # TODO: Check the field to add is not in the list already pass newFieldResult.writeInfoXML(fieldResultsNode) # Write the file, default name if filename provided is empty outFile = open(filename, 'wb') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close()
def writeRecordXML(self, outputDir="", filename="", prettyPrint=True): """Write an XML record of a :class:`.ModelResult`.""" if filename == "": filename = self.defaultRecordFilename() if outputDir == "": outputDir = self.outputPath # Write extra model results, e.g. # create model file mrNode = etree.Element(self.XML_INFO_TAG) xmlDoc = etree.ElementTree(mrNode) etree.SubElement(mrNode, 'modelName').text = self.modelName etree.SubElement(mrNode, 'outputPath').text = self.outputPath if self.jobMetaInfo is not None: self.jobMetaInfo.writeInfoXML(mrNode) if (self.fieldResults): fieldResultsNode = etree.SubElement( mrNode, fields.FieldComparisonResult.XML_INFO_LIST_TAG) for fieldResult in self.fieldResults: fieldResult.writeInfoXML(fieldResultsNode) # Write the files if not os.path.exists(outputDir): os.makedirs(outputDir) fullPath = os.path.join(outputDir, filename) outFile = open(fullPath, 'wb') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close() return fullPath
def writeRecordXML(self, outputDir="", filename="", prettyPrint=True): """Write an XML record of a :class:`.ModelResult`.""" if filename == "": filename = 'ModelResult-' + self.modelName + '.xml' if outputDir == "": outputDir = self.outputPath # Write extra model results, e.g. # create model file # TODO: [Refactor] modified this from 'StgModelResult', check if okay mrNode = etree.Element(self.__class__.__name__) xmlDoc = etree.ElementTree(mrNode) etree.SubElement(mrNode, 'modelName').text = self.modelName etree.SubElement(mrNode, 'outputPath').text = self.outputPath if self.jobMetaInfo is not None: self.jobMetaInfo.writeInfoXML(mrNode) # if (self.fieldResults): # fieldResultsNode = etree.SubElement(mrNode, # fields.FieldComparisonResult.XML_INFO_LIST_TAG) # for fieldResult in self.fieldResults: # fieldResult.writeInfoXML(fieldResultsNode) # Write the files if not os.path.exists(outputDir): os.makedirs(outputDir) fullPath = os.path.join(outputDir, filename) outFile = open(fullPath, 'wb') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close() return fullPath
def updateModelResultsXMLFieldInfo(filename, newFieldResult, prettyPrint=True): """Update an existing XML record of a :class:`.ModelResult` with info about a particular fieldResult.""" assert filename != "" xmlDoc = etree.parse(filename) root = xmlDoc.getroot() # Because we just grabbed a reference to the root, the find will # look relative to the root fieldResultsNode = xmlDoc.find(fields.FieldComparisonResult.XML_INFO_LIST_TAG) # It may not exist, if there were no field results already, # in which case grab existing if fieldResultsNode is None: fieldResultsNode = etree.SubElement(root, fields.FieldComparisonResult.XML_INFO_LIST_TAG) else: # TODO: Check the field to add is not in the list already pass newFieldResult.writeInfoXML(fieldResultsNode) # Write the file, default name if filename provided is empty outFile = open(filename, 'w') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close()
def writeRecordXML(self, outputDir="", filename="", prettyPrint=True): """Write an XML record of a :class:`.ModelResult`.""" if filename == "": filename = self.defaultRecordFilename() if outputDir == "": outputDir = self.outputPath # Write extra model results, e.g. # create model file mrNode = etree.Element(self.XML_INFO_TAG) xmlDoc = etree.ElementTree(mrNode) etree.SubElement(mrNode, 'modelName').text = self.modelName etree.SubElement(mrNode, 'outputPath').text = self.outputPath if self.jobMetaInfo is not None: self.jobMetaInfo.writeInfoXML(mrNode) if (self.fieldResults): fieldResultsNode = etree.SubElement(mrNode, fields.FieldComparisonResult.XML_INFO_LIST_TAG) for fieldResult in self.fieldResults: fieldResult.writeInfoXML(fieldResultsNode) # Write the files if not os.path.exists(outputDir): os.makedirs(outputDir) fullPath = os.path.join(outputDir, filename) outFile = open(fullPath, 'w') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close() return fullPath
def writeInfoXML(self, writePath="", filename="", update=False, prettyPrint=True): """Writes an XML recording the key details of this ModelRun, in CREDO format - useful for benchmarking etc. `writePath` and `filename` can be specified, if not they will use default values (the outputPath of the model, and the value returned by :attr:`defaultModelRunFilename()`, respectively).""" if filename == "": filename = self.defaultModelRunFilename() if writePath == "": writePath = os.path.join(self.basePath, self.outputPath) writePath += os.sep # create XML document root = etree.Element('StgModelRun') xmlDoc = etree.ElementTree(root) # Write key entries: # Model description (grab from XML file perhaps) name = etree.SubElement(root, 'name') name.text = self.name filesList = etree.SubElement(root, 'modelInputFiles') for xmlFilename in self.modelInputFiles: modFile = etree.SubElement(filesList, 'inputFile') modFile.text = xmlFilename etree.SubElement(root, 'basePath').text = self.basePath etree.SubElement(root, 'outputPath').text = self.outputPath if self.cpReadPath: etree.SubElement(root, 'cpReadPath').text = self.cpReadPath self.jobParams.writeInfoXML(root) if not self.simParams: # In this case: # We will write a copy of the simParams read from actual model # XMLs, plus the over-ride parameters) simParams = self.getSimParams() simParams.writeInfoXML(root) else: self.simParams.writeInfoXML(root) writeParamOverridesInfoXML(self.paramOverrides, root) writeSolverOptsInfoXML(self.solverOpts, root) analysisNode = etree.SubElement(root, 'analysisOps') for opName, analysisOp in self.analysisOps.iteritems(): analysisOp.writeInfoXML(analysisNode) # TODO : write info on cpFields? # Write the file if not os.path.exists(writePath): os.makedirs(writePath) outFile = open(writePath + filename, 'w') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close() return writePath + filename
def writeInfoXML(self, writePath="", filename="", update=False, prettyPrint=True): """Writes an XML recording the key details of this ModelRun, in CREDO format - useful for benchmarking etc. `writePath` and `filename` can be specified, if not they will use default values (the outputPath of the model, and the value returned by :attr:`defaultModelRunFilename()`, respectively).""" if filename == "": filename = self.defaultModelRunFilename() if writePath == "": writePath=os.path.join(self.basePath, self.outputPath) writePath+=os.sep # create XML document root = etree.Element('StgModelRun') xmlDoc = etree.ElementTree(root) # Write key entries: # Model description (grab from XML file perhaps) name = etree.SubElement(root, 'name') name.text = self.name filesList = etree.SubElement(root, 'modelInputFiles') for xmlFilename in self.modelInputFiles: modFile = etree.SubElement(filesList, 'inputFile') modFile.text = xmlFilename etree.SubElement(root, 'basePath').text = self.basePath etree.SubElement(root, 'outputPath').text = self.outputPath if self.cpReadPath: etree.SubElement(root, 'cpReadPath').text = self.cpReadPath self.jobParams.writeInfoXML(root) if not self.simParams: # In this case: # We will write a copy of the simParams read from actual model # XMLs, plus the over-ride parameters) simParams = self.getSimParams() simParams.writeInfoXML(root) else: self.simParams.writeInfoXML(root) writeParamOverridesInfoXML(self.paramOverrides, root) writeSolverOptsInfoXML(self.solverOpts, root) analysisNode = etree.SubElement(root, 'analysisOps') for opName, analysisOp in self.analysisOps.iteritems(): analysisOp.writeInfoXML(analysisNode) # TODO : write info on cpFields? # Write the file if not os.path.exists(writePath): os.makedirs(writePath) outFile = open(writePath+filename, 'w') writeXMLDoc(xmlDoc, outFile, prettyPrint) outFile.close() return writePath+filename