.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gettingstarted/examples/gallery/auto_examples_core/c_importer/plot_generic_read.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_examples_gallery_auto_examples_core_c_importer_plot_generic_read.py: Reading datasets ================ In this example, we show the use of the generic `read` method to create dataset either from local or remote files. .. GENERATED FROM PYTHON SOURCE LINES 17-18 First we need to import the spectrochempy API package .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: default import spectrochempy as scp .. GENERATED FROM PYTHON SOURCE LINES 21-25 Import dataset from local files ------------------------------- Read a IR data recorded in Omnic format (``.spg`` extension). We just pass the file name as parameter. .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: default dataset = scp.read("irdata/nh4y-activation.spg") dataset .. raw:: html
name nh4y-activation
author runner@fv-az1152-754
created 2024-03-08 00:59:42+00:00
description
Omnic title: NH4Y-activation.SPG
Omnic filename: /home/runner/.spectrochempy/testdata/irdata/nh4y-activation.spg
history
2024-03-08 00:59:42+00:00> Imported from spg file /home/runner/.spectrochempy/testdata/irdata/nh4y-activation.spg.
2024-03-08 00:59:42+00:00> Sorted by date
DATA
title absorbance
values
[[ 2.057 2.061 ... 2.013 2.012]
[ 2.033 2.037 ... 1.913 1.911]
...
[ 1.794 1.791 ... 1.198 1.198]
[ 1.816 1.815 ... 1.24 1.238]] a.u.
shape (y:55, x:5549)
DIMENSION `x`
size 5549
title wavenumbers
coordinates
[ 6000 5999 ... 650.9 649.9] cm⁻¹
DIMENSION `y`
size 55
title acquisition timestamp (GMT)
coordinates
[1.468e+09 1.468e+09 ... 1.468e+09 1.468e+09] s
labels
[[ 2016-07-06 19:03:14+00:00 2016-07-06 19:13:14+00:00 ... 2016-07-07 04:03:17+00:00 2016-07-07 04:13:17+00:00]
[ vz0466.spa, Wed Jul 06 21:00:38 2016 (GMT+02:00) vz0467.spa, Wed Jul 06 21:10:38 2016 (GMT+02:00) ...
vz0520.spa, Thu Jul 07 06:00:41 2016 (GMT+02:00) vz0521.spa, Thu Jul 07 06:10:41 2016 (GMT+02:00)]]


.. GENERATED FROM PYTHON SOURCE LINES 29-31 .. code-block:: default _ = dataset.plot(style="paper") .. image-sg:: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_001.png :alt: plot generic read :srcset: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 32-33 When using `read`, we can pass filename as a `str` or a `~pathlib.Path` object. .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: default from pathlib import Path filename = Path("irdata/nh4y-activation.spg") dataset = scp.read(filename) .. GENERATED FROM PYTHON SOURCE LINES 39-41 Note that is the file is not found in the current working directory, `SpectroChemPy` will try to find it in the ``datadir`` directory defined in `preferences` : .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default datadir = scp.preferences.datadir datadir .. rst-class:: sphx-glr-script-out .. code-block:: none PosixPath('/home/runner/.spectrochempy/testdata') .. GENERATED FROM PYTHON SOURCE LINES 45-50 If the supplied argument is a directory, then the whole directory is read at once. By default, the different files will be merged along the first dimension (y). However, for this to work, the second dimension (x) must be compatible (same size) or else a WARNING appears. To avoid the warning and get individual spectra, you can set ``merge`` to `False` . .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: default dataset_list = scp.read("irdata", merge=False) dataset_list .. rst-class:: sphx-glr-script-out .. code-block:: none [NDDataset: [float64] a.u. (shape: (y:19, x:3112)), NDDataset: [float64] a.u. (shape: (y:55, x:5549)), NDDataset: [float64] unitless (shape: (y:1, x:3736))] .. GENERATED FROM PYTHON SOURCE LINES 54-56 to get full details on the parameters that can be used, look at the API documentation: `spectrochempy.read` . .. GENERATED FROM PYTHON SOURCE LINES 58-61 Import dataset from remote files -------------------------------- To download and read file from remote server you can use urls. .. GENERATED FROM PYTHON SOURCE LINES 61-62 .. code-block:: default dataset_list = scp.read("http://www.eigenvector.com/data/Corn/corn.mat") .. GENERATED FROM PYTHON SOURCE LINES 63-65 In this case the matlab data contains 7 arrays that have been automatically transformed to `NDDataset` . .. GENERATED FROM PYTHON SOURCE LINES 65-68 .. code-block:: default for nd in dataset_list: print(f"{nd.name} : {nd.shape}") .. rst-class:: sphx-glr-script-out .. code-block:: none m5nbs : (3, 700) mp5nbs : (4, 700) mp6nbs : (4, 700) propvals : (80, 4) m5spec : (80, 700) mp5spec : (80, 700) mp6spec : (80, 700) .. GENERATED FROM PYTHON SOURCE LINES 69-73 The `eigenvector.com `__ website contains the same data in a compressed (zipped) format: `corn.mat_.zip `__ . This can also be used by the `read` method. .. GENERATED FROM PYTHON SOURCE LINES 73-81 .. code-block:: default dataset_list = scp.read( "https://eigenvector.com/wp-content/uploads/2019/06/corn.mat_.zip" ) _ = dataset_list[-1].plot() _ = dataset_list[-2].plot() _ = dataset_list[-3].plot() _ = dataset_list[-4].plot() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_002.png :alt: plot generic read :srcset: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_002.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_003.png :alt: plot generic read :srcset: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_003.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_004.png :alt: plot generic read :srcset: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_004.png :class: sphx-glr-multi-img * .. image-sg:: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_005.png :alt: plot generic read :srcset: /gettingstarted/examples/gallery/auto_examples_core/c_importer/images/sphx_glr_plot_generic_read_005.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 82-84 This ends the example ! The following line can be uncommented if no plot shows when running the .py script with python .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: default # scp.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 3.803 seconds) .. _sphx_glr_download_gettingstarted_examples_gallery_auto_examples_core_c_importer_plot_generic_read.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_generic_read.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_generic_read.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_