Example #1
0
def make_atomic_weight(h5_file='nuc_data.h5', data_file='atomic_weight.txt'):
    """Makes an atomic weight table and adds it to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * data_file (str): path to the atomic weight text file to load data from.
    """
    # Open the HDF5 File
    kdb = tb.openFile(h5_file, 'a')

    # Make a new the table
    Atable = kdb.createTable("/", "A", atomic_weight_desc, "Atomic Weight Data [amu]")
    nuc = Atable.row

    with open(data_file, 'r') as f:
        for line in f:
            ls = line.split()
            iso_LL = isoname.mixed_2_LLAAAM(ls[0])
            iso_zz = isoname.LLAAAM_2_zzaaam(iso_LL)

            nuc['iso_LL'] = iso_LL
            nuc['iso_zz'] = iso_zz
            nuc['value'] = float(ls[1])
            nuc['error'] = float(ls[2])
            nuc['abund'] = float(ls[3])

            # Insert nuclide to table
            nuc.append()

    # Ensure that data was written to table
    Atable.flush()

    # Close the hdf5 file
    kdb.close()
Example #2
0
def make_xs_1g(h5_file='nuc_data.h5', data_dir='xs_html/'):
    """Makes an atomic weight table and adds it to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * data_dir (str): path to that holds nuclide html one group neutron 
          cross section files.
    """
    # Get nulcide list from directory
    nuclist = [nuc.partition('.html')[0] for nuc in os.listdir(data_dir)]
    nuclist_zz = isoname.LLAAAM_2_zzaaam_List(nuclist)
    nuclist_zz.sort()
    nuclist = isoname.zzaaam_2_LLAAAM_List(nuclist_zz)

    # Open the HDF5 File
    kdb = tb.openFile(h5_file, 'a')

    # Create neutron group
    if not hasattr(kdb.root, 'neutron'):
        neutron_group = kdb.createGroup('/', 'neutron', 'Neutron Cross Sections')

    # Create xs_1g Group
    xs_1g_group = kdb.createGroup("/neutron", "xs_1g", "One Group Neutron Cross Section Data")

    # Loop through all energy types
    for xsef in xs_1g_energy_flags:
        # Create table for this energy 
        xs_1g_table = kdb.createTable(xs_1g_group, xsef, xs_1g_desc, "({0}) [barns]".format(xs_1g_energy_flags[xsef]))
        nucrow = xs_1g_table.row

        for nuc in nuclist:
            iso_LL = isoname.mixed_2_LLAAAM(nuc)
            iso_zz = isoname.LLAAAM_2_zzaaam(iso_LL)

            nucrow['iso_LL'] = iso_LL
            nucrow['iso_zz'] = iso_zz

            for xstf in xs_1g_type_flags:
                nucrow[xstf] = get_xs_from_html_file(nuc, data_dir, xs_1g_type_flags[xstf], xs_1g_energy_flags[xsef])

            nucrow['sigma_s'] = nucrow['sigma_e'] + nucrow['sigma_i']

            nucrow['sigma_a'] = nucrow['sigma_gamma'] + nucrow['sigma_f'] + nucrow['sigma_alpha'] + \
                                nucrow['sigma_proton'] + nucrow['sigma_deut'] + nucrow['sigma_trit'] + \
                                nucrow['sigma_2n'] + nucrow['sigma_3n'] + nucrow['sigma_4n']

            # Write out this row 
            nucrow.append()

        # Writr out this table
        xs_1g_table.flush()

    # Close the hdf5 file
    kdb.close()
Example #3
0
def nist_2_LLAAAM(nist_iso):
    """Converts a NIST style isotope to a LLAAAM style.

    Args:
        * nist_iso (str): A nist isotope.

    Returns:
        * iso_LL (int): a LLAAAM isotope.
    """
    m = re.match(nist_iso_pattern, nist_iso)

    iso_LL = isoname.mixed_2_LLAAAM(m.group(2) + m.group(1))

    return iso_LL
Example #4
0
 def test_mixed_2_LLAAAM(self):
     assert_equal(isoname.mixed_2_LLAAAM(952421),  "AM242M")
     assert_equal(isoname.mixed_2_LLAAAM("PU239"), "PU239")
     assert_equal(isoname.mixed_2_LLAAAM(94239),   "PU239")
Example #5
0
def make_decay(h5_file='nuc_data.h5', decay_file='decay.txt'):
    """Makes a decay table and adds it to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * decay_file (str): path to the decay text file to load data from.
    """
    # Open the hdf5 file
    decayfile = tb.openFile(h5_file, "a")

    # Get the HDF5 root group
    root = decayfile.root

    # Initialize decay table
    decaytbl = decayfile.createTable(root, "decay", decay_iso_desc, "Isotopic Deacy Information")

    # Now, fill the table:
    row = decaytbl.row

    # Read the text file
    with open(decay_file, 'r') as lib:
        for line in lib:
            ls = line.split()

            from_iso_LL = isoname.mixed_2_LLAAAM(ls[0])
            from_iso_zz = isoname.LLAAAM_2_zzaaam(from_iso_LL)            
       	    row['from_iso_LL'] = from_iso_LL
       	    row['from_iso_zz'] = from_iso_zz

	        # Set halflife
            if ls[1] == "inf":
    	        hl = 10.0**300
            else:
                hl = float(ls[1])
            row['half_life'] = hl

        	# Set decay constants
            row['decay_const'] = math.log(2.0) / hl

            # Set to iso
            if ls[2] == "None":
                to_iso_LL = from_iso_LL
                to_iso_zz = from_iso_zz
    	    else:
                to_iso_LL = isoname.mixed_2_LLAAAM(ls[2])
                to_iso_zz = isoname.LLAAAM_2_zzaaam(to_iso_LL)

            row['to_iso_LL'] = to_iso_LL
            row['to_iso_zz'] = to_iso_zz

            # Set branch ratio
            row['branch_ratio'] = float(ls[3])

            # This injects the Record values
            row.append()

        # Flush the table buffer
        decaytbl.flush()

    # Finally, close the HDF5 file 
    decayfile.close()