Utils
Utils for the ESPM package
- espm.utils.approx_density(atomic_fraction=False, *, elements_dict={})[source]
Wrapper to the density_of_mixture function of hyperspy. Takes a dict of chemical composition expressed in atomic weight fractions. Returns an approximated density.
- espm.utils.arg_helper(params, d_params)[source]
Check if all parameter of d_params are in params. If not, they are added to params with the default value.
- Parameters:
- paramsdict
Dictionary of parameters to be checked.
- d_paramsdict
Dictionary of default parameters.
- Returns:
- paramsdict
Dictionary of parameters with the default parameters added if not present.
- espm.utils.atomic_to_weight_dict(*, elements_dict={})[source]
Wrapper to the atomic_to_weight function of hyperspy. Takes a dict of chemical composition expressed in atomic fractions. Returns a dict of chemical composition expressed in atomic weight fratiom.
- espm.utils.bin_spim(data, n, m)[source]
Take a 3D array of size (x,y,k) [px, py, e] Returns a 3D array of size (n,m,k) [new_px, new_py, e]
- espm.utils.check_keys(params, d_params, upperkeys='', toprint=True)[source]
Check if all parameter of d_params are in params. If not, they are added to params with the default value.
- Parameters:
- paramsdict
Dictionary of parameters to be checked.
- d_paramsdict
Dictionary of default parameters.
- upperkeysstr
String of the upper keys.
- toprintbool
If True, print the warning.
- Returns:
- paramsdict
Dictionary of parameters with the default parameters added if not present.
Examples
>>> params = {'a':1,'b':2} >>> d_params = {'a':1,'b':2,'c':3} >>> check_keys(params,d_params) >>> params {'a': 1, 'b': 2, 'c': 3}
- espm.utils.composition_parser(comp_string)[source]
Parse a string of the form of a chemical formula to dictionarry of the normalize composition.
- Parameters:
- comp_stringstr
Chemical formula to parse.
- Returns:
- compodict
Dictionary of the chemical composition.
Examples
>>> composition_parser("Bi3Fe4.5Ca0.5O12") {'Bi': 3.0, 'Ca': 0.5, 'Fe': 4.5, 'O': 12.0}
- espm.utils.create_laplacian_matrix(nx, ny=None)[source]
Helper method to create the laplacian matrix for the laplacian regularization
- Parameters:
- :param nx: height of the original image
- :param ny: width of the original image
- Returns:
- rtype:
scipy.sparse.csr_matrix ..
- :return:the n x n laplacian matrix, where n = nx*ny
- espm.utils.is_number(i)[source]
Return True if i is a number
- Parameters:
i (any) – variable to check
- Returns:
True if i is a number
- Return type:
- espm.utils.is_symbol(i)[source]
Return True if i is a chemical symbol
- Parameters:
i (any) – variable to check
- Returns:
True if i is a chemical symbol
- Return type:
- espm.utils.isdict(p)[source]
Return True if the variable a dictionary.
- Parameters:
p (any) – variable to check
- Returns:
True if p is a dictionary
- Return type:
- espm.utils.number_to_symbol_dict(func)[source]
Decorator Takes a dict of elements (a.k.a chemical composition) with atomic numbers as keys (e.g. 26 for Fe) returns a dict of elements with symbols as keys (e.g. Fe for iron)
- espm.utils.number_to_symbol_list(func)[source]
Decorator Takes a dict of elements (a.k.a chemical composition) with symbols as keys (e.g. Fe for iron) returns a dict of elements with atomic numbers as keys (e.g. 26 for iron)
- espm.utils.process_losses(losses)[source]
Process the losses to be plotted
- Parameters:
- losses: np.ndarray
Array of losses (output of espm.estimators.NMFEstimator.get_losses method)
- Returns:
- values: np.ndarray
Array of values
- names: list
List of names
- espm.utils.rescaled_DH(D, H)[source]
Rescale the matrices D and H such that the columns of H sums approximately to one.
- Parameters:
D (np.array 2D) – n x k matrix
H (np.array 2D) – k x m matrix
- Returns:
D_rescale, H_rescale
- Return type:
np.array 2D, np.array 2D