.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gettingstarted/gallery/auto_examples/analysis/plot_2D_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_gettingstarted_gallery_auto_examples_analysis_plot_2D_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 16-19 .. code-block:: default import spectrochempy as scp .. GENERATED FROM PYTHON SOURCE LINES 20-22 Uploading dataset ----------------- .. GENERATED FROM PYTHON SOURCE LINES 22-24 .. code-block:: default X = scp.read("irdata/CO@Mo_Al2O3.SPG") .. GENERATED FROM PYTHON SOURCE LINES 25-28 ``X`` has two coordinates: * `wavenumbers` named "x" * and `timestamps` (*i.e.,* the time of recording) named "y". .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. 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 32-40 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 40-65 .. 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 66-67 Now we can set multiple coordinates: .. GENERATED FROM PYTHON SOURCE LINES 67-72 .. 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 73-75 To get a detailed a rich display of these coordinates. In a jupyter notebook, just type: .. GENERATED FROM PYTHON SOURCE LINES 75-78 .. 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 79-82 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 82-88 .. 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:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_001.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_001.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_002.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 89-91 To seamlessly work with the second coordinates (pressures), we can change the default coordinate: .. GENERATED FROM PYTHON SOURCE LINES 91-95 .. 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 96-97 Let's now plot the spectral range of interest. The default coordinate is now used: .. GENERATED FROM PYTHON SOURCE LINES 97-103 .. 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:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_003.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_003.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_004.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_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 104-109 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 109-113 .. code-block:: default scp.set_loglevel(scp.INFO) iris = scp.IRIS(X_, "langmuir", q=[-8, -1, 50]) .. rst-class:: sphx-glr-script-out .. code-block:: none Build kernel matrix with: langmuir Build S matrix (sharpness) ... done Solving for 312 channels and 19 observations, no regularization --> residuals = 1.09e-01 curvature = 9.15e+04 Done. .. GENERATED FROM PYTHON SOURCE LINES 114-115 Plots the results .. GENERATED FROM PYTHON SOURCE LINES 115-119 .. code-block:: default iris.plotdistribution() _ = iris.plotmerit() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_005.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_005.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_006.png :alt: 2D IRIS merit plot, $\lambda$ = 0.00e+00 :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 120-124 With regularization and a manual search --------------------------------------- %% Perform IRIS with regularization, manual search .. GENERATED FROM PYTHON SOURCE LINES 124-130 .. code-block:: default iris = scp.IRIS(X_, "langmuir", q=[-8, -1, 50], reg_par=[-10, 1, 12]) iris.plotlcurve(title="L curve, manual search") iris.plotdistribution(-7) _ = iris.plotmerit(-7) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_007.png :alt: L curve :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_007.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_008.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_008.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_009.png :alt: 2D IRIS merit plot, $\lambda$ = 1.00e-05 :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_009.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Build kernel matrix with: langmuir Build S matrix (sharpness) ... done Solving for 312 channels, 19 observations and 12 regularization parameters log10(lambda)=-10.000 --> residuals = 1.088e-01 regularization constraint = 9.085e+04 log10(lambda)=-9.000 --> residuals = 1.088e-01 regularization constraint = 8.266e+04 log10(lambda)=-8.000 --> residuals = 1.093e-01 regularization constraint = 2.244e+04 log10(lambda)=-7.000 --> residuals = 1.104e-01 regularization constraint = 3.301e+03 log10(lambda)=-6.000 --> residuals = 1.121e-01 regularization constraint = 6.108e+02 log10(lambda)=-5.000 --> residuals = 1.153e-01 regularization constraint = 1.148e+02 log10(lambda)=-4.000 --> residuals = 1.210e-01 regularization constraint = 2.192e+01 log10(lambda)=-3.000 --> residuals = 1.309e-01 regularization constraint = 4.383e+00 log10(lambda)=-2.000 --> residuals = 1.474e-01 regularization constraint = 9.509e-01 log10(lambda)=-1.000 --> residuals = 1.778e-01 regularization constraint = 3.208e-01 log10(lambda)=0.000 --> residuals = 2.639e-01 regularization constraint = 1.399e-01 log10(lambda)=1.000 --> residuals = 5.505e-01 regularization constraint = 9.736e-02 Done. .. GENERATED FROM PYTHON SOURCE LINES 131-135 Automatic search ---------------- %% Now try an automatic search of the regularization parameter: .. GENERATED FROM PYTHON SOURCE LINES 135-140 .. code-block:: default iris = scp.IRIS(X_, "langmuir", q=[-8, -1, 50], reg_par=[-10, 1]) iris.plotlcurve(title="L curve, automated search") .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_010.png :alt: L curve :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_010.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Build kernel matrix with: langmuir Build S matrix (sharpness) ... done Solving for 312 channel(s) and 19 observations, search optimum regularization parameter in the range: [10**-10, 10**1] Initial Log(lambda) values = [ -10 -5.798 -3.202 1] log10(lambda)=-10.000 --> residuals = 1.088e-01 regularization constraint = 9.085e+04 log10(lambda)=-5.798 --> residuals = 1.126e-01 regularization constraint = 4.325e+02 log10(lambda)=-3.202 --> residuals = 1.284e-01 regularization constraint = 6.047e+00 log10(lambda)=1.000 --> residuals = 5.505e-01 regularization constraint = 9.736e-02 Curvatures of the inner points: C1 = 0.012 ; C2 = 0.163 New range of Log(lambda) values: [ -10 -7.403 -5.798 -3.202] log10(lambda)=-7.403 --> residuals = 1.099e-01 regularization constraint = 7.236e+03 new curvature: C2 = 0.014 New range (Log lambda):[ -7.403 -5.798 -4.807 -3.202] log10(lambda)=-4.807 --> residuals = 1.162e-01 regularization constraint = 8.329e+01 Curvatures of the inner points: C1 = 0.010 ; C2 = 0.021 New range of Log(lambda) values: [ -7.403 -6.411 -5.798 -4.807] log10(lambda)=-6.411 --> residuals = 1.113e-01 regularization constraint = 1.223e+03 new curvature: C2 = 0.012 New range (Log lambda):[ -6.411 -5.798 -5.42 -4.807] log10(lambda)=-5.420 --> residuals = 1.138e-01 regularization constraint = 2.293e+02 Curvatures of the inner points: C1 = 0.011 ; C2 = 0.014 New range of Log(lambda) values: [ -6.411 -6.033 -5.798 -5.42] log10(lambda)=-6.033 --> residuals = 1.121e-01 regularization constraint = 6.458e+02 new curvature: C2 = 0.012 New range (Log lambda):[ -6.033 -5.798 -5.654 -5.42] log10(lambda)=-5.654 --> residuals = 1.130e-01 regularization constraint = 3.413e+02 Curvatures of the inner points: C1 = 0.011 ; C2 = 0.013 New range of Log(lambda) values: [ -6.033 -5.888 -5.798 -5.654] log10(lambda)=-5.888 --> residuals = 1.124e-01 regularization constraint = 5.035e+02 new curvature: C2 = 0.013 New range (Log lambda):[ -5.888 -5.798 -5.743 -5.654] log10(lambda)=-5.743 --> residuals = 1.128e-01 regularization constraint = 3.950e+02 Curvatures of the inner points: C1 = 0.013 ; C2 = 0.015 New range of Log(lambda) values: [ -5.888 -5.833 -5.798 -5.743] log10(lambda)=-5.833 --> residuals = 1.126e-01 regularization constraint = 4.582e+02 new curvature: C2 = 0.013 New range (Log lambda):[ -5.833 -5.798 -5.777 -5.743] log10(lambda)=-5.777 --> residuals = 1.127e-01 regularization constraint = 4.176e+02 Curvatures of the inner points: C1 = 0.012 ; C2 = 0.015 New range of Log(lambda) values: [ -5.833 -5.811 -5.798 -5.777] log10(lambda)=-5.811 --> residuals = 1.126e-01 regularization constraint = 4.421e+02 new curvature: C2 = 0.011 New range (Log lambda): [ -5.833 -5.819 -5.811 -5.798] log10(lambda)=-5.819 --> residuals = 1.126e-01 regularization constraint = 4.482e+02 optimum found: index = 7 ; Log(lambda) = -5.811 ; lambda = 1.54375e-06 ; curvature = 0.012 Done. .. GENERATED FROM PYTHON SOURCE LINES 141-143 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 143-148 .. code-block:: default iris.plotdistribution(-2) _ = iris.plotmerit(-2) # scp.show() # uncomment to show plot if needed (not necessary in jupyter notebook) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_011.png :alt: plot 2D iris :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_011.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_012.png :alt: 2D IRIS merit plot, $\lambda$ = 6.29e-04 :srcset: /gettingstarted/gallery/auto_examples/analysis/images/sphx_glr_plot_2D_iris_012.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 24.730 seconds) .. _sphx_glr_download_gettingstarted_gallery_auto_examples_analysis_plot_2D_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_2D_iris.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_2D_iris.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_