Cross sections utils

espm.cross_sections_utils.get_k_factor(table: dict, mdata: dict, element: int, line: str, range: float = 0.5, ref_elt: str = '14', ref_line: str = 'KL3', ref_range: float = 0.5)[source]

Obtain the k-factor of a line from an emtables, X-ray emission cross section table.

Parameters:
tabledict

The table of the X-ray emission cross sections.

mdatadict

The metadata of the table.

elementint

The atomic number of the element to use.

linestr

The regex of the line to use. It has to correspond to IUPAC notation.

rangefloat

The energy range to use for the integration of the cross section of the line. For example, if range = 0.5, the integration will be done between the energy of the line - 0.5 and the energy of the line + 0.5. We do so that when you select the “KL3” line, it integrates around it and make it correspond to the K-alpha bunch of lines.

ref_eltstr

The atomic number of the element to use as a reference for the k-factor. The default reference line is Si “KL3” with an integration range of 0.5.

ref_linestr

The regex of the line to use as a reference for the k-factor. It has to correspond to IUPAC notation.

ref_rangefloat

The energy range to use for the integration of the cross section of the reference line.

Returns:
k_factorfloat

The k-factor of the line. It does not take into account the absorption correction.

espm.cross_sections_utils.import_k_factors(table: dict, mdata: dict, k_factors_names: list[str], k_factors_values: list[int], ref_name: str) tuple[dict, dict][source]

Modify the X-ray emission cross-sections of the input table using the k-factors input, i.e. imposing cross-sections ratios to correspond to the k-factors. The metadata are modified too to keep track of the modifications.

Parameters:
tabledict

The table of the X-ray emission cross sections.

mdatadict

The metadata of the table.

k_factors_nameslist

The list of the names of the k-factors to import. It has to correspond to the nomenclature of the hyperspy X-ray lines.

k_factors_valueslist

The list of the values of the k-factors to import. It has to have the same length and ordering as k_factors_names.

ref_namestr

The name of the X-ray line to use as a reference for the k-factors. It has to correspond to the nomenclature of the hyperspy X-ray lines.

Returns:
new_tabledict

The modified table of the X-ray emission cross sections.

new_mdatadict

The modified metadata of the table.

espm.cross_sections_utils.load_table(db_name: str) tuple[dict, dict][source]

Load the table and metadata of a json table generated by emtables.

Parameters:
db_namestr

The file name of the table to load.

Returns:
tabledict

The table of the cross sections.

metadatadict

The metadata of the table.

Notes

Call espm.conf.DB_PATH to get the folder of the tables.

espm.cross_sections_utils.modify_cross_sections(energy: int | str, input_type: str = 'new_values', lines_new_values: dict[str, float] = None, lines_scaling_factors: dict[str, float] = None, k_factors: dict[str, float] = None, reference_line: str = None, output_filename: str = None) None[source]

Function allowing the user to modify the X-ray emission cross-sections of the input database. The function can be with three diffrent input types: new values, scaling factors and k-factors with a reference line.

Parameters:
energyint

The electron energy in keV for which the cross-sections are to be modified.

input_typestr

The type of input to be used. Can be one of the following: ‘new_values’, ‘scaling_factors’, ‘k_factors’.

lines_new_valuesdict

[For the ‘new_values’ input type] A dictionary containing the new values for the cross-sections. The keys of the dictionary should be the element symbol and the X-ray line in Siegbahn notation, separated by an underscore. The correspoding values should be the new cross-section values. For example: {‘Cu_Ka1’ : 6.3e-23}.

lines_scaling_factorsdict

[For the ‘scaling_factors’ input type] A dictionary containing the scaling factors for the cross-sections. The keys of the dictionary should be the element symbol and the X-ray line family in Siegbahn notation, separated by an underscore. The corresponding values should be the scaling factors. For example: {‘Cu_Ka’ : 1.2}.

k_factorsdict

[For the ‘k_factors’ input type] A dictionary containing the k-factors for the cross-sections. The keys of the dictionary should be the element symbol and the X-ray line family in Siegbahn notation, separated by an underscore. The corresponding values should be the Cliff-Lorimer k-factors. For example: {‘Cu_Ka’ : 1.75}.

reference_linestr

[For the ‘k_factors’ input type] The reference line for the k-factors. Should be the element symbol and the X-ray line family in Siegbahn notation, separated by an underscore. For example: ‘Si_Ka’.

output_filenamestr

The name of the output file. If None, the default name is the same as the input file with ‘_modified’ appended.

Returns:
None
espm.cross_sections_utils.modify_table_lines(table: dict, mdata: dict, elements: list[str], line: str, coeff: float) tuple[dict, dict][source]

Modify the cross section of the lines of the selected elements in the input table.

Parameters:
tabledict

The table of the X-ray emission cross sections.

mdatadict

The metadata of the table.

elementslist

The list of the atomic numbers of the elements to modify.

linestr

The regex of the line to modify. It has to correspond to IUPAC notation.

coefffloat

The coefficient to multiply the cross section of the selected lines.

Returns:
new_tabledict

The modified table of the X-ray emission cross sections.

new_mdatadict

The modified metadata of the table.

Notes

X-ray line regex examples : input “L” will modify all the L lines, input “L3” will modifiy all the L3 lines, input “L3M2” will modify the “L3M2” line.

espm.cross_sections_utils.save_table(filename: str, table: dict, mdata: dict) None[source]

Saves a table and its metadata in a json file. The structure of the json file is compliant with espm.