Пример #1
0
def get_edges_near_energy(energy, width=10):
    """Find edges near a given energy that are within the given energy 
    window.
    
    Parameters
    ----------
    energy : float
        Energy to search, in eV
    width : float
        Width of window, in eV, around energy in which to find nearby 
        energies, i.e. a value of 1 eV (the default) means to 
        search +/- 0.5 eV. The default is 10.
    
    Returns
    -------
    edges : list
        All edges that are within the given energy window, sorted by 
        energy difference to the given energy.
    """        
    
    if width < 0:
        raise ValueError("Provided width needs to be >= 0.")
    
    Emin, Emax = energy - width/2, energy + width/2            

    # find all subshells that have its energy within range
    valid_edges = []
    for element, element_info in elements_db.items():
        try:
            for shell, shell_info in element_info[
                'Atomic_properties']['Binding_energies'].items():
                if shell[-1] != 'a' and \
                    Emin <= shell_info['onset_energy (eV)'] <= Emax:
                    subshell = '{}_{}'.format(element, shell)
                    Ediff = np.abs(shell_info['onset_energy (eV)'] - energy)
                    valid_edges.append((subshell, Ediff))           
        except KeyError:
            continue 
        
    # Sort by energy difference and return only the edges
    edges = [edge for edge, _ in sorted(valid_edges, key=lambda x: x[1])]
    
    return edges
Пример #2
0
def get_xray_lines_near_energy(energy, width=0.2, only_lines=None):
    """Find xray lines near a specific energy, more specifically all xray lines
    that satisfy only_lines and are within the given energy window width around
    the passed energy.

    Parameters
    ----------
    energy : float
        Energy to search near in keV
    width : float
        Window width in keV around energy in which to find nearby energies,
        i.e. a value of 0.2 keV (the default) means to search +/- 0.1 keV.
    only_lines :
        If not None, only the given lines will be added (eg. ('a','Kb')).

    Returns
    -------
    List of xray-lines sorted by energy difference to given energy.
    """
    only_lines = _parse_only_lines(only_lines)
    valid_lines = []
    E_min, E_max = energy - width / 2., energy + width / 2.
    for element, el_props in elements_db.items():
        # Not all elements in the DB have the keys, so catch KeyErrors
        try:
            lines = el_props['Atomic_properties']['Xray_lines']
        except KeyError:
            continue
        for line, l_props in lines.items():
            if only_lines and line not in only_lines:
                continue
            line_energy = l_props['energy (keV)']
            if E_min <= line_energy <= E_max:
                # Store line in Element_Line format, and energy difference
                valid_lines.append(
                    (element + "_" + line, np.abs(line_energy - energy)))
    # Sort by energy difference, but return only the line names
    return [line for line, _ in sorted(valid_lines, key=lambda x: x[1])]
Пример #3
0
def get_xray_lines_near_energy(energy, width=0.2, only_lines=None):
    """Find xray lines near a specific energy, more specifically all xray lines
    that satisfy only_lines and are within the given energy window width around
    the passed energy.

    Parameters
    ----------
    energy : float
        Energy to search near in keV
    width : float
        Window width in keV around energy in which to find nearby energies,
        i.e. a value of 0.2 keV (the default) means to search +/- 0.1 keV.
    only_lines :
        If not None, only the given lines will be added (eg. ('a','Kb')).

    Returns
    -------
    List of xray-lines sorted by energy difference to given energy.
    """
    only_lines = _parse_only_lines(only_lines)
    valid_lines = []
    E_min, E_max = energy - width / 2., energy + width / 2.
    for element, el_props in elements_db.items():
        # Not all elements in the DB have the keys, so catch KeyErrors
        try:
            lines = el_props['Atomic_properties']['Xray_lines']
        except KeyError:
            continue
        for line, l_props in lines.items():
            if only_lines and line not in only_lines:
                continue
            line_energy = l_props['energy (keV)']
            if E_min <= line_energy <= E_max:
                # Store line in Element_Line format, and energy difference
                valid_lines.append((element + "_" + line,
                                    np.abs(line_energy - energy)))
    # Sort by energy difference, but return only the line names
    return [line for line, _ in sorted(valid_lines, key=lambda x: x[1])]
Пример #4
0
def get_edges_near_energy(energy, width=10, only_major=False, order='closest'):
    """Find edges near a given energy that are within the given energy
    window.

    Parameters
    ----------
    energy : float
        Energy to search, in eV
    width : float
        Width of window, in eV, around energy in which to find nearby
        energies, i.e. a value of 10 eV (the default) means to
        search +/- 5 eV. The default is 10.
    only_major : bool
        Whether to show only the major edges. The default is False.
    order : str
        Sort the edges, if 'closest', return in the order of energy difference,
        if 'ascending', return in ascending order, similarly for 'descending'

    Returns
    -------
    edges : list
        All edges that are within the given energy window, sorted by
        energy difference to the given energy.
    """

    if width < 0:
        raise ValueError("Provided width needs to be >= 0.")
    if order not in ('closest', 'ascending', 'descending'):
        raise ValueError("order needs to be 'closest', 'ascending' or "
                         "'descending'")

    Emin, Emax = energy - width / 2, energy + width / 2

    # find all subshells that have its energy within range
    valid_edges = []
    for element, element_info in elements_db.items():
        try:
            for shell, shell_info in element_info['Atomic_properties'][
                    'Binding_energies'].items():
                if only_major:
                    if shell_info['relevance'] != 'Major':
                        continue
                if shell[-1] != 'a' and \
                    Emin <= shell_info['onset_energy (eV)'] <= Emax:
                    subshell = '{}_{}'.format(element, shell)
                    Ediff = np.abs(shell_info['onset_energy (eV)'] - energy)
                    valid_edges.append(
                        (subshell, shell_info['onset_energy (eV)'], Ediff))
        except KeyError:
            continue

    # Sort according to 'order' and return only the edges
    if order == 'closest':
        edges = [
            edge for edge, _, _ in sorted(valid_edges, key=lambda x: x[2])
        ]
    elif order == 'ascending':
        edges = [
            edge for edge, _, _ in sorted(valid_edges, key=lambda x: x[1])
        ]
    elif order == 'descending':
        edges = [
            edge for edge, _, _ in sorted(
                valid_edges, key=lambda x: x[1], reverse=True)
        ]

    return edges