Example #1
0
def test_expand_elements2():
    """Inspired by #86"""
    natmat = Material({'C': 1.0})
    expmat = natmat.expand_elements()
    afrac = expmat.to_atom_frac()
    assert_almost_equal(data.natural_abund(60120000), afrac[60120000])
    assert_almost_equal(data.natural_abund(60130000), afrac[60130000])
Example #2
0
def test_expand_elements2():
    """Inspired by #86"""
    natmat = Material({'C': 1.0})
    expmat = natmat.expand_elements()
    afrac = expmat.to_atom_frac()
    assert_almost_equal(data.natural_abund(60120000), afrac[60120000])
    assert_almost_equal(data.natural_abund(60130000), afrac[60130000])
Example #3
0
def test_natural_abund_excited_state():
    # initialize natural_abund_map
    gnd = 902320000
    excited = gnd + 1
    data.natural_abund(gnd)
    # excited state should not be in the map yet
    assert_equal(data.natural_abund_map.get(excited), None)
    nabund = data.natural_abund(excited)
    assert_equal(nabund, data.natural_abund_map.get(excited))
Example #4
0
def test_natural_abund_excited_state():
    # initialize natural_abund_map
    gnd = 902320000
    excited = gnd + 1
    data.natural_abund(gnd)
    # excited state should not be in the map yet
    assert_equal(data.natural_abund_map.get(excited), None)
    nabund = data.natural_abund(excited)
    assert_equal(nabund, data.natural_abund_map.get(excited))
Example #5
0
def test_natural_abund_excited_state():
    # set the datapath to nonsense so we call, the cpp data version
    orig = pyne_conf.NUC_DATA_PATH
    pyne_conf.NUC_DATA_PATH = b"bobbobhonkeytonk"
    # initialize natural_abund_map
    gnd = 902320000
    excited = gnd + 42
    data.natural_abund(gnd)
    # excited state should not be in the map yet
    assert_true(excited not in data.natural_abund_map)
    nabund = data.natural_abund(excited)
    assert_equal(nabund, data.natural_abund_map.get(excited))
    pyne_conf.NUC_DATA_PATH = orig
Example #6
0
def make_elements():
    """Make natural elemental materials based on isotopic abundances.

    Returns
    -------
    eltsdict : dict from str to pyne.material.Material
        Natural elements as materials.
    """
    natural_abund("H1")  # initialize natural_abund_map
    # get rid of elemental total abundances and empty isotopic abundances
    abunds_no_trivial = [abund for abund in natural_abund_map.items() if
                         nucname.anum(abund[0]) != 0 and abund[1] != 0]
    sorted_abunds = sorted(abunds_no_trivial)
    grouped_abunds = groupby(sorted_abunds, lambda abund: nucname.znum(abund[0]))
    # filter out 111, 113, 115, 117, 118 - the ones with no names
    elts = (Material(dict(abunds), metadata={"name": nucname.name(zz)})
            for zz, abunds in grouped_abunds if zz in nucname.zz_name.keys())
    eltsdict = dict(((elt.metadata["name"], elt) for elt in elts))
    return eltsdict
Example #7
0
def make_elements():
    """Makes natural elemental materials based on isotopic abundances."""
    habund = natural_abund('H')
    for name, zz in nucname.name_zz.items():
        elemental_mats[name] = {}
    for nuc, abund in natural_abund_map.items():
        if 0 == nuc%10000 or abund == 0.0:
            continue
        zz = nuc/10000
        if zz not in nucname.zz_name:
            continue
        name = nucname.zz_name[zz]
        elemental_mats[name][nuc] = abund
Example #8
0
def grab_materials_compendium(location="materials_compendium.csv"):
    """Parses data from a materials compendium csv file.

    Parameters
    ----------
    location : str
        The file to read in compendium from.

    Returns
    -------
    mats : list of pyne.material.Material
        The materials in the compendium.
    """
    natural_abund("H1")  # initialize natural_abund_map
    if sys.version_info[0] > 2:
        f = open(location, "r", newline="", encoding="utf-8")
    else:
        f = open(location, "rb")
    reader = csv.reader(f, delimiter=",", quotechar='"')
    lines = list(filter(is_comp_matname_or_density, reader))
    mats = parse_materials({}, lines)
    f.close()
    return mats
Example #9
0
def grab_materials_compendium(location='materials_compendium.csv'):
    """Parses data from a materials compendium csv file.

    Parameters
    ----------
    location : str
        The file to read in compendium from.

    Returns
    -------
    mats : list of pyne.material.Material
        The materials in the compendium.
    """
    natural_abund("H1")  # initialize natural_abund_map
    if sys.version_info[0] > 2:
        f = open(location, 'r', newline='', encoding="utf-8")
    else:
        f = open(location, 'rb')
    reader = csv.reader(f, delimiter=',', quotechar='"')
    lines = list(filter(is_comp_matname_or_density, reader))
    mats = parse_materials({}, lines)
    f.close()
    return mats
def findPeaks(energyList=[],
              energyUncertainty=[],
              intensityList=[],
              intensityUncertainty=[]):
    """Finds relevant 'peak' elements in a spectra.

    Args:
        energyList: energies associated with an intensity peak in our
            dataset.
        energyUncertainty: uncertainties of energy values (in order).
        intensityList: The spectrum of intensities in our dataset. 
        intensityUncertainty: The uncertainties of intensity peaks (in 
            order) of dataset
    """
    #initialize
    posEl = []
    counts = 0
    bestCount = 0
    bestElement = 'FirstRun'
    abundance = 0.0
    bCE = []
    bAE = []
    bA = []
    bC = []
    bCEN = []
    bAEN = []
    bAN = []
    bCN = []

    #for each energy, find the parents associated with that energy
    posEl = findParents(energyList, energyUncertainty)

    for element in posEl:
        counts = 0
        #find all intensities associated with this element
        intensities = data.gamma_photon_intensity(element)
        #find unicode name of element
        name = nucname.name(element)
        #count number of intensity peaks that this set has in common
        #with this element
        counts = countIntensityPeaks(intensities, intensityList,
                                     intensityUncertainty)

        #calculate relative counts and natural abundance
        counts = 1.0 * counts / len(intensities)
        abundance = data.natural_abund(element)
        #update lists
        addToLists(bC, bA, bCE, bAE, bCN, bAN, bCEN, bAEN, counts, abundance,
                   name, element)

        checkAbundanceLists(abundance, name, bA, bAE, bAN, element, bAEN)

        checkCountsLists(abundance, name, element, bCE, bC, bCN, bCEN, counts)

        if (counts > bestCount and abundance > 0.0 and abundance < 1.0
                and name[-1] != 'M'):
            num = getNum(name)
            if bestElement == 'FirstRun':
                bestCount = counts
                bestElement = name
                counts = 0

            elif num < getNum(bestElement):
                bestCount = counts
                bestElement = name
                counts = 0
            elif data.natural_abund(bestElement) < abundance:
                bestCount = counts
                bestElement = name
                counts = 0
    presentInfo(bestElement, bAN, bAEN)