Exemplo n.º 1
0
def test_atomic_data():
    assert atomic_number('zn') == 30
    assert atomic_symbol(26) == 'Fe'
    assert atomic_mass(45) > 102.8
    assert atomic_mass(45) < 103.0
    assert atomic_density(29) == atomic_density('cu')
    assert atomic_density(22) > 4.51
Exemplo n.º 2
0
def element(elem=None):
    edges = atomic = lines = {}
    if elem is not None:
        atomic = {
            'n': xraydb.atomic_number(elem),
            'mass': xraydb.atomic_mass(elem),
            'density': xraydb.atomic_density(elem)
        }
        _edges = xraydb.xray_edges(elem)
        _lines = xraydb.xray_lines(elem)
        lines = OrderedDict()
        for k in sorted(_lines.keys()):
            en, inten, init, final = _lines[k]  # XrayLine
            lines[k] = XrayLine(energy=f'{en:.1f}',
                                intensity=f'{inten:.5f}',
                                initial_level=init,
                                final_level=final)
        edges = OrderedDict()
        for k in sorted(_edges.keys()):
            en, fy, jump = _edges[k]  # XrayEdge
            edges[k] = XrayEdge(energy=f'{en:.1f}',
                                fyield=f'{fy:.5f}',
                                jump_ratio=f'{jump:.3f}')

    return render_template('elements.html',
                           edges=edges,
                           elem=elem,
                           atomic=atomic,
                           lines=lines,
                           materials_dict=materials_dict)
Exemplo n.º 3
0
def darwinwidth(elem=None):
    edges = atomic = lines = {}
    if elem is not None:
        edges= xraydb.xray_edges(elem)
        atomic= {'n': xraydb.atomic_number(elem),
                 'mass': xraydb.atomic_mass(elem),
                 'density': xraydb.atomic_density(elem)}
        lines= xraydb.xray_lines(elem)
    return render_template('darwinwidth.html', edges=edges, elem=elem,
                           atomic=atomic, lines=lines, materials_dict=materials_dict)
Exemplo n.º 4
0
def get_att_len(energy, material=None, density=None):
    """
    Get the attenuation length (in meter) of a material.

    The X-ray beam intensity I(x) at depth x in a material is a function of the
    attenuation coefficient mu, and can be calculated by the Beer-Lambert law.
    The Absorption Length (or Attenuation Length) is defined as the distance
    into a material where the x-ray beam intensity has decreased to a value of
    1/e (~ 40%) of the incident beam intensity (Io).

    (1/e) = e^(-mu * x)
    ln(1/e) = ln(e^(-mu * x))
    1 = mu * x
    x = 1/mu

    Parameters
    ----------
    energy : number
        Beam Energy given in KeV
    material : str, optional
        Atomic symbol for element, defaults to 'Be'
    density : float, optional
        Material density in g/cm^3

    Returns
    -------
    att_len : float
        Attenuation length (in meters)

    Raises
    ------
    ValueError
        If an invalid symbol is provided for material.

    Examples
    --------
    >>> get_att_len(energy=8, material='Be')
    0.004810113254120656
    """
    material = material or MATERIAL
    density = density or xdb.atomic_density(material)
    try:
        # xdb.material_my returns absorption length in 1/cm and takes energy
        # or array of energies in eV.
        att_len = 1.0 / (xdb.material_mu(material, energy * 1.0e3,
                                         density=density)) * 1.0e-2
    except Exception as ex:
        logger.error('Get Attenuation Length error: %s', ex)
        raise ex
    return att_len
Exemplo n.º 5
0
def get_delta(energy, material=None, density=None):
    """
    Calculate delta for a given material at a given energy.

    Anomalous components of the index of refraction for a material, using the
    tabulated scattering components from Chantler.

    Parameters
    ----------
    energy : number
        x-ray energy in KeV
    material : str, optional
        Atomic symbol for element, defaults to 'Be'.
    density : float, optional
        Material density in g/cm^3

    Returns
    -------
    delta : float
        Real part of index of refraction

    Raises
    ------
    ValueError
        If an invalid symbol is provided for material.
    ZeroDivisionError
        When energy is 0.

    Examples
    --------
    >>> get_delta(energy=8, material='Au')
    4.728879989419882e-05
    """
    material = material or MATERIAL
    # xray_delta_beta returns (delta, beta, atlen), wehre delta : real part of
    # index of refraction, and takes x-ray energy in eV.
    if density is None:
        density = xdb.atomic_density(material)
    try:
        delta = xdb.xray_delta_beta(material,
                                    density=density,
                                    energy=energy * 1.0e3)[0]
    except Exception as ex:
        logger.error('Get Delta error: %s', ex)
        raise ex
    return delta
Exemplo n.º 6
0
def element(elem=None):
    edges = atomic = lines = {}
    if elem is not None:
        atomic= {'n': xraydb.atomic_number(elem),
                 'mass': xraydb.atomic_mass(elem),
                 'density': xraydb.atomic_density(elem)}
        _edges= xraydb.xray_edges(elem)
        _lines= xraydb.xray_lines(elem)
        lines = OrderedDict()
        for k in sorted(_lines.keys()):
            lines[k] = _lines[k]

        edges = OrderedDict()
        for k in sorted(_edges.keys()):
            edges[k] = _edges[k]
    return render_template('elements.html', edges=edges, elem=elem,
                           atomic=atomic, lines=lines, materials_dict=materials_dict)