Note
Run this example online :
Spectrum Database¶
RADIS has SpecDatabase
feature used to store
and retrieve calculated Spectrums. 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 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 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.
SpecDatabase
also has useful
fit_spectrum()
and
interpolate()
methods.
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)
Creating SpecDatabase This is simply a local folder on your computer.
from radis.test.utils import getTestFile
my_folder = Path(getTestFile(".")) / "SpecDatabase_Test"
db = SpecDatabase(my_folder)
Database SpecDatabase_Test initialised in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files
*** Loading the database with 1 processor (0 files)***
There are many ways to add spectra to the database : Method 1: Creating .spec file and adding manually to SpecDatabase
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816.spec (0.1Mb)
loaded 20230816.spec
'/home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816.spec'
Method 2: Using init_database()
SpecDatabase is connected to the SpectrumFactory sf
above
Generated Spectrum are added to SpecDatabase automatically :
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")

Loading database SpecDatabase_Test
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib1200K_Trot1200K.spec (0.1Mb)
loaded 20230816_Tvib1200K_Trot1200K.spec
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib2100K_Trot2100K.spec (0.1Mb)
loaded 20230816_Tvib2100K_Trot2100K.spec
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib3000K_Trot3000K.spec (0.1Mb)
loaded 20230816_Tvib3000K_Trot3000K.spec
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib300K_Trot300K.spec (0.2Mb)
loaded 20230816_Tvib300K_Trot300K.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib1200K_Trot1200K_1.spec (0.2Mb)
loaded 20230816_Tvib1200K_Trot1200K_1.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib2100K_Trot2100K_1.spec (0.2Mb)
loaded 20230816_Tvib2100K_Trot2100K_1.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib3000K_Trot3000K_1.spec (0.2Mb)
loaded 20230816_Tvib3000K_Trot3000K_1.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib300K_Trot300K_1.spec (0.3Mb)
loaded 20230816_Tvib300K_Trot300K_1.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib1200K_Trot1200K_2.spec (0.4Mb)
loaded 20230816_Tvib1200K_Trot1200K_2.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib2100K_Trot2100K_2.spec (0.4Mb)
loaded 20230816_Tvib2100K_Trot2100K_2.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib3000K_Trot3000K_2.spec (0.4Mb)
loaded 20230816_Tvib3000K_Trot3000K_2.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib300K_Trot300K_2.spec (10.7Mb)
loaded 20230816_Tvib300K_Trot300K_2.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib1200K_Trot1200K_3.spec (12.2Mb)
loaded 20230816_Tvib1200K_Trot1200K_3.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib2100K_Trot2100K_3.spec (12.4Mb)
loaded 20230816_Tvib2100K_Trot2100K_3.spec
Warning. File already exists. Filename is incremented
Spectrum stored in /home/docs/checkouts/readthedocs.org/user_builds/radis/checkouts/latest/radis/test/files/SpecDatabase_Test/20230816_Tvib3000K_Trot3000K_3.spec (12.4Mb)
loaded 20230816_Tvib3000K_Trot3000K_3.spec
Loading database SpecDatabase_Test
/home/docs/checkouts/readthedocs.org/user_builds/radis/conda/latest/lib/python3.8/site-packages/publib/main.py:230: UserWarning:
The figure layout has changed to tight
Total running time of the script: ( 0 minutes 8.122 seconds)