Analysis of simulated EDX data
In this notebook we showcase the analysis of the built-in simulated dataset. We use the espm EDXS modelling to simulate the data. We first perform a KL-NMF decomposition of the data and then plot the results.
Imports
[ ]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
# Generic imports
# espm imports
import espm.datasets as ds
from espm.estimators import SmoothNMF
Generating artificial datasets and loading them
If the datasets were already generated, they are not generated again
[ ]:
# Generate the data
# Here `seeds_range` is the number of different samples to generate
ds.generate_built_in_datasets(seeds_range=1)
# Load the data
spim = ds.load_particules(sample=0)
# We need to change the data to floats for the decomposition to run
spim.change_dtype("float64")
Building G
The information in the metadata of the spim object are used to build the G matrix. This matrix contains a model of the characteristic X-rays and the bremsstrahlung.
[3]:
spim.build_G()
Problem solving
Picking analysis parameters
3 components for 3 phases
convergence criterions : tol and max_iter. tol is the minimum change of the loss function between two iterations. max_iter is the max number of iterations.
G : The EDX model is integrated in the decomposition. The algorithm learns the concentration of each chemical element and the bremsstrahlung parameters.
hspy_comp is a required parameter if you want to use the hyperspy api
[4]:
est = SmoothNMF(n_components=3, tol=1e-6, max_iter=200, G=spim.model, hspy_comp=True)
Calculating the decomposition
/! It should take a minute to execute in the case of the built-in dataset
[ ]:
out = spim.decomposition(algorithm=est, return_info=True)
Getting the losses and the results of the decomposition
First cell : Printing the resulting concentrations.
Second cell : Ploting the resulting spectra
Thrid cell : Ploting the resulting abundances
Hyperspy is mainly designed to be used with the qt graphical backend of matplotlib. Thus two plots will appear if you are in inline mode.
[ ]:
spim.print_concentration_report()
[ ]:
spim.plot_decomposition_loadings(3)
[ ]:
spim.plot_decomposition_factors(3)
[ ]: