.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gettingstarted/gallery/auto_examples/nddataset/plot_coordinates.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_nddataset_plot_coordinates.py: NDDataset coordinates example ============================= In this example, we show how coordinates can be used in SpectroChemPy .. GENERATED FROM PYTHON SOURCE LINES 17-19 .. code-block:: default import spectrochempy as scp .. GENERATED FROM PYTHON SOURCE LINES 20-22 Uploading a 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-30 .. 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 31-33 To display them individually use the ``x`` and ``y`` attributes of the dataset ``X``: .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: default X.x .. raw:: html
size 3112
title wavenumbers
coordinates
[ 4000 3999 ... 1001 999.9] cm⁻¹


.. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: default X.y .. raw:: html
size 19
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)]]


.. GENERATED FROM PYTHON SOURCE LINES 42-50 Setting new coordinates ----------------------- In this example, each experiment have a timestamp corresponds to the time when a given pressure of CO in the infrared cell was set. Hence, it would be interesting to replace the "useless" timestamps (``y``) by a pressure coordinates: .. GENERATED FROM PYTHON SOURCE LINES 50-73 .. code-block:: default pressures = [ 0.00300, 0.00400, 0.00900, 0.01400, 0.02100, 0.02600, 0.03600, 0.05100, 0.09300, 0.15000, 0.20300, 0.30000, 0.40400, 0.50300, 0.60200, 0.70200, 0.80100, 0.90500, 1.00400, ] .. GENERATED FROM PYTHON SOURCE LINES 74-76 1. A first way to do this is to replace the time coordinates by the pressure coordinate .. GENERATED FROM PYTHON SOURCE LINES 78-80 *(we first make a copy of the time coordinates for later use the original will be destroyed by the following operation)* .. GENERATED FROM PYTHON SOURCE LINES 80-83 .. code-block:: default c_times = X.y.copy() .. GENERATED FROM PYTHON SOURCE LINES 84-85 Now we perform the replacement with this new coordinate: .. GENERATED FROM PYTHON SOURCE LINES 85-90 .. code-block:: default c_pressures = scp.Coord(pressures, title="pressure", units="torr") X.y = c_pressures print(X.y) .. rst-class:: sphx-glr-script-out .. code-block:: none Coord: [float64] torr (size: 19) .. GENERATED FROM PYTHON SOURCE LINES 91-93 2. A second way is to affect several coordinates to the corresponding dimension. To do this, the simplest is to affect a list of coordinates instead of a single one: .. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: default 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 98-100 By default, the current coordinate is the first one (here `c_times`). For example, it will be used for plotting: .. GENERATED FROM PYTHON SOURCE LINES 100-106 .. 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/nddataset/images/sphx_glr_plot_coordinates_001.png :alt: plot coordinates :srcset: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_001.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_002.png :alt: plot coordinates :srcset: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 107-109 To seamlessly work with the second coordinates (pressures), we can change the default coordinate: .. GENERATED FROM PYTHON SOURCE LINES 109-113 .. 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 114-115 Let's now plot the spectral range of interest. The default coordinate is now used: .. GENERATED FROM PYTHON SOURCE LINES 115-120 .. 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/nddataset/images/sphx_glr_plot_coordinates_003.png :alt: plot coordinates :srcset: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_003.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_004.png :alt: plot coordinates :srcset: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_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 121-124 The same can be done for the x coordinates. Let's take for instance row with index 10 of the previous dataset .. GENERATED FROM PYTHON SOURCE LINES 124-129 .. code-block:: default row10 = X_[10].squeeze() row10.plot() print(row10.coordset) .. image-sg:: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_005.png :alt: plot coordinates :srcset: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none CoordSet: [x:wavenumbers] .. GENERATED FROM PYTHON SOURCE LINES 130-131 Now we wants to add a coordinate with the wavelength instead of wavenumber. .. GENERATED FROM PYTHON SOURCE LINES 131-140 .. code-block:: default c_wavenumber = row10.x.copy() c_wavelength = row10.x.to("nanometer") print(c_wavenumber, c_wavelength) row10.x = [c_wavenumber, c_wavelength] row10.x.select(2) _ = row10.plot() # scp.show() # uncomment to show plot if needed (not necessary in jupyter notebook) .. image-sg:: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_006.png :alt: plot coordinates :srcset: /gettingstarted/gallery/auto_examples/nddataset/images/sphx_glr_plot_coordinates_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none LinearCoord: [float64] cm⁻¹ (size: 312) LinearCoord: [float64] nm (size: 312) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.080 seconds) .. _sphx_glr_download_gettingstarted_gallery_auto_examples_nddataset_plot_coordinates.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_coordinates.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_coordinates.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_