def calc_radis():

        # %% Calculate with RADIS
        # ----------
        pl = SpectrumFactory(wavenum_min=wmin,
                             wavenum_max=wmax,
                             mole_fraction=1,
                             path_length=L,
                             wstep=dnu,
                             molecule=molecule,
                             pressure=p,
                             broadening_max_width=broadening_max_width,
                             cutoff=1e-23,
                             db_use_cached=True,
                             isotope=iso)  # 0.2)
        pl.warnings['MissingSelfBroadeningWarning'] = 'ignore'
        pl.warnings['HighTemperatureWarning'] = 'ignore'
        pl.fetch_databank(format='hitran', load_energies=False)

        s = pl.eq_spectrum(Tgas=T)  # , Ttrans=300)
        s.name = 'RADIS'

        if plot:
            pl.plot_broadening()

        return s
    def calc_radis():

        # %% Calculate with RADIS
        # ----------
        pl = SpectrumFactory(
            wavenum_min=wmin,
            wavenum_max=wmax,
            mole_fraction=1,
            path_length=L,
            wstep=dnu,
            molecule=molecule,
            pressure=p,
            broadening_max_width=broadening_max_width,
            cutoff=1e-23,
            isotope=iso,
        )
        pl.warnings["MissingSelfBroadeningWarning"] = "ignore"
        pl.warnings["HighTemperatureWarning"] = "ignore"
        pl.fetch_databank(
            source="hitran",
            load_energies=False,
            db_use_cached=True,
        )

        s = pl.eq_spectrum(Tgas=T)  # , Ttrans=300)
        s.name = "RADIS"

        if plot:
            pl.plot_broadening()

        return s
Ejemplo n.º 3
0
def run_example():
    setup_test_line_databases(
        verbose=True)  # add HITEMP-CO2-HAMIL-TEST in ~/.radis if not there

    sf = SpectrumFactory(
        wavenum_min=2283.7,
        wavenum_max=2285.1,
        wstep=0.001,
        cutoff=1e-30,
        path_length=0.1,
        mole_fraction=400e-6,
        isotope=[1],
        db_use_cached=True,  # important to test CAche file here
        verbose=2,
    )
    sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
    sf.load_databank("HITEMP-CO2-HAMIL-TEST")

    # Now generate vibrational energies for a 2-T model
    # ... Note that this is arbitrary. Lookup Pannier & Dubuet 2020 for more.
    levels = sf.parsum_calc["CO2"][1]["X"].df
    levels["Evib"] = levels.Evib1 + levels.Evib2 + levels.Evib3

    # Calculate populations using the non-equilibrium module:
    # This will crash the first time because the Levels Database is just a fragment and does not include all levels.
    try:
        sf.non_eq_spectrum(300, 300)
    except AssertionError:  # expected
        sf.df0.dropna(inplace=True)

    getTestFile("HITEMP-CO2-HAMIL-TEST")

    s = sf.non_eq_spectrum(300, 300)
    s.plot()
Ejemplo n.º 4
0
def test_eq_spectrum_gpu():
    T = 1000
    p = 0.1
    wstep = 0.001
    wmin = 2284.0  # cm-1
    wmax = 2285.0  # cm-1
    sf = SpectrumFactory(
        wavenum_min=wmin,
        wavenum_max=wmax,
        mole_fraction=0.01,  # until self and air broadening is implemented
        path_length=1,  # doesnt change anything
        wstep=wstep,
        pressure=p,
        isotope="1",
        chunksize="DLM",
        warnings={
            "MissingSelfBroadeningWarning": "ignore",
            "NegativeEnergiesWarning": "ignore",
            "HighTemperatureWarning": "ignore",
            "GaussianBroadeningWarning": "ignore",
        },
    )
    sf._broadening_method = "fft"
    sf.load_databank(
        path=getTestFile("cdsd_hitemp_09_fragment.txt"),
        format="cdsd-4000",
        parfuncfmt="hapi",
    )
    s_cpu = sf.eq_spectrum(Tgas=T)
    s_gpu = sf.eq_spectrum_gpu(Tgas=T)
    s_cpu.crop(wmin=2284.2, wmax=2284.8)  # remove edge lines
    s_gpu.crop(wmin=2284.2, wmax=2284.8)
    assert s_cpu.compare_with(s_gpu, spectra_only=True, rtol=0.07,
                              plot=False)  # set the appropriate tolerance
Ejemplo n.º 5
0
def run_example():
    from radis import SpectrumFactory

    setup_test_line_databases(
        verbose=True)  # add HITEMP-CO2-HAMIL-TEST in ~/.radis if not there
    sf = SpectrumFactory(
        wavelength_min=4165,
        wavelength_max=4200,
        path_length=0.1,
        pressure=20,
        molecule="CO2",
        isotope="1,2",
        cutoff=1e-25,  # cm/molecule
        broadening_max_width=10,  # cm-1
    )
    sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
    sf.load_databank(
        "HITRAN-CO2-TEST")  # this database must be defined in ~/.radis
Ejemplo n.º 6
0
 def time_noneq_spectrum(self):
     # Note @ dev:  can't use calc_spectrum directly because it cannot
     # read a custom database
     opt = self.test_options
     sf = SpectrumFactory(
         **{
             k: opt[k]
             for k in [
                 "wavenum_min",
                 "wavenum_max",
                 "molecule",
                 "isotope",
                 "wstep",
                 "cutoff",
                 "verbose",
                 "chunksize",
             ]
         }
     )
     sf.load_databank(
         path=opt["path"],
         format=opt["dbformat"],
         parfuncfmt="hapi",
         levelsfmt="radis",
     )
     assert len(sf.df0) == 1487308  # number of lines
     sf.non_eq_spectrum(Ttrans=300, Tvib=1700, Trot=1550)
Ejemplo n.º 7
0
def test_line_survey_CO2(verbose=True,
                         plot=True,
                         warnings=True,
                         *args,
                         **kwargs):

    setup_test_line_databases()

    try:
        pl = SpectrumFactory(
            wavenum_min=2380,
            wavenum_max=2400,
            #                         wavelength_min=4170,
            #                         wavelength_max=4200,
            mole_fraction=400e-6,
            path_length=100,  # cm
            parallel=False,
            cutoff=1e-30,
            isotope=[1],
            save_memory=True,
            db_use_cached=True,
        )  # 0.2)
        pl.warnings["MissingSelfBroadeningWarning"] = "ignore"
        pl.load_databank("HITRAN-CO2-TEST")
        s = pl.eq_spectrum(Tgas=1500)
        s.apply_slit(0.5)
        if plot:
            s.line_survey(overlay="transmittance", barwidth=0.01)

        if verbose:
            printm("no boolean defined for test_line_survey")
        return True  # test not defined (just testing methods work)

    except DatabankNotFound as err:
        assert IgnoreMissingDatabase(err, __file__, warnings)
Ejemplo n.º 8
0
 def peakmem_noneq_spectrum(self):
     opt = self.test_options
     sf = SpectrumFactory(
         **{
             k: opt[k]
             for k in [
                 "wavenum_min",
                 "wavenum_max",
                 "molecule",
                 "isotope",
                 "wstep",
                 "cutoff",
                 "verbose",
                 "chunksize",
             ]
         }
     )
     sf.load_databank(
         path=opt["path"],
         format=opt["dbformat"],
         parfuncfmt="hapi",
         levelsfmt="radis",
     )
     assert len(sf.df0) == 1487308  # number of lines
     sf.non_eq_spectrum(Ttrans=300, Tvib=1700, Trot=1550)
Ejemplo n.º 9
0
    def run_example():

        from radis.test.utils import (
            define_Evib_as_sum_of_Evibi,
            discard_lines_with_na_levels,
        )

        setup_test_line_databases(
            verbose=True)  # add HITEMP-CO2-HAMIL-TEST in ~/.radis if not there

        sf = SpectrumFactory(
            wavenum_min=2283.7,
            wavenum_max=2285.1,
            wstep=0.001,
            cutoff=1e-30,
            path_length=0.1,
            mole_fraction=400e-6,
            isotope=[1],
            verbose=2,
        )
        sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
        sf.load_databank(
            "HITEMP-CO2-HAMIL-TEST",
            db_use_cached=True,  # important to test CAche file here
        )

        # Now generate vibrational energies for a 2-T model
        levels = sf.parsum_calc["CO2"][1]["X"].df
        define_Evib_as_sum_of_Evibi(levels)
        discard_lines_with_na_levels(sf)

        # Calculate populations using the non-equilibrium module:
        # This will crash the first time because the Levels Database is just a fragment and does not include all levels.
        try:
            sf.non_eq_spectrum(300, 300)
        except AssertionError:  # expected
            sf.df0.dropna(inplace=True)

        s = sf.non_eq_spectrum(300, 300)
        s.plot()
Ejemplo n.º 10
0
def test_klarenaar_validation_case(verbose=True,
                                   plot=False,
                                   warnings=True,
                                   *args,
                                   **kwargs):
    """ Reproduce the Klarenaar 2018 validation case, as given in the 
    [RADIS-2018]_ article. 
    
    References
    ----------

    Klarenaar et al, "Time evolution of vibrational temperatures in a CO 2 glow 
    discharge measured with infrared absorption spectroscopy", doi 10.1088/1361-6595/aa902e,
    and the references there in.
    
    """

    setup_test_line_databases()

    # %% Data from Dang, adapted by Klarenaar
    s_exp = Spectrum.from_txt(
        getValidationCase(
            join(
                "test_CO2_3Tvib_vs_klarenaar_data",
                "klarenaar_2017_digitized_data.csv",
            )),
        "transmittance_noslit",
        waveunit="cm-1",
        unit="I/I0",
        delimiter=",",
        name="Klarenaar 2017",
    )

    # %% Calculate Klarenaar test case conditions

    sf = SpectrumFactory(
        2284.2,
        2284.6,
        wstep=0.001,  # cm-1
        pressure=20 * 1e-3,  # bar
        db_use_cached=True,
        cutoff=1e-25,
        molecule="CO2",
        isotope="1,2",
        path_length=10,  # cm-1
        # warning! 10% in mass fraction -> less in mole fraction
        mole_fraction=0.1 * 28.97 / 44.07,
        broadening_max_width=1,  # cm-1
        medium="vacuum",
        export_populations="vib",
    )
    sf.warnings["MissingSelfBroadeningWarning"] = "ignore"
    #        sf.load_databank('HITEMP-CO2-DUNHAM')
    sf.load_databank("HITEMP-CO2-TEST")

    # Calculate with Klarenaar fitted values
    T12 = 517
    T3 = 2641
    Trot = 491

    s = sf.non_eq_spectrum((T12, T12, T3),
                           Trot,
                           Ttrans=Trot,
                           vib_distribution="treanor",
                           name="RADIS")

    if plot:
        plot_diff(s, s_exp, "transmittance_noslit")
    #        plt.savefig('test_CO2_3Tvib_vs_klarenaar.png')

    assert get_residual(s, s_exp, "transmittance_noslit",
                        ignore_nan=True) < 0.003

    return True
