.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/auto_examples/analysis/plot_iris.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_auto_examples_analysis_plot_iris.py: 2D-IRIS analysis example ========================= In this example, we perform the 2D IRIS analysis of CO adsorption on a sulfide catalyst. .. GENERATED FROM PYTHON SOURCE LINES 15-17 .. code-block:: default import spectrochempy as scp .. GENERATED FROM PYTHON SOURCE LINES 18-20 Uploading dataset ----------------- .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: default X = scp.read("irdata/CO@Mo_Al2O3.SPG") .. GENERATED FROM PYTHON SOURCE LINES 23-26 `X` has two coordinates: * `wavenumbers` named "x" * and `timestamps` (*i.e.,* the time of recording) named "y". .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: default print(X.coordset) .. rst-class:: sphx-glr-script-out .. code-block:: none CoordSet: [x:wavenumbers, y:acquisition timestamp (GMT)] .. GENERATED FROM PYTHON SOURCE LINES 30-38 Setting new coordinates ----------------------- The `y` coordinates of the dataset is the acquisition timestamp. However, each spectrum has been recorded with a given pressure of CO in the infrared cell. Hence, it would be interesting to add pressure coordinates to the `y` dimension: .. GENERATED FROM PYTHON SOURCE LINES 38-63 .. code-block:: default pressures = [ 0.003, 0.004, 0.009, 0.014, 0.021, 0.026, 0.036, 0.051, 0.093, 0.150, 0.203, 0.300, 0.404, 0.503, 0.602, 0.702, 0.801, 0.905, 1.004, ] c_pressures = scp.Coord(pressures, title="pressure", units="torr") .. GENERATED FROM PYTHON SOURCE LINES 64-65 Now we can set multiple coordinates: .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: default c_times = X.y.copy() # the original coordinate X.y = [c_times, c_pressures] print(X.y) .. rst-class:: sphx-glr-script-out .. code-block:: none CoordSet: [_1:acquisition timestamp (GMT), _2:pressure] .. GENERATED FROM PYTHON SOURCE LINES 71-73 To get a detailed a rich display of these coordinates. In a jupyter notebook, just type: .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: default X.coordset .. raw:: html
DIMENSION `x`
size 3112
title wavenumbers
coordinates
[ 4000 3999 ... 1001 999.9] cm⁻¹
DIMENSION `y`
size 19
(_1)
title acquisition timestamp (GMT)
coordinates
[1.477e+09 1.477e+09 ... 1.477e+09 1.477e+09] s
labels
[[ 2016-10-18 13:49:35+00:00 2016-10-18 13:54:06+00:00 ... 2016-10-18 16:01:33+00:00 2016-10-18 16:06:37+00:00]
[ *Résultat de Soustraction:04_Mo_Al2O3_calc_0.003torr_LT_after sulf_Oct 18 15:46:42 2016 (GMT+02:00)
*Résultat de Soustraction:04_Mo_Al2O3_calc_0.004torr_LT_after sulf_Oct 18 15:51:12 2016 (GMT+02:00) ...
*Résultat de Soustraction:04_Mo_Al2O3_calc_0.905torr_LT_after sulf_Oct 18 17:58:42 2016 (GMT+02:00)
*Résultat de Soustraction:04_Mo_Al2O3_calc_1.004torr_LT_after sulf_Oct 18 18:03:41 2016 (GMT+02:00)]]
(_2)
title pressure
coordinates
[ 0.003 0.004 ... 0.905 1.004] torr


.. GENERATED FROM PYTHON SOURCE LINES 77-80 By default, the current coordinate is the first one (here `c_times` ). For example, it will be used by default for plotting: .. GENERATED FROM PYTHON SOURCE LINES 80-86 .. code-block:: default prefs = X.preferences prefs.figure.figsize = (7, 3) _ = X.plot(colorbar=True) _ = X.plot_map(colorbar=True) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_001.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_001.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_002.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 87-89 To seamlessly work with the second coordinates (pressures), we can change the default coordinate: .. GENERATED FROM PYTHON SOURCE LINES 89-93 .. code-block:: default X.y.select(2) # to select coordinate `_2` X.y.default .. raw:: html
size 19
title pressure
coordinates
[ 0.003 0.004 ... 0.905 1.004] torr


