.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/6_Misc/plot_SpecDatabase.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note You can download :ref:`below ` the full example code and run it with 🔬 `Radis-Lab `__, .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_6_Misc_plot_SpecDatabase.py: ================= Spectrum Database ================= RADIS has :py:class:`~radis.tools.database.SpecDatabase` feature used to store and retrieve calculated Spectrums. This feature is convinient if a spectrum takes a long time to compute. A path can be specified for SpecDatabase all Spectrums are stored as .spec files which can be loaded from the SpecDatabase object itself. A csv file is generated which contains all input and conditional parameters of Spectrum. RADIS also has :py:meth:`~radis.lbl.loader.DatabankLoader.init_database` feature which initializes the SpecDatabase for the SpectrumFactory and every Spectrum generated from it will be stored in the SpecDatabase automatically. You can use :py:meth:`~radis.tools.database.SpecList.plot_cond` to make a 2D plot using the conditions of the Spectrums in the SpecDatabase and use a z_label to plot a heat map based on it. :py:class:`~radis.tools.database.SpecDatabase` also has useful :py:meth:`~radis.tools.database.SpecDatabase.fit_spectrum` and :py:meth:`~radis.tools.database.SpecDatabase.interpolate` methods. .. GENERATED FROM PYTHON SOURCE LINES 27-51 .. code-block:: Python from pathlib import Path import numpy as np from radis import SpectrumFactory from radis.tools import SpecDatabase sf = SpectrumFactory( wavenum_min=2900, wavenum_max=3200, molecule="OH", truncation=5, # cm-1 medium="vacuum", verbose=0, # more for more details pressure=10, wstep=0.1, ) sf.warnings = {"AccuracyError": "ignore"} sf.fetch_databank("hitemp") # Generating a Spectrum s1 = sf.eq_spectrum(Tgas=300, path_length=1) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/db/molparam.py:252: FutureWarning: The 'delim_whitespace' keyword in pd.read_csv is deprecated and will be removed in a future version. Use ``sep='\s+'`` instead .. GENERATED FROM PYTHON SOURCE LINES 52-54 Creating SpecDatabase This is simply a local folder on your computer. .. GENERATED FROM PYTHON SOURCE LINES 54-59 .. code-block:: Python from radis.test.utils import getTestFile my_folder = Path(getTestFile(".")) / "SpecDatabase_Test" db = SpecDatabase(my_folder) .. rst-class:: sphx-glr-script-out .. code-block:: none Database SpecDatabase_Test initialised in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files *** Loading the database with 1 processor (0 files)*** .. GENERATED FROM PYTHON SOURCE LINES 60-62 There are many ways to add spectra to the database : Method 1: Creating .spec file and adding manually to SpecDatabase .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python db.add(s1) .. rst-class:: sphx-glr-script-out .. code-block:: none Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424.spec (0.1Mb) loaded 20240424.spec '/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424.spec' .. GENERATED FROM PYTHON SOURCE LINES 66-69 Method 2: Using init_database() SpecDatabase is connected to the SpectrumFactory ``sf`` above Generated Spectrum are added to SpecDatabase automatically : .. GENERATED FROM PYTHON SOURCE LINES 69-88 .. code-block:: Python sf.init_database(my_folder) wstep = np.linspace(0.1, 0.001, 4) Tgas = np.linspace(300, 3000, 4) # Multiple Spectrum calculation based on different values of Tgas and wstep for i in wstep: sf._wstep = i sf.params.wstep = i for j in Tgas: sf.eq_spectrum(Tgas=j, path_length=1) # Loading SpecDatabase db_new = SpecDatabase(my_folder) # Plot Tgas vs wstep for all Spectrums, heatmap based on calculation_time db_new.plot_cond("Tgas", "wstep", "calculation_time") .. image-sg:: /auto_examples/6_Misc/images/sphx_glr_plot_SpecDatabase_001.png :alt: SpecDatabase_Test :srcset: /auto_examples/6_Misc/images/sphx_glr_plot_SpecDatabase_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Loading database SpecDatabase_Test Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib1200K_Trot1200K.spec (0.1Mb) loaded 20240424_Tvib1200K_Trot1200K.spec Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib2100K_Trot2100K.spec (0.1Mb) loaded 20240424_Tvib2100K_Trot2100K.spec Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib3000K_Trot3000K.spec (0.1Mb) loaded 20240424_Tvib3000K_Trot3000K.spec Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib300K_Trot300K.spec (0.2Mb) loaded 20240424_Tvib300K_Trot300K.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib1200K_Trot1200K_1.spec (0.2Mb) loaded 20240424_Tvib1200K_Trot1200K_1.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib2100K_Trot2100K_1.spec (0.2Mb) loaded 20240424_Tvib2100K_Trot2100K_1.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib3000K_Trot3000K_1.spec (0.2Mb) loaded 20240424_Tvib3000K_Trot3000K_1.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib300K_Trot300K_1.spec (0.3Mb) loaded 20240424_Tvib300K_Trot300K_1.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib1200K_Trot1200K_2.spec (0.4Mb) loaded 20240424_Tvib1200K_Trot1200K_2.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib2100K_Trot2100K_2.spec (0.4Mb) loaded 20240424_Tvib2100K_Trot2100K_2.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib3000K_Trot3000K_2.spec (0.4Mb) loaded 20240424_Tvib3000K_Trot3000K_2.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib300K_Trot300K_2.spec (10.7Mb) loaded 20240424_Tvib300K_Trot300K_2.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib1200K_Trot1200K_3.spec (12.2Mb) loaded 20240424_Tvib1200K_Trot1200K_3.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib2100K_Trot2100K_3.spec (12.4Mb) loaded 20240424_Tvib2100K_Trot2100K_3.spec Warning. File already exists. Filename is incremented Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/develop/radis/test/files/SpecDatabase_Test/20240424_Tvib3000K_Trot3000K_3.spec (12.4Mb) loaded 20240424_Tvib3000K_Trot3000K_3.spec Loading database SpecDatabase_Test .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.239 seconds) .. _sphx_glr_download_auto_examples_6_Misc_plot_SpecDatabase.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_SpecDatabase.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_SpecDatabase.py `