예제 #1
0
def test_cs_different_units():
    e = XrfElement('Fe')
    # test at different energies
    for eng in range(10, 20):
        cs1 = np.array([v for k, v in e.cs(eng).all])   # unit in cm2/g
        cs2 = np.array([v for k, v in e.csb(eng).all])  # unit in barns/atom
        cs1 /= cs1[0]
        cs2 /= cs2[0]
        # ratio should be the same no matter which unit is used
        assert_array_almost_equal(cs1, cs2, decimal=10)
예제 #2
0
def test_cs_different_units():
    e = XrfElement('Fe')
    # test at different energies
    for eng in range(10, 20):
        cs1 = np.array([v for k, v in e.cs(eng).all])   # unit in cm2/g
        cs2 = np.array([v for k, v in e.csb(eng).all])  # unit in barns/atom
        cs1 /= cs1[0]
        cs2 /= cs2[0]
        # ratio should be the same no matter which unit is used
        assert_array_almost_equal(cs1, cs2, decimal=10)
예제 #3
0
def test_element_data():
    """
    smoke test of all elements
    """

    data1 = []
    data2 = []

    name_list = []
    for i in range(100):
        e = XrfElement(i+1)
        data1.append(e.cs(10)['Ka1'])
        name_list.append(e.name)

    for item in name_list:
        e = XrfElement(item)
        data2.append(e.cs(10)['Ka1'])

    assert_array_equal(data1, data2)

    return
예제 #4
0
def smoke_test_element_creation():
    prev_element = None
    elements = [elm for abbrev, elm in six.iteritems(basic)
                if isinstance(abbrev, int)]
    elements.sort()
    for element in elements:
        Z = element.Z
        element.mass
        element.density
        sym = element.sym
        inits = [Z, sym, sym.upper(), sym.lower(), sym.swapcase()]
        element = None
        for init in inits:
            element = XrfElement(init)
            # obtain the next four attributes to make sure the XrayLibWrap is
            # working
            element.bind_energy
            element.fluor_yield
            element.jump_factor
            element.emission_line.all
            if prev_element is not None:
                # compare prev_element to element
                assert_equal(prev_element.__lt__(element), True)
                assert_equal(prev_element < element, True)
                assert_equal(prev_element.__eq__(element), False)
                assert_equal(prev_element == element, False)
                assert_equal(prev_element >= element, False)
                assert_equal(prev_element > element, False)
                # compare element to prev_element
                assert_equal(element < prev_element, False)
                assert_equal(element.__lt__(prev_element), False)
                assert_equal(element <= prev_element, False)
                assert_equal(element.__eq__(prev_element), False)
                assert_equal(element == prev_element, False)
                assert_equal(element >= prev_element, True)
                assert_equal(element > prev_element, True)
        prev_element = element
예제 #5
0
def test_element_creation():
    prev_element = None
    elements = [elm for abbrev, elm in six.iteritems(basic)
                if isinstance(abbrev, int)]
    elements.sort()
    for element in elements:
        Z = element.Z
        element.mass
        element.density
        sym = element.sym
        inits = [Z, sym, sym.upper(), sym.lower(), sym.swapcase()]
        element = None
        for init in inits:
            element = XrfElement(init)
            # obtain the next four attributes to make sure the XrayLibWrap is
            # working
            element.bind_energy
            element.fluor_yield
            element.jump_factor
            element.emission_line.all
            if prev_element is not None:
                # compare prev_element to element
                assert_equal(prev_element.__lt__(element), True)
                assert_equal(prev_element < element, True)
                assert_equal(prev_element.__eq__(element), False)
                assert_equal(prev_element == element, False)
                assert_equal(prev_element >= element, False)
                assert_equal(prev_element > element, False)
                # compare element to prev_element
                assert_equal(element < prev_element, False)
                assert_equal(element.__lt__(prev_element), False)
                assert_equal(element <= prev_element, False)
                assert_equal(element.__eq__(prev_element), False)
                assert_equal(element == prev_element, False)
                assert_equal(element >= prev_element, True)
                assert_equal(element > prev_element, True)
        prev_element = element
예제 #6
0
def test_element_data():
    """
    smoke test of all elements
    """

    data1 = []
    data2 = []

    name_list = []
    for i in range(100):
        e = XrfElement(i+1)
        data1.append(e.cs(10)['Ka1'])
        name_list.append(e.name)

    for item in name_list:
        e = XrfElement(item)
        data2.append(e.cs(10)['Ka1'])

    assert_array_equal(data1, data2)

    return
예제 #7
0
def _get_elemental_line_parameters(*, elemental_line, incident_energy):
    r"""
    Retrieve information on all emission lines for the given element and the group (K, L or M)
    at given incident energy. For each emission line, the information includes emission line name,
    energy and ratio. The data is used for simulation of emission spectra of elements.

    Parameters
    ----------

    elemental_line: str
        Elemental line name in the format ``Fe_K``, ``Ca_L``, etc.

    incident_energy: float
        Incident energy in keV

    Returns
    -------

    List of dictionaries. Keys: ``name`` - emission line name, ``energy`` - energy of the
    emission line, "ratio" - ratio of the emission line area to the area of ``a1`` line.

    Raises
    ------

    RuntimeError
        Elemental line is not in the list of supported lines or the emission line is
        incorrectly formatted.
    """

    # Check format (Fe_K, Y_L, W_M etc.)
    if not re.search(r"^[A-Z][a-z]?_[KLM]$", elemental_line):
        raise RuntimeError(
            f"Elemental line {elemental_line} has incorrect format")

    element, line = elemental_line.split("_")
    line_name = elemental_line

    ALL_LINES = K_LINE + L_LINE + M_LINE
    if line_name not in ALL_LINES:
        raise RuntimeError(f"Elemental line {line_name} is not supported")

    elemental_lines = []

    # XrfElement class provides convenient access to xraylib library functions
    e = XrfElement(element)

    # Check if the emission line is activated (check if 'a1' line is active)
    em_line_a1 = f"{line.lower()}a1"
    i_line_a1 = e.cs(incident_energy)[em_line_a1]
    if i_line_a1 > 0:
        for num, item in enumerate(e.emission_line.all):
            l_name = item[0]  # Line name (ka1, kb2 etc.)
            energy_v = item[1]  # Energy (in kEv)
            if line.lower() not in l_name:
                continue

            i_line = e.cs(incident_energy)[l_name]
            ratio_v = i_line / i_line_a1

            if energy_v == 0 or ratio_v == 0:
                continue

            elemental_lines.append({
                "name": l_name,
                "energy": energy_v,
                "ratio": ratio_v
            })

    return elemental_lines