From 798b0842747cb1532f3c5bd01f9e09dee8d66134 Mon Sep 17 00:00:00 2001 From: anandxkumar Date: Wed, 14 Jul 2021 00:40:23 +0530 Subject: [PATCH 1/5] Linting fixed --- examples/plot_SpecDatabase.py | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/plot_SpecDatabase.py diff --git a/examples/plot_SpecDatabase.py b/examples/plot_SpecDatabase.py new file mode 100644 index 000000000..c5687b62e --- /dev/null +++ b/examples/plot_SpecDatabase.py @@ -0,0 +1,57 @@ +""" +================================================ +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. + +:py:class:`~radis.tools.database.SpecDatabase` +""" + +from radis import SpectrumFactory +from radis.tools import SpecDatabase + +sf = SpectrumFactory( + wavenum_min=2384, + wavenum_max=2400, + molecule="CO2", + isotope="1,2", + broadening_max_width=10, # cm-1 + medium="vacuum", + verbose=0, # more for more details + wstep="auto", +) +sf.fetch_databank() + +# Generating 3 Spectrums +s1 = sf.eq_spectrum(name="Spectum_CO2_400", Tgas=400, path_length=1) +s2 = sf.eq_spectrum(name="Spectum_CO2_450", Tgas=450, path_length=1) +s3 = sf.eq_spectrum(name="Spectum_CO2_500", Tgas=500, 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: Creating .spec file manually +# Note: Doesn't get added to SpecDatabase csv file +s3.store(my_folder + s3.name) + +# Loading SpecDatabase +""" +Note: If number of spec files in SpecDatabase isn't equal to number of Spectrums +in the csv files, use lazy_loading=False. +""" +db_new = SpecDatabase(my_folder, lazy_loading=False) + +# Loading all spec files in a list +list_Spectrum = [] +for s in db_new: + list_Spectrum.append(s) + +# Generating Plot +for spec in list_Spectrum: + spec.plot("radiance_noslit", nfig="same") From 22ead13851b80d25d288e907f607d6ea148fe53e Mon Sep 17 00:00:00 2001 From: anandxkumar Date: Wed, 14 Jul 2021 19:15:01 +0530 Subject: [PATCH 2/5] Updated example, added mini gallery to SpecDatabase, init_database, and plot_cond --- examples/plot_SpecDatabase.py | 42 +++++++++++++++++++++-------------- radis/lbl/loader.py | 4 ++++ radis/tools/database.py | 10 ++++++--- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/examples/plot_SpecDatabase.py b/examples/plot_SpecDatabase.py index c5687b62e..6c0353cba 100644 --- a/examples/plot_SpecDatabase.py +++ b/examples/plot_SpecDatabase.py @@ -2,31 +2,35 @@ ================================================ 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 +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. -:py:class:`~radis.tools.database.SpecDatabase` +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. + + """ from radis import SpectrumFactory from radis.tools import SpecDatabase sf = SpectrumFactory( - wavenum_min=2384, - wavenum_max=2400, - molecule="CO2", - isotope="1,2", + 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() +sf.fetch_databank("hitemp") # Generating 3 Spectrums s1 = sf.eq_spectrum(name="Spectum_CO2_400", Tgas=400, path_length=1) s2 = sf.eq_spectrum(name="Spectum_CO2_450", Tgas=450, path_length=1) -s3 = sf.eq_spectrum(name="Spectum_CO2_500", Tgas=500, path_length=1) # Creating SpecDatabase my_folder = r"/home/pipebomb/Desktop/SpecDatabase_Test/" @@ -36,22 +40,26 @@ db.add(s1) db.add(s2) -# Method 2: Creating .spec file manually -# Note: Doesn't get added to SpecDatabase csv file -s3.store(my_folder + s3.name) + +sf.init_database(my_folder) +sf.eq_spectrum(name="Spectum_CO2_500", Tgas=500, path_length=1) +sf.eq_spectrum(name="Spectum_CO2_550", Tgas=550, path_length=1) +sf.eq_spectrum(name="Spectum_CO2_600", Tgas=600, path_length=1) +sf.eq_spectrum(name="Spectum_CO2_650", Tgas=650, path_length=1) + # Loading SpecDatabase -""" -Note: If number of spec files in SpecDatabase isn't equal to number of Spectrums -in the csv files, use lazy_loading=False. -""" -db_new = SpecDatabase(my_folder, lazy_loading=False) +db_new = SpecDatabase(my_folder) # Loading all spec files in a list list_Spectrum = [] for s in db_new: list_Spectrum.append(s) -# Generating Plot +# Generating 'radiance_noslit' Plot from SpecDatabase for spec in list_Spectrum: spec.plot("radiance_noslit", nfig="same") + + +# Comparing data conditions of different spectrum from csv generated file +db_new.plot_cond("Tgas", "wstep") diff --git a/radis/lbl/loader.py b/radis/lbl/loader.py index 666ab8523..baa4cdc50 100644 --- a/radis/lbl/loader.py +++ b/radis/lbl/loader.py @@ -1339,6 +1339,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 @@ -1369,6 +1370,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..87fca7760 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,7 +1688,7 @@ 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) + assert (len(self.df[z_value])) == len(self.df) z = np.array(z_value) ** 0.5 # because the lower the better @@ -1805,7 +1807,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 +1828,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__( From 0f3a069281abf10797883f850a732f98523d7bce Mon Sep 17 00:00:00 2001 From: anandxkumar Date: Wed, 14 Jul 2021 22:13:04 +0530 Subject: [PATCH 3/5] Updated example to single plot --- examples/plot_SpecDatabase.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/examples/plot_SpecDatabase.py b/examples/plot_SpecDatabase.py index 6c0353cba..b48640a91 100644 --- a/examples/plot_SpecDatabase.py +++ b/examples/plot_SpecDatabase.py @@ -40,8 +40,10 @@ db.add(s1) db.add(s2) - +# Method 2: Using init_database() sf.init_database(my_folder) + +# Generates Spectrum and adds to SpecDatabase automatically sf.eq_spectrum(name="Spectum_CO2_500", Tgas=500, path_length=1) sf.eq_spectrum(name="Spectum_CO2_550", Tgas=550, path_length=1) sf.eq_spectrum(name="Spectum_CO2_600", Tgas=600, path_length=1) @@ -51,15 +53,5 @@ # Loading SpecDatabase db_new = SpecDatabase(my_folder) -# Loading all spec files in a list -list_Spectrum = [] -for s in db_new: - list_Spectrum.append(s) - -# Generating 'radiance_noslit' Plot from SpecDatabase -for spec in list_Spectrum: - spec.plot("radiance_noslit", nfig="same") - - # Comparing data conditions of different spectrum from csv generated file db_new.plot_cond("Tgas", "wstep") From 9d3e216a1a9ebce7256575c4ceb0397809caee45 Mon Sep 17 00:00:00 2001 From: anandxkumar Date: Thu, 15 Jul 2021 03:12:42 +0530 Subject: [PATCH 4/5] Modified plot_cond and added z_value in example --- examples/plot_SpecDatabase.py | 16 ++++++++-------- radis/tools/database.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/plot_SpecDatabase.py b/examples/plot_SpecDatabase.py index b48640a91..f23da2d54 100644 --- a/examples/plot_SpecDatabase.py +++ b/examples/plot_SpecDatabase.py @@ -8,11 +8,13 @@ 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. +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. """ +import numpy as np + from radis import SpectrumFactory from radis.tools import SpecDatabase @@ -29,8 +31,8 @@ sf.fetch_databank("hitemp") # Generating 3 Spectrums -s1 = sf.eq_spectrum(name="Spectum_CO2_400", Tgas=400, path_length=1) -s2 = sf.eq_spectrum(name="Spectum_CO2_450", Tgas=450, path_length=1) +s1 = sf.eq_spectrum(Tgas=300, path_length=1) +s2 = sf.eq_spectrum(Tgas=450, path_length=1) # Creating SpecDatabase my_folder = r"/home/pipebomb/Desktop/SpecDatabase_Test/" @@ -44,14 +46,12 @@ sf.init_database(my_folder) # Generates Spectrum and adds to SpecDatabase automatically -sf.eq_spectrum(name="Spectum_CO2_500", Tgas=500, path_length=1) -sf.eq_spectrum(name="Spectum_CO2_550", Tgas=550, path_length=1) -sf.eq_spectrum(name="Spectum_CO2_600", Tgas=600, path_length=1) -sf.eq_spectrum(name="Spectum_CO2_650", Tgas=650, path_length=1) +for i in np.arange(600, 3100, 150): + 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") +db_new.plot_cond("Tgas", "wstep", "calculation_time") diff --git a/radis/tools/database.py b/radis/tools/database.py index 87fca7760..666c4567c 100644 --- a/radis/tools/database.py +++ b/radis/tools/database.py @@ -1688,17 +1688,22 @@ def plot_cond(self, cond_x, cond_y, z_value=None, nfig=None): # Overlay color if z_value is not None: - assert (len(self.df[z_value])) == len(self.df) + print(type(z_value)) + 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, From 787bb1cb4b82c1e3fbe6ba96be4db2c0f9fa627c Mon Sep 17 00:00:00 2001 From: anandxkumar Date: Thu, 15 Jul 2021 03:48:55 +0530 Subject: [PATCH 5/5] Better example --- examples/plot_SpecDatabase.py | 13 ++++++++----- radis/tools/database.py | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/plot_SpecDatabase.py b/examples/plot_SpecDatabase.py index f23da2d54..d173cb3ab 100644 --- a/examples/plot_SpecDatabase.py +++ b/examples/plot_SpecDatabase.py @@ -13,8 +13,6 @@ """ -import numpy as np - from radis import SpectrumFactory from radis.tools import SpecDatabase @@ -30,9 +28,9 @@ ) sf.fetch_databank("hitemp") -# Generating 3 Spectrums +# Generating 2 Spectrums s1 = sf.eq_spectrum(Tgas=300, path_length=1) -s2 = sf.eq_spectrum(Tgas=450, path_length=1) +s2 = sf.eq_spectrum(Tgas=600, path_length=1) # Creating SpecDatabase my_folder = r"/home/pipebomb/Desktop/SpecDatabase_Test/" @@ -46,7 +44,12 @@ sf.init_database(my_folder) # Generates Spectrum and adds to SpecDatabase automatically -for i in np.arange(600, 3100, 150): +# 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) diff --git a/radis/tools/database.py b/radis/tools/database.py index 666c4567c..976f53c55 100644 --- a/radis/tools/database.py +++ b/radis/tools/database.py @@ -1688,7 +1688,6 @@ def plot_cond(self, cond_x, cond_y, z_value=None, nfig=None): # Overlay color if z_value is not None: - print(type(z_value)) if type(z_value) is str: z = self.df[z_value] else: