Ejemplo n.º 1
0
 def peakmem_eq_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.eq_spectrum(Tgas=1700)
Ejemplo n.º 2
0
    def time_eq_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.eq_spectrum(Tgas=1700)
Ejemplo n.º 3
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.º 4
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)
    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
    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
Ejemplo n.º 7
0
    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())),
    ))
    assert (int(sf.params.broadening_max_width /
                (sf.df1.hwhm_voigt.max()))) == benchmark_line_brd_ratio

    # %% Run HAPI
    print("Now calculating with HAPI")

    # Generate HAPI database locally
Ejemplo n.º 8
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)
# Calculate ground emission
s_earth_0 = sPlanck(wmin, wmax, wstep=wstep, T=T_earth, eps=1 - albedo)

#%% Calculate atmosphere

# Calculate atmosphere layers

slabs = []
print('Calculating Atmosphere layers')
pb = ProgressBar(len(atm))
for i, r in atm.iterrows():
    pb.update(i)
    s = sf.eq_spectrum(
        Tgas=r.T_K,
        mole_fraction=x_CO2,
        path_length=r.path_length * 1e5,  # cm
        pressure=r.P_Pa * 1e-5,  # bar
    )
    slabs.append(s)
pb.done()

# now solve the line of sight for the atmosphere:
print('Solving radiative transfer equation')
s_atm = SerialSlabs(*slabs)

# %% Calculate the total Upward radiation

s_los_400 = SerialSlabs(s_earth_0, s_atm, resample='intersect')

# Note: RADIS does not have an irradiance unit by default.
# Here we create the irradiance from the radiance
Ejemplo n.º 10
0
"""

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
sfco = SpectrumFactory(
    wavelength_min=4000,
    wavelength_max=5000,  # cm-1
    wstep=0.01,
    isotope='1',
    verbose=3,
)