def read_evaluation(inFile, skipBadData=True, verbose=False, reconstructResonances=False): ''' Read in the evaluation :param endfFile: the file name. This routine will attempt to determine the file type itself. :return: the evaluation as a dict of results like {'reactionSuite':the reaction suite, 'covarianceSuite': the covariances} ''' if not os.path.exists(inFile): raise IOError("File named " + inFile + " doesn't exist!") if open(inFile).readline().startswith("<?xml"): from fudge.gnd import reactionSuite return { 'reactionSuite': reactionSuite.readXML(inFile), 'covarianceSuite': None, 'info': {}, 'errors': [] } else: from fudge.legacy.converting import endfFileToGND return endfFileToGND.endfFileToGND( inFile, toStdOut=verbose, skipBadData=skipBadData, reconstructResonances=reconstructResonances)
def read(fileName, reactionSuite=None): """ This function uses the function **type** to determine the proper **FUDGE** function to call to read in the file *fileName* into **FUDGE**. It returns the **FUDGE** instance for the type. """ name, dummy = type(fileName) if (name == reactionSuiteModule.reactionSuite.moniker): return (reactionSuiteModule.readXML(fileName)) elif (name == covarianceSuiteModule.covarianceSuite.moniker): return (covarianceSuiteModule.readXML(fileName, reactionSuite)) return (databaseModule.database.readFile(fileName))
def getReactionSuite( filename, singleMTOnly = None ): try: RS = reactionSuiteModule.readXML( filename ) except: try: rce = endfFileToGND.endfFileToGND( filename, singleMTOnly = singleMTOnly, parseCrossSectionOnly = True, skipBadData = True ) RS, c = rce['reactionSuite'], rce['covarianceSuite'] except: print "File %s doesn't seem to be a legal ENDF or GND file!" % filename sys.exit() RS.originalFile = filename return RS
# Process command line options parser = argparse.ArgumentParser(description='Translate GND into ENDF') parser.add_argument('inFilePrefix', type=str, help='The prefix of the GND files you want to translate.') parser.add_argument('-o', dest='outFile', default=None, help='Specify the output file') args = parser.parse_args() # Compute input file names inEvalFile = args.inFilePrefix + '.gnd.xml' inCovFile = args.inFilePrefix + '.gndCov.xml' # Compute the output file name if args.outFile == None: outFile = args.inFilePrefix + '.endf' else: outFile = args.outFile # Read in XML files myEval = reactionSuite.readXML(inEvalFile) if os.path.exists(inCovFile): myCov = covariances.readXML(inCovFile, reactionSuite=myEval) else: myCov = None # Now translate open(outFile, mode='w').write(myEval.toENDF6({'verbosity': 0}, covarianceSuite=myCov))
from fudge.gnd import reactionSuite from fudge.gnd.covariances import covarianceSuite import site_packages.legacy.toENDF6.toENDF6 parser = argparse.ArgumentParser("""Translate one or more GND files to ENDF-6. Sample use: python gnd2endf.py n-001_H_001.xml n-001_H_002.xml ... If file n-001_H_001-cov.xml exists, covariances will automatically be read from it.""" ) parser.add_argument('-l', '--lineNumbers', action='store_true', help='Add line numbers') parser.add_argument('gnds', nargs="+", help="GND file(s) to translate") if __name__ == '__main__': args = parser.parse_args() for gndFile in args.gnds: gnd = reactionSuite.readXML(gndFile) gndCov = None for extension in ('-cov.xml', '-covar.xml'): tmp = gndFile.replace('.xml', extension) if os.path.exists(tmp): gndCov = covarianceSuite.readXML(tmp, reactionSuite=gnd) with open(os.path.basename(gndFile) + '.endf', 'w') as fout: fout.write( gnd.toENDF6('eval', flags={'verbosity': 0}, covarianceSuite=gndCov, lineNumbers=args.lineNumbers))
transportables = [] for particle in gids: gbs = valuesModule.values([ PQUModule.PQU(boundary, 'MeV').getValueAs(args.energyUnit) for boundary in bdfls.group(gids[particle]).gb ]) grid = axesModule.grid('energy_in', 0, args.energyUnit, axesModule.boundariesGridToken, gbs) group = groupModule.group(gids[particle], grid) transportables.append( transportablesModule.transportable( particle, transportablesModule.conserve.number, group)) #### read in GND file reactionSuite = reactionSuiteModule.readXML(args.gnd) if (reactionSuite.projectile != IDsPoPsModule.neutron): tempsDefault = 0 if (args.temperatures == None): args.temperatures = [tempsDefault] ### fail on detection of existing processed data for style in reactionSuite.styles: if (isinstance(style, stylesModule.heated) or isinstance(style, stylesModule.MC) or isinstance(style, stylesModule.multiGroup)): raise Exception( "File already contains processed data. Please use a clean file!") ### convert units if necessary reactionSuite.convertUnits({'MeV': args.energyUnit, 'eV': args.energyUnit}) convertedUnitsFileName = args.gnd.replace('.xml', '.%s.xml' % 'conv')
type=int, nargs='+', help='MT number(s) to plot') parser.add_argument('--temp', dest='temp', type=str, default=False, help="""Optional temperature for heating. Temperature should be given as a string with units. Possible values are '1200 K' or '0.1 eV/k' (quotes are required)""" ) args = parser.parse_args() filename = args.file[0] if open(filename).readline().startswith("<?xml"): from fudge.gnd import reactionSuite RS = reactionSuite.readXML(filename) else: from fudge.legacy.converting import endfFileToGND rce = endfFileToGND.endfFileToGND(filename) RS, CS = rce['reactionSuite'], rce['covarianceSuite'] reconstructed = False data = {} for MT in args.mt: reac = [r for r in RS if r.ENDF_MT == MT and hasattr(r, 'crossSection')] if not reac: print("MT %i not present in the file" % MT) continue reac = reac[0]
# herein do not necessarily state or reflect those of the United States Government or # Lawrence Livermore National Security, LLC, and shall not be used for advertising or # product endorsement purposes. # # <<END-copyright>> import argparse from fudge.gnd import reactionSuite from fudge.gnd.covariances import covarianceSuite import site_packages.legacy.toENDF6.toENDF6 FIRSTLINE=" $Rev:: 700 $ $Date:: 2016-01-13#$ 1 0 0 0" def process_args(): '''Process command line options''' parser = argparse.ArgumentParser(description="translates GND formatted files back into the ENDF format") parser.add_argument('evaluation', help="evaluation to translate") parser.add_argument('-c', dest='covariance', default=None, help='optional covariance file') parser.add_argument("-v", action="store_true", dest="verbose", help="enable verbose output") parser.add_argument("-q", action="store_false", dest="verbose", help="disable verbose output") return parser.parse_args() if __name__=="__main__": args=process_args() gnd=reactionSuite.readXML( args.evaluation ) if args.covariance is not None: cov=covarianceSuite.readXML( args.covariance ) else: cov=None outLines = gnd.toENDF6( 'eval', {'verbosity':args.verbose*10}, covarianceSuite = cov ).split('\n') endfTxt='\n'.join([FIRSTLINE,outLines[1].replace('-1',' 8')]+outLines[2:]) open( args.evaluation.replace('.gnd.xml','.endf'), mode='w' ).write(endfTxt)