Note
Go to the end to download the full example code.
SIMPLISMA example#
In this example, we perform the PCA dimensionality reduction of a spectra dataset
Import the package
import spectrochempy as scp
Load and annotate the dataset#

Dataset (Jaumot et al., Chemometr. Intell. Lab. 76 (2005) 101-110)):
cpure (204, 4)
MATRIX (204, 96)
isp_matrix (4, 4)
spure (4, 96)
csel_matrix (51, 4)
m1 (51, 96)
Add metadata for a nicer display. The archived file does not store the physical elution time and wavelength coordinates, so the axes are plain indices without physical units:
ds.title = "absorbance"
ds.units = "absorbance"
ds.set_coordset(None, None)
ds.y.title = "elution time (index)"
ds.x.title = "wavelength (index)"
Fit the SIMPLISMA model#
Fit SIMPLISMA on m1
/opt/hostedtoolcache/Python/3.13.18/x64/lib/python3.13/site-packages/traitlets/traitlets.py:1575: UserWarning: SIMPLISMA does not handle easily negative values.
c(event)
*** Automatic SIMPL(I)SMA analysis ***
dataset: m1
noise: 3.0 %
tol: 0.2 %
n_components: 20
#iter index_pc coord_pc Std(res) R^2
---------------------------------------------
1 4 4.0 0.0263 0.9755
2 82 82.0 0.0100 0.9964
3 29 29.0 0.0072 0.9981
**** Unexplained variance lower than 'tol' (0.2 %)
**** End of SIMPL(I)SMA analysis.
Visualize the results#
Concentration profiles:
_ = simpl.C.T.plot(title="Concentration")

Pure component spectra:
_ = simpl.components.plot(title="Pure profiles")

Merit plot after reconstruction:
_ = simpl.plot_merit(offset=0, nb_traces=5)

Uncomment the following line to display all figures when running the script directly with Python.
# scp.show()
Total running time of the script: (0 minutes 0.635 seconds)