Ejemplo n.º 11
0
    benchmark_line_brd_ratio = 50  # “WavenumberWingHW”/HWHMs
    dnu = 0.01  # step in HAPI Benchmark article
    molecule = "CH4"
    wavenum_min = 0.001
    wavenum_max = 11505
    pressure_bar = 1.01315
    T = 296
    isotopes = [1, 2, 3, 4]

    sf = SpectrumFactory(
        wavenum_min=wavenum_min,
        wavenum_max=wavenum_max,
        isotope=isotopes,  #'all',
        verbose=2,
        wstep=dnu,  # depends on HAPI benchmark.
        cutoff=1e-23,
        broadening_max_width=
        5.73,  # Corresponds to WavenumberWingHW/HWHM=50 in HAPI
        molecule=molecule,
    )
    sf.fetch_databank("astroquery", load_energies=False)

    s = sf.eq_spectrum(Tgas=T, pressure=pressure_bar)
    s.name = "RADIS ({0:.1f}s)".format(s.conditions["calculation_time"])

    # Print our HWHM for comparison (a posteriori)
    print(("HWHM max {0:.2f} cm-1".format(sf.df1.hwhm_voigt.max())))
    print((
        "WavenumberWingHW/HWHM",
        int(sf.params.broadening_max_width / (sf.df1.hwhm_voigt.max())),
Ejemplo n.º 12
0
from radis.test.utils import setup_test_line_databases

if __name__ == "__main__":

    # %% Generate carbon monoxide files

    from radis import SpectrumFactory

    setup_test_line_databases()  # add HITRAN-CO-TEST in ~/.radis if not there

    Tgas = 1500
    sf = SpectrumFactory(
        wavelength_min=4400,
        wavelength_max=4800,
        mole_fraction=0.01,
        #                         path_length=0.1,
        cutoff=1e-25,
        wstep=0.005,
        isotope=[1],
        db_use_cached=True,
        self_absorption=True,
        verbose=False,
    )
    sf.load_databank("HITRAN-CO-TEST")
    s1 = sf.non_eq_spectrum(Tgas, Tgas, path_length=0.01)
    s1.store("CO_Tgas1500K_mole_fraction0.01.spec", compress=True)

    s2 = sf.non_eq_spectrum(Tgas, Tgas, path_length=0.01, mole_fraction=0.5)
    s2.store("CO_Tgas1500K_mole_fraction0.5.spec", compress=True)
Ejemplo n.º 13
0
def test_validation_vs_specair(rtol=1e-2,
                               verbose=True,
                               plot=False,
                               *args,
                               **kwargs):
    ''' Test RADIS output on CO IR bands against SPECAIR

    Test is only performed on integrals of absorption coefficient

    RADIS doesnt actually match Specair exactly, but this is due to line intensity
    differences (Specair has no rovibrational specific intensities) rather than 
    differences in populations calculations, as evidenced by the partition functions
    comparison in the RADIS presentation article. 

    '''

    setup_test_line_databases()  # add HITRAN-CO-TEST in ~/.radis if not there

    # %% Specair calculation
    # -----------

    specair_300_300 = load_spec(getValidationCase(
        join('test_validation_vs_specair_noneqCO_data',
             'specair_CO_IR_Tvib300_Trot300.spec')),
                                binary=True)
    specair_300_2000 = load_spec(getValidationCase(
        join('test_validation_vs_specair_noneqCO_data',
             'specair_CO_IR_Tvib300_Trot2000.spec')),
                                 binary=True)
    specair_2000_300 = load_spec(getValidationCase(
        join('test_validation_vs_specair_noneqCO_data',
             'specair_CO_IR_Tvib2000_Trot300.spec')),
                                 binary=True)

    article_version = False  # just for the article

    # %% Compare with RADIS
    # ----------

    wstep = 0.002
    pl = SpectrumFactory(
        wavelength_min=4400,
        wavelength_max=4900,
        mole_fraction=1,
        pressure=0.01,  # bar
        path_length=1,  # we dont care for abscoeff anyway
        parallel=False,
        cutoff=1e-30,
        wstep=wstep,
        isotope=1,  # '1,2,3',
        medium='vacuum')  # 0.2)
    pl.warnings['MissingSelfBroadeningWarning'] = 'ignore'

    if article_version:
        pl.load_databank('HITEMP-CO-DUNHAM')
    else:
        pl.load_databank('HITRAN-CO-TEST')
        # Available on all systems, convenient for fast testing, but you
        # will be missing some small lines for T ~ 2000 K .
        print(
            'Using HITRAN: small lines will be missing at T ~ 2000K. Use HITEMP if you want them'
        )

    s_300_300 = pl.eq_spectrum(300, name='RADIS')

    s_2000_300 = pl.non_eq_spectrum(Tvib=2000,
                                    Trot=300,
                                    Ttrans=300,
                                    name='RADIS')

    s_300_2000 = pl.non_eq_spectrum(Tvib=300,
                                    Trot=2000,
                                    Ttrans=2000,
                                    name='RADIS')

    # %% Test

    # Compare integrals

    b1 = np.isclose(specair_300_300.get_integral('abscoeff'),
                    s_300_300.get_integral('abscoeff'),
                    rtol=rtol)
    b1 *= np.isclose(specair_2000_300.get_integral('abscoeff'),
                     s_2000_300.get_integral('abscoeff'),
                     rtol=rtol)
    b1 *= np.isclose(specair_300_2000.get_integral('abscoeff'),
                     s_300_2000.get_integral('abscoeff'),
                     rtol=rtol)

    # Compare partition functions to hardcoded values
    b2 = np.isclose(s_2000_300.lines.Q, 139, atol=1)  # Specair: 139
    b2 *= np.isclose(s_300_2000.lines.Q, 727, atol=1)  # Specair: 727

    if verbose:
        printm(
            '>>> comparing RADIS vs SPECAIR on CO: integrals of abscoeff is are close'
            + ' to within {0:.1f}%: {1} ({2:.1f}%, {3:.1f}%, {4:.1f}%)'.format(
                rtol * 100,
                bool(b1),
                abs(
                    specair_300_300.get_integral('abscoeff') /
                    s_300_300.get_integral('abscoeff') - 1) * 100,
                abs(
                    specair_2000_300.get_integral('abscoeff') /
                    s_2000_300.get_integral('abscoeff') - 1) * 100,
                abs(
                    specair_300_2000.get_integral('abscoeff') /
                    s_300_2000.get_integral('abscoeff') - 1) * 100,
            ))
        printm('>>> comparing RADIS vs SPECAIR on CO: partition functions ' +
               'are equal to round error: {0}'.format(bool(b2)))

    if plot:
        plot_diff(
            specair_300_300,
            s_300_300,
            title=r'T$_\mathregular{vib}$ 300 K, T$_\mathregular{rot}$ 300 K',
            diff_window=int(
                0.02 // wstep
            ),  # compensate for small shifts in both codes. we're comparing intensities here.
            lw_multiplier=1,  #0.75, 
            wunit='nm_vac',
            plot_medium=True,
        )
        plt.xlim((4500, 4900))
        if article_version:
            plt.savefig(
                'out/test_validation_vs_specair_noneqCO_Tvib300_Trot300.png')
            plt.savefig(
                'out/test_validation_vs_specair_noneqCO_Tvib300_Trot300.pdf')

        plot_diff(
            specair_2000_300,
            s_2000_300,
            title=r'T$_\mathregular{vib}$ 2000 K, T$_\mathregular{rot}$ 300 K',
            diff_window=int(
                0.02 // wstep
            ),  # compensate for small shifts in both codes. we're comparing intensities here.
            lw_multiplier=1,  #0.75, 
            wunit='nm_vac',
            plot_medium=True,
        )
        plt.xlim((4500, 4900))
        if article_version:
            plt.savefig(
                'out/test_validation_vs_specair_noneqCO_Tvib2000_Trot300.png')
            plt.savefig(
                'out/test_validation_vs_specair_noneqCO_Tvib2000_Trot300.pdf')

        plot_diff(
            specair_300_2000,
            s_300_2000,
            title=r'T$_\mathregular{vib}$ 300 K, T$_\mathregular{rot}$ 2000 K',
            diff_window=int(
                0.02 // wstep
            ),  # compensate for small shifts in both codes. we're comparing intensities here.
            lw_multiplier=1,  #0.75, 
            wunit='nm_vac',
            plot_medium=True,
        )
        plt.xlim((4500, 4900))
        if article_version:
            plt.savefig(
                'out/test_validation_vs_specair_noneqCO_Tvib300_Trot2000.png')
            plt.savefig(
                'out/test_validation_vs_specair_noneqCO_Tvib300_Trot2000.pdf')

    return bool(b1 * b2)
Ejemplo n.º 14
0
    def setup(self):
        self.test_options = opt = {
            "wavelength_min": 4165,
            "wavelength_max": 4200,
            "databank": "fetch",  # not appropriate for these temperatures, but convenient for automatic testing
            "Tgas": 300,
            "Tvib": 1700,
            "Trot": 1550,
            "path_length": 0.1,
            "mole_fraction": 0.5,
            "molecule": "CO2",
            "isotope": "1,2",
            "wstep": 0.01,
            "cutoff": 1e-25,
            "use_cached": True,
            "medium": "vacuum",
            "optimization": "simple",
            "export_lines": False,
            "warnings": {
                "MissingSelfBroadeningWarning": "ignore",
                "NegativeEnergiesWarning": "ignore",
                "HighTemperatureWarning": "ignore",
            },
        }

        # Backward compatibility
        # ----------------------

        # Old version of RADIS do not necessary work with the latest parameters
        # Fix it :
        version = get_version(add_git_number=False)
        if version < "0.9.26":
            del self.test_options["optimization"]

        # Also fix problems with cache files :

        # First run to check there are no problems with Line database cache-files
        # ... Note @dev : as of 0.9.26 encountering a cache file generated with a future version
        # ... raises an error with no option to automatically regenerate the cache file
        sf = SpectrumFactory(
            **{
                k: v
                for (k, v) in opt.items()
                if k
                in [
                    "wavelength_min",
                    "wavelength_max",
                    "molecule",
                    "isotope",
                    "broadening_max_width",
                    "medium",
                ]
            }
        )

        for attempt in range(15):  # max number of failed cache files
            try:
                sf.fetch_databank()
            except ValueError as err:
                if "generated with a future version" in str(err):
                    # Get failing cache file :
                    fcache = re.search(
                        r"(?<=Cache file \().*(?=\) generated)", str(err)
                    )
                    if fcache is not None:
                        fcache = fcache.group()
                        printm(
                            "Backward compatibility : regenerating cache file",
                            fcache,
                        )
                        os.remove(fcache)
                        continue
                raise
            else:
                break
Ejemplo n.º 15
0
.. warning::

  the CO2 database used in the paper for the CO2 equilibrium case is CDSD-4000. 
  The database used below is HITEMP-2010, which makes calculations faster 
  for the sake of the example. Expect some differences in the > 4.4 µm region 

"""

from radis import SpectrumFactory, SerialSlabs

# Calculate CO2
sf = SpectrumFactory(
    wavelength_min=4000,
    wavelength_max=5000,  # cm-1
    wstep=0.01,
    isotope='1',
    verbose=3,
    chunksize='DLM',
)
sf.load_databank('HITEMP-CO2')  # link to my CO2 HITEMP database files
s_forebody = sf.eq_spectrum(Tgas=4000,
                            pressure=1,
                            mole_fraction=0.027,
                            path_length=1)
s_freeflow = sf.non_eq_spectrum(Trot=1690,
                                pressure=0.017,
                                Tvib=2200,
                                mole_fraction=0.606,
                                path_length=3)

# Calcule CO
Ejemplo n.º 16
0
    def setup(self):
        self.test_options = opt = {
            "wavenum_min": 2000,
            "wavenum_max": 2250,
            "molecule": "CO2",
            "isotope": "1,2,3",
            "verbose": 3,
            "wstep": 0.01,
            "cutoff": 0,
            "chunksize": "auto",
            "broadening_max_width": 10,
            "path": [
                r"D:\Dropbox\Data ECP\14_Databases\CDSD-HITEMP\cdsd_hitemp_07",
                r"D:\Dropbox\Data ECP\14_Databases\CDSD-HITEMP\cdsd_hitemp_08",
                r"D:\Dropbox\Data ECP\14_Databases\CDSD-HITEMP\cdsd_hitemp_09",
            ],
            "use_cached": True,
            "dbformat": "cdsd-hitemp",
        }

        # Chunksize : number of lines to proceed at the same time (doestn apply if LDM)
        if opt["chunksize"] == "auto":
            opt["chunksize"] = digits(
                virtual_memory().available
                / sys.getsizeof(
                    _generate_broadening_range(
                        opt["wstep"], opt["broadening_max_width"]
                    )
                ),
                n=1,
            )
            printm("chunksize auto : ", opt["chunksize"])

        # Backward compatibility
        # ----------------------

        # Old version of RADIS do not necessary work with the latest parameters
        # Fix it :
        version = get_version(add_git_number=False)
        if version < "0.9.21":
            opt["dbformat"] = "cdsd"

        # Also fix problems with cache files :

        # First run to check there are no problems with Line database cache-files
        # ... Note @dev : as of 0.9.26 encountering a cache file generated with a future version
        # ... raises an error with no option to automatically regenerate the cache file
        sf = SpectrumFactory(
            **{
                k: opt[k]
                for k in [
                    "wavenum_min",
                    "wavenum_max",
                    "molecule",
                    "isotope",
                    "wstep",
                    "cutoff",
                    "verbose",
                ]
            }
        )

        for attempt in range(15):  # max number of failed cache files
            try:
                sf.load_databank(
                    path=opt["path"],
                    format=opt["dbformat"],
                    parfuncfmt="hapi",
                    levelsfmt="radis",
                )
            except ValueError as err:
                if "generated with a future version" in str(err):
                    # Get failing cache file :
                    fcache = re.search(
                        r"(?<=Cache file \().*(?=\) generated)", str(err)
                    )
                    if fcache is not None:
                        fcache = fcache.group()
                        printm(
                            "Backward compatibility : regenerating cache file",
                            fcache,
                        )
                        os.remove(fcache)
                        continue
                raise
            else:
                break
Ejemplo n.º 17
0
def test_klarenaar_validation_case(verbose=True, plot=False, warnings=True,
                                   *args, **kwargs):
    ''' Reproduce the Klarenaar 2018 validation case, as given in the 
    [RADIS-2018]_ article. 
    
    References
    ----------

    Klarenaar et al, "Time evolution of vibrational temperatures in a CO 2 glow 
    discharge measured with infrared absorption spectroscopy", doi 10.1088/1361-6595/aa902e,
    and the references there in.
    
    '''
    
    setup_test_line_databases()

    try:
        # %% Data from Dang, adapted by Klarenaar
        s_exp = Spectrum.from_txt(getValidationCase(join('test_CO2_3Tvib_vs_klarenaar_data', 
                                                    'klarenaar_2017_digitized_data.csv')),
                                  'transmittance_noslit', waveunit='cm-1', unit='I/I0',
                                  delimiter=',',
                                  name='Klarenaar 2017')

        # %% Calculate Klarenaar test case conditions

        sf = SpectrumFactory(2284.2, 2284.6,
                             wstep=0.001,                # cm-1
                             pressure=20*1e-3,           # bar
                             db_use_cached=True,
                             cutoff=1e-25,
                             molecule='CO2',
                             isotope='1,2',
                             path_length=10,             # cm-1
                             # warning! 10% in mass fraction -> less in mole fraction
                             mole_fraction=0.1*28.97/44.07,
                             broadening_max_width=1,     # cm-1
                             medium='vacuum',
                             export_populations='vib',
                             )
        sf.warnings['MissingSelfBroadeningWarning'] = 'ignore'
#        sf.load_databank('HITEMP-CO2-DUNHAM')
        sf.load_databank('HITEMP-CO2-TEST')

        # Calculate with Klarenaar fitted values
        T12 = 517
        T3 = 2641
        Trot = 491

        s = sf.non_eq_spectrum((T12, T12, T3), Trot, Ttrans=Trot,
                               vib_distribution='treanor',
                               name='RADIS')

        if plot:
            plot_diff(s, s_exp, 'transmittance_noslit')
    #        plt.savefig('test_CO2_3Tvib_vs_klarenaar.png')

        assert get_residual(s, s_exp, 'transmittance_noslit', ignore_nan=True) < 0.003
        
        return True

    except DatabankNotFound as err:
        assert IgnoreMissingDatabase(err, __file__, warnings)
Ejemplo n.º 18
0
# Spectral Computation parameters
wstep = 0.003  # wavenumber step (cm-1)
broadening_max_width = 3  # Line broadening (cm-1)

# %% Earth Model
# without albedo, but lower effective temperature
albedo = 0  # reflectivity of the earth surface
T_earth = 288  # average night/day Earth surface  K

# %% Get Spectral line database
sf = SpectrumFactory(
    wavenum_min=wmin,
    wavenum_max=wmax,
    molecule='CO2',
    isotope='1,2,3',
    verbose=False,
    broadening_max_width=broadening_max_width,
    wstep=wstep,
    warnings={'MissingSelfBroadeningWarning': 'ignore'},
    export_lines=False,
    chunksize='DLM',
)
sf.fetch_databank(
    load_energies=False)  # loads from HITRAN, requires an internet connection

#%% ===========================================================================
# Calculations
# =============================================================================

# Calculate ground emission
s_earth_0 = sPlanck(wmin, wmax, wstep=wstep, T=T_earth, eps=1 - albedo)
Ejemplo n.º 19
0
                                            '\klarenaar_2017_digitized_data.csv'),
                          'transmittance_noslit', waveunit='cm-1', unit='I/I0',
                          delimiter=',',
                          name='Klarenaar 2017')

w_exp, T_exp = s_exp.get('transmittance_noslit', wunit='cm-1')

# %% Calculate 

sf = SpectrumFactory(2284.2, 2284.6,
                     wstep=0.001,                # cm-1
                     pressure=20*1e-3,           # bar
                     db_use_cached=True,
                     lvl_use_cached=True,
                     cutoff=1e-25,
                     isotope='1,2',
                     path_length=10,             # cm-1
                     mole_fraction=0.1*28.97/44.07,
                     broadening_max_width=1,     # cm-1
                     medium='vacuum',
                     export_populations='vib',
                     )
sf.warnings['MissingSelfBroadeningWarning'] = 'ignore'
#sf.load_databank('RADIS-CO2-HITEMP')
sf.load_databank('CDSD-HITEMP-DUNHAM')

# Get default values
model_input = {'T12':517, 
               'T3':2641,
               'Trot':491,
               }
Ejemplo n.º 20
0
    unit='I/I0',
    delimiter=',',
    name='Klarenaar 2017')

w_exp, T_exp = s_exp.get('transmittance_noslit', wunit='cm-1')

# %% Calculate

sf = SpectrumFactory(
    2284.2,
    2284.6,
    wstep=0.001,  # cm-1
    pressure=20 * 1e-3,  # bar
    db_use_cached=True,
    lvl_use_cached=True,
    cutoff=1e-25,
    isotope='1,2',
    path_length=10,  # cm-1
    mole_fraction=0.1 * 28.97 / 44.07,
    broadening_max_width=1,  # cm-1
    medium='vacuum',
    export_populations=None,  # 'vib',
)
sf.warnings['MissingSelfBroadeningWarning'] = 'ignore'
sf.load_databank('HITEMP-CO2-TEST')

# Get initial values of fitted parameters
model_input = {
    'T12': 517,
    'T3': 2641,
    'Trot': 491,