.. GENERATED FROM PYTHON SOURCE LINES 94-95 Let's now plot the spectral range of interest. The default coordinate is now used: .. GENERATED FROM PYTHON SOURCE LINES 95-100 .. code-block:: default X_ = X[:, 2250.0:1950.0] print(X_.y.default) _ = X_.plot() _ = X_.plot_map() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_003.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_003.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_004.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Coord: [float64] torr (size: 19) .. GENERATED FROM PYTHON SOURCE LINES 101-105 IRIS analysis without regularization ------------------------------------ Perform IRIS without regularization (the loglevel can be set to `INFO` to have information on the running process) .. GENERATED FROM PYTHON SOURCE LINES 105-107 .. code-block:: default iris1 = scp.IRIS(log_level="INFO") .. GENERATED FROM PYTHON SOURCE LINES 108-109 first we compute the kernel object .. GENERATED FROM PYTHON SOURCE LINES 109-111 .. code-block:: default K = scp.IrisKernel(X_, "langmuir", q=[-8, -1, 50]) .. rst-class:: sphx-glr-script-out .. code-block:: none Creating Kernel... Kernel now ready as IrisKernel().kernel! .. GENERATED FROM PYTHON SOURCE LINES 112-113 The actual kernel is given by the `kernel` attribute .. GENERATED FROM PYTHON SOURCE LINES 113-116 .. code-block:: default kernel = K.kernel kernel .. raw:: html
name langmuir kernel matrix
author runner@fv-az626-878
created 2023-06-06 01:27:35+00:00
DATA
title coverage
values
[[ 0.06424 0.1265 ... 0.001332 0.0005778]
[ 0.0659 0.1303 ... 0.00177 0.0007683]
...
[ 0.0714 0.1428 ... 0.1056 0.05078]
[ 0.0714 0.1428 ... 0.1084 0.05227]]
shape (y:19, x:50)
DIMENSION `x`
size 50
title $\Delta_{ads}G^{0}/RT$
coordinates
[ -8 -7.857 ... -1.143 -1]
DIMENSION `y`
size 19
title pressure
coordinates
[ 0.003 0.004 ... 0.905 1.004] torr


.. GENERATED FROM PYTHON SOURCE LINES 117-118 Now we fit the model - we can pass either the Kernel object or the kernel NDDataset .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: default iris1.fit(X_, K) .. rst-class:: sphx-glr-script-out .. code-block:: none Build S matrix (sharpness) ... done Solving for 312 channels and 19 observations, no regularization --> residuals = 1.09e-01 curvature = 9.14e+04 Done. .. GENERATED FROM PYTHON SOURCE LINES 121-122 Plots the results .. GENERATED FROM PYTHON SOURCE LINES 122-125 .. code-block:: default iris1.plotdistribution() _ = iris1.plotmerit() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_005.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_005.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_006.png :alt: 2D IRIS merit plot, $\lambda$ = 0.00e+00 :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 126-129 With regularization and a manual search --------------------------------------- Perform IRIS with regularization, manual search .. GENERATED FROM PYTHON SOURCE LINES 129-131 .. code-block:: default iris2 = scp.IRIS(reg_par=[-10, 1, 12]) .. GENERATED FROM PYTHON SOURCE LINES 132-133 We keep the same kernel object as previously - performs the fit. .. GENERATED FROM PYTHON SOURCE LINES 133-139 .. code-block:: default iris2.fit(X_, K) iris2.plotlcurve(title="L curve, manual search") iris2.plotdistribution(-7) _ = iris2.plotmerit(-7) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_007.png :alt: L curve, manual search :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_007.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_008.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_008.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_009.png :alt: 2D IRIS merit plot, $\lambda$ = 0.00e+00 :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_009.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 140-144 Automatic search ---------------- %% Now try an automatic search of the regularization parameter: .. GENERATED FROM PYTHON SOURCE LINES 144-149 .. code-block:: default iris3 = scp.IRIS(reg_par=[-10, 1]) iris3.fit(X_, K) iris3.plotlcurve(title="L curve, automated search") .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_010.png :alt: L curve, automated search :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_010.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 150-152 The data corresponding to the largest curvature of the L-curve are at the second last position of output data. .. GENERATED FROM PYTHON SOURCE LINES 152-158 .. code-block:: default # sphinx_gallery_thumbnail_number = 11 iris3.plotdistribution(-2) _ = iris3.plotmerit(-2) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_011.png :alt: plot iris :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_011.png :class: sphx-glr-multi-img * .. image-sg:: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_012.png :alt: 2D IRIS merit plot, $\lambda$ = 1.00e-03 :srcset: /gallery/auto_examples/analysis/images/sphx_glr_plot_iris_012.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 159-161 This ends the example ! The following line can be uncommented if no plot shows when running the .py script .. GENERATED FROM PYTHON SOURCE LINES 163-165 .. code-block:: default # scp.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.614 seconds) .. _sphx_glr_download_gallery_auto_examples_analysis_plot_iris.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_iris.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_iris.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_