def calc_hapi():
     ''' Calc spectrum under HAPI '''
     
     clean_after_run = not exists(HAPIdb) and False
 
     try:
         db_begin(HAPIdb)
         if not molecule in tableList():   # only if data not downloaded already
             fetch(molecule, mol_id, iso, wmin-broadening_max_width /
                   2, wmax+broadening_max_width/2)
             # HAPI doesnt correct for side effects
     
         # Calculate with HAPI
         nu, coef = absorptionCoefficient_Voigt(SourceTables='CO2',
                                                Environment={'T': T,  # K
                                                             'p': p/1.01325,  # atm
                                                             },
                                                WavenumberStep=dnu,
                                                HITRAN_units=False,
                                                GammaL='gamma_self')
         nu, trans = transmittanceSpectrum(nu, coef,
                                           Environment={'l': L,  # cm
                                                        })
         s_hapi = Spectrum.from_array(nu, trans, 'transmittance_noslit', 'cm-1', 'I/I0',
                                      conditions={'Tgas': T},
                                      name='HAPI')
     
     except:
         raise
         
     finally:
         if clean_after_run:
             shutil.rmtree(HAPIdb)
     return s_hapi
Beispiel #2
0
    def calc_hapi():
        """ Calc spectrum under HAPI """

        clean_after_run = not exists(HAPIdb) and False

        try:
            db_begin(HAPIdb)
            if not molecule in tableList(
            ):  # only if data not downloaded already
                fetch(
                    molecule,
                    mol_id,
                    iso,
                    wmin - broadening_max_width / 2,
                    wmax + broadening_max_width / 2,
                )
                # HAPI doesnt correct for side effects

            # Calculate with HAPI
            nu, coef = absorptionCoefficient_Voigt(
                SourceTables="CO2",
                Environment={
                    "T": T,
                    "p": p / 1.01325,
                },  # K  # atm
                WavenumberStep=dnu,
                HITRAN_units=False,
                GammaL="gamma_self",
            )
            nu, trans = transmittanceSpectrum(
                nu,
                coef,
                Environment={
                    "l": L,
                },
            )  # cm
            s_hapi = Spectrum.from_array(
                nu,
                trans,
                "transmittance_noslit",
                "cm-1",
                "1",
                conditions={"Tgas": T},
                name="HAPI",
            )

        except:
            raise

        finally:
            if clean_after_run:
                shutil.rmtree(HAPIdb)
        return s_hapi
Beispiel #3
0
def test_broadening(rtol=1e-2, verbose=True, plot=False, *args, **kwargs):
    '''
    Test broadening against HAPI and tabulated data

    We're looking at CO(0->1) line 'R1' at 2150.86 cm-1
    '''
    from radis.io.hapi import db_begin, fetch, tableList, absorptionCoefficient_Voigt

    if plot:  # Make sure matplotlib is interactive so that test are not stuck in pytest
        plt.ion()

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

    # Conditions
    T = 3000
    p = 0.0001
    wstep = 0.001
    wmin = 2150  # cm-1
    wmax = 2152  # cm-1
    broadening_max_width = 10  # cm-1

    # %% HITRAN calculation
    # -----------

    # Generate HAPI database locally
    db_begin(join(dirname(__file__), __file__.replace('.py', '_HAPIdata')))
    if not 'CO' in tableList():  # only if data not downloaded already
        fetch('CO', 5, 1, wmin - broadening_max_width / 2,
              wmax + broadening_max_width / 2)
        # HAPI doesnt correct for side effects

    # Calculate with HAPI
    nu, coef = absorptionCoefficient_Voigt(
        SourceTables='CO',
        Environment={
            'T': T,  # K
            'p': p / 1.01325,  # atm
        },
        WavenumberStep=wstep,
        HITRAN_units=False)

    s_hapi = Spectrum.from_array(nu,
                                 coef,
                                 'abscoeff',
                                 'cm-1',
                                 'cm_1',
                                 conditions={'Tgas': T},
                                 name='HAPI')

    # %% Calculate with RADIS
    # ----------
    sf = SpectrumFactory(
        wavenum_min=wmin,
        wavenum_max=wmax,
        mole_fraction=1,
        path_length=1,  # doesnt change anything
        wstep=wstep,
        pressure=p,
        broadening_max_width=broadening_max_width,
        isotope=[1],
        warnings={
            'MissingSelfBroadeningWarning': 'ignore',
            'NegativeEnergiesWarning': 'ignore',
            'HighTemperatureWarning': 'ignore',
            'GaussianBroadeningWarning': 'ignore'
        })  # 0.2)
    sf.load_databank('HITRAN-CO-TEST')
    #    s = pl.non_eq_spectrum(Tvib=T, Trot=T, Ttrans=T)
    s = sf.eq_spectrum(Tgas=T, name='RADIS')

    if plot:  # plot broadening of line of largest linestrength
        sf.plot_broadening(i=sf.df1.S.idxmax())

    # Plot and compare
    res = abs(get_residual_integral(s, s_hapi, 'abscoeff'))
    if plot:
        plot_diff(s,
                  s_hapi,
                  var='abscoeff',
                  title='{0} bar, {1} K (residual {2:.2g}%)'.format(
                      p, T, res * 100),
                  show_points=False)
        plt.xlim((wmin, wmax))
    if verbose:
        printm('residual:', res)
    assert res < rtol
Beispiel #4
0
    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.fwhm_voigt.max() / 2)))
    print(
        ('WavenumberWingHW/HWHM',
         int(sf.params.broadening_max_width / (sf.df1.fwhm_voigt.max() / 2))))
    assert (int(sf.params.broadening_max_width /
                (sf.df1.fwhm_voigt.max() / 2))) == benchmark_line_brd_ratio

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

    # Generate HAPI database locally
    db_begin(join(dirname(__file__), __file__.replace('.py', '_HAPIdata')))
    if not molecule in tableList():  # only if data not downloaded already
        mol_iso_ids = [k for k in ISO_ID if ISO_ID[k][-1] == molecule]
        mol_iso_ids = [k for k in mol_iso_ids if ISO_ID[k][1] in isotopes]
        fetch_by_ids(molecule, mol_iso_ids, wavenum_min, wavenum_max)

    # Calculate with HAPI
    def calc_hapi():
        nu, coef = absorptionCoefficient_Voigt(
            SourceTables=molecule,
            Environment={
                'T': T,  # K
                'p': pressure_bar / 1.01315,  # atm
            },
            GammaL='gamma_self',
            WavenumberStep=dnu,
            HITRAN_units=False)