diff --git a/examples/plot_SpecDatabase.py b/examples/plot_SpecDatabase.py new file mode 100644 index 000000000..d173cb3ab --- /dev/null +++ b/examples/plot_SpecDatabase.py @@ -0,0 +1,60 @@ +""" +================================================ +Spectrum Database +================================================ +RADIS has :py:class:`~radis.tools.database.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 :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. + + +""" + +from radis import SpectrumFactory +from radis.tools import SpecDatabase + +sf = SpectrumFactory( + wavenum_min=2900, + wavenum_max=3200, + molecule="OH", + broadening_max_width=10, # cm-1 + medium="vacuum", + verbose=0, # more for more details + pressure=10, + wstep="auto", +) +sf.fetch_databank("hitemp") + +# Generating 2 Spectrums +s1 = sf.eq_spectrum(Tgas=300, path_length=1) +s2 = sf.eq_spectrum(Tgas=600, path_length=1) + +# Creating SpecDatabase +my_folder = r"/home/pipebomb/Desktop/SpecDatabase_Test/" +db = SpecDatabase(my_folder, lazy_loading=False) + +# Method 1: Creating .spec file +db.add(s1) +db.add(s2) + +# Method 2: Using init_database() +sf.init_database(my_folder) + +# Generates Spectrum and adds to SpecDatabase automatically +# Increasing Temperature and decreasing wstep +wstep_value = 2 +for i in range(900, 3100, 300): + wstep_value = wstep_value / 2 + sf.wstep = wstep_value + sf.params.wstep = wstep_value + sf.eq_spectrum(Tgas=i, path_length=1) + + +# Loading SpecDatabase +db_new = SpecDatabase(my_folder) + +# Comparing data conditions of different spectrum from csv generated file +db_new.plot_cond("Tgas", "wstep", "calculation_time") diff --git a/radis/lbl/loader.py b/radis/lbl/loader.py index fa684d82c..9d39df5e0 100644 --- a/radis/lbl/loader.py +++ b/radis/lbl/loader.py @@ -1332,6 +1332,7 @@ def init_database( """Init a :class:`~radis.tools.database.SpecDatabase` folder in ``path`` to later store our spectra. Spectra can also be automatically retrieved from the database instead of being calculated. + Parameters ---------- path: str @@ -1362,6 +1363,9 @@ def init_database( ------- db: SpecDatabase the database where spectra will be stored or retrieved + + + .. minigallery:: radis.lbl.loader.DatabankLoader.init_database """ db = SpecDatabase(path, add_info=add_info, add_date=add_date, binary=compress) diff --git a/radis/tools/database.py b/radis/tools/database.py index 28aae419d..976f53c55 100644 --- a/radis/tools/database.py +++ b/radis/tools/database.py @@ -1668,6 +1668,8 @@ def plot_cond(self, cond_x, cond_y, z_value=None, nfig=None): >>> db.plot(Tvib, Trot, residual) # where residual is calculated by a fitting # procedure... + ------- + .. minigallery:: radis.tools.database.SpecList.plot_cond """ # %% @@ -1686,17 +1688,21 @@ def plot_cond(self, cond_x, cond_y, z_value=None, nfig=None): # Overlay color if z_value is not None: - assert (len(z_value)) == len(self.df) + if type(z_value) is str: + z = self.df[z_value] + else: + z = z_value - z = np.array(z_value) ** 0.5 # because the lower the better + assert len(z) == len(self.df) + z = np.array(z) ** 0.5 # because the lower the better # norm = cm.colors.Normalize(vmax=z.max(), vmin=z.min()) # cmap = cm.PRGn xarr = np.linspace(min(x), max(x)) yarr = np.linspace(min(y), max(y)) mx, my = np.meshgrid(xarr, yarr) - zgrid = griddata((x, y), z, (mx, my), method="linear") + zgrid = griddata((x, y), z, (mx, my), method="nearest") levels = np.linspace(min(z), max(z), 20) ax.contourf( mx, @@ -1805,7 +1811,6 @@ class SpecDatabase(SpecList): requires all conditions to be either float, string, or boolean. List won't work! - See Also -------- :func:`~radis.tools.database.load_spec`, @@ -1827,7 +1832,10 @@ class SpecDatabase(SpecList): Compare another Spectrum to all spectra in the database: - :meth:`~radis.tools.database.SpecDatabase.fit_spectrum`, + :meth:`~radis.tools.database.SpecDatabase.fit_spectrum` + + + .. minigallery:: radis.SpecDatabase """ def __init__(