def open_partial_library(self): """Select and open an ACE file and store data in memory.""" filename = QFileDialog.getOpenFileName( self, "Load ACE Library", "./", "ACE Libraries (*)" ) table_names, completed = QInputDialog.getText( self, "Nuclides", "Enter nuclides:" ) if completed: table_names = str(table_names).split() else: return try: if filename: # Parse ACE library lib = ace.Library(filename) lib.read(table_names) # Append tables into self.tables object for table in lib.tables.values(): self.tables.append(table) except: pass # Sort tables based on name self.tables.sort(key=lambda table: table.name) # Reset combo box self.populate_reactions()
def main(): """ Converts ACE files into the ROOT format""" parser = argparse.ArgumentParser( description=main.__doc__, epilog='Homepage: https://github.com/kbat/mc-tools') parser.add_argument('acefile', type=str, help='input ACE file name') parser.add_argument('rootfile', type=str, default="", nargs='?', help='output ROOT file name') args = parser.parse_args() if not os.path.isfile(args.acefile): print("ace2root: File %s does not exist." % args.acefile, file=sys.stderr) sys.exit(1) if args.rootfile == "": rootFileName = "%s%s" % (args.acefile, ".root") else: rootFileName = args.rootfile lib = ace.Library(args.acefile) lib.read() ntables = len(lib.tables) if not ntables: print("ace2root: no tables found in", args.acefile, file=sys.stderr) sys.exit(2) # else: # print(ntables, "tables found") rootfile = ROOT.TFile(rootFileName, "recreate") for tname in lib.tables: table = lib.tables[tname] # print(tname, table.reactions) newdir = ROOT.gDirectory.mkdir(tname, "") newdir.cd() for mt in table.reactions: reaction = table.find_reaction(mt) # print(reaction.text) gr = ROOT.TGraph(len(table.energy), table.energy, reaction.sigma) gr.SetName("mt%s" % str(mt)) gr.SetTitle("%s #bullet MT=%d;Enegy [MeV];#sigma [barn]" % (tname, mt)) gr.Write() rootfile.cd() rootfile.Close()
def _load_reaction(self, nuc, rx, temp=300.0): """Loads reaction data from ACE files indexed by OpenMC. Parameters ---------- nuc : int Nuclide id. rx : int Reaction id. temp : float, optional The nuclide temperature in [K]. """ rx = rxname.id(rx) try: mt = rxname.mt(rx) except RuntimeError: return None totrx = rxname.id('total') absrx = rxname.id('absorption') ace_tables = self._rank_ace_tables(nuc, temp=temp) lib = ntab = None for atab in ace_tables: if atab not in self.libs: lib = self.libs[atab] = ace.Library(atab.abspath or atab.path) lib.read(atab.name) lib = self.libs[atab] ntab = lib.tables[atab.name] if mt in ntab.reactions or rx == totrx or rx == absrx: break lib = ntab = None if lib is None: return None # no reaction available E_g = self.src_group_struct E_points = ntab.energy if rx == totrx: rawdata = ntab.sigma_t elif rx == absrx: rawdata = ntab.sigma_a else: ntabrx = ntab.reactions[mt] if ntabrx.IE is None or ntabrx.IE == 0: rawdata = ntabrx.sigma else: rawdata = np.empty(len(E_points), dtype='f8') rawdata[:ntabrx.IE] = 0.0 rawdata[ntabrx.IE:] = ntabrx.sigma if (E_g[0] <= E_g[-1] and E_points[-1] <= E_points[0]) or \ (E_g[0] >= E_g[-1] and E_points[-1] >= E_points[0]): E_points = E_points[::-1] rawdata = rawdata[::-1] rxdata = bins.pointwise_linear_collapse(E_g, E_points, rawdata) return rxdata
def load(self, temp=300.0): """Loads the entire data source into memory. This can be expensive for lots of ACE data. Parameters ---------- temp : float, optional Temperature [K] of material, defaults to 300.0. """ for atab in self.cross_sections.ace_tables: lib = self.libs[atab] = ace.Library(atab.abspath or atab.path) lib.read(atab.name)
def open_library(self): """Select and open an ACE file and store data in memory.""" filename = QFileDialog.getOpenFileName(self, "Load ACE Library", "./", "ACE Libraries (*)") try: if filename: # Parse ACE library lib = ace.Library(filename) lib.read() # Append tables into self.tables object for table in lib.tables.values(): self.tables.append(table) except: pass # Sort tables based on name self.tables.sort(key=lambda table: table.name) # Reset combo box self.populate_reactions()
def pointwise(self, nuc, rx, temp=300.0): """Returns pointwise reaction data from ACE files indexed by OpenMC. Parameters ---------- nuc : int Nuclide id. rx : int Reaction id. temp : float, optional The nuclide temperature in [K]. Returns ------- E_points : array-like The array or energy points that the reaction is evaluated at. rawdata : array-like Raw pointwise reaction data. """ nuc = nucname.id(nuc) rx = rxname.id(rx) try: mt = rxname.mt(rx) except RuntimeError: return None totrx = rxname.id("total") absrx = rxname.id("absorption") ace_tables = self._rank_ace_tables(nuc, temp=temp) lib = ntab = None for atab in ace_tables: if os.path.isfile(atab.abspath or atab.path): if atab not in self.libs: lib = self.libs[atab] = ace.Library(atab.abspath or atab.path) lib.read(atab.name) lib = self.libs[atab] ntab = lib.tables[atab.name] if mt in ntab.reactions or rx == totrx or rx == absrx: break lib = ntab = None if lib is None: return None # no reaction available E_g = self.src_group_struct E_points = ntab.energy if rx == totrx: rawdata = ntab.sigma_t elif rx == absrx: rawdata = ntab.sigma_a else: ntabrx = ntab.reactions[mt] if ntabrx.IE is None or ntabrx.IE == 0: rawdata = ntabrx.sigma else: rawdata = np.empty(len(E_points), dtype="f8") rawdata[:ntabrx.IE] = 0.0 rawdata[ntabrx.IE:] = ntabrx.sigma if (E_g[0] <= E_g[-1] and E_points[-1] <= E_points[0]) or ( E_g[0] >= E_g[-1] and E_points[-1] >= E_points[0]): E_points = E_points[::-1] rawdata = rawdata[::-1] return E_points, rawdata
#============================ Define max scattering order Lmax = 9 #============================ Plot properties plot_xmin = 1e-10 plot_xmax = 200 plot_ymin = 1e-6 plot_ymax = 1e6 #XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # DONT CHANGE ANYTHING BELOW THIS #============================ Extracting ACE data print("A=%f" % A) pyne_libfile = pyne_ace.Library(AcePath + Acefile) pyne_libfile.read() pyne_XSTable = pyne_libfile.tables[Acefile] print('The following reactions are available:') print('<ACE Reaction: MT=1 >') for MT in pyne_XSTable: print(MT) pyne_E = pyne_XSTable.energy pyne_sigma_t = pyne_XSTable.sigma_t pyne_sigma_s = pyne_XSTable.reactions[2].sigma pyne_sigma_a = pyne_XSTable.reactions[102].sigma out_sigma_t = np.zeros((G))
import math import numpy, sys, cPickle, copy import matplotlib.pyplot as plt from MCNPtools.to_energy import to_energy from MCNPtools.to_wavelength import to_wavelength plt.rc('text', usetex=True) plt.rc('font', family='serif') plt.rc('font', size=12) #prefix = '/usr/local/LANL/MCNP6_DATA' prefix = '/home/l_bergmann/LANL/MCNP6_DATA' # xs o16_lib = ace.Library(prefix + '/xdata/endf71x/O/8016.710nc') al27_lib = ace.Library(prefix + '/xdata/endf71x/Al/13027.710nc') # sab al27_sab_lib = ace.Library(prefix + '/xdata/ENDF71SaB/al27.22t') sapp_sab_lib = ace.Library(prefix + '/sapphire') # read o16_lib.read() al27_lib.read() al27_sab_lib.read() sapp_sab_lib.read() # get libs o16_lib = o16_lib.tables['8016.710nc'] al27_lib = al27_lib.tables['13027.710nc']