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
    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
예제 #3
0
def substract(s1, s2, var='radiance', wunit='nm', Iunit='default', 
              resample=True, name='default'):
    '''Substract s2 to s1

    Parameters    
    ----------
    s1, s2: Spectrum objects
        The spectra to substract.
    var: str, optional
        Spectral quantity (ex: 'radiance', 'transmittance'...).
    wunit: str, optional 
        Wave unit ('nm', 'cm-1', ...) to use for output. If default, s1 wunit is taken.        
    Iunit: str
        If 'default' s1 unit is used for variable var.
    name: str, optional
        If not given will be s1 and s2 names separated by '+'.
    Returns    
    ----------
    sub : Spectrum object where intensities of s1 and s2 are substracted
    
    Note    
    ----------
    Wavelength of s1 is taken as reference.
    '''
    if s1.get_conditions()['medium'] != s2.get_conditions()['medium']:
        raise ValueError('Not the same medium for s1 and s2')
        # Check inputs, get defaults
    # ----
    if Iunit == 'default':
        try:
            Iunit = s1.units[var]
        except KeyError:  # unit not defined in dictionary
            raise KeyError('Iunit not defined in spectrum. Cant plot') 
            
    w1, I3 = get_diff(s1, s2, var=var, wunit=wunit, Iunit=Iunit, 
                                  resample=resample)
    if name != 'default':
        name = s1.get_name()+'+'+s2.get_name()
    sub = Spectrum.from_array(w1, I3, var, 
                               waveunit=wunit, 
                               unit=Iunit,
                               conditions={'medium' : s1.conditions['medium'], 'waveunit':wunit}, 
                               name=name)
    return sub
예제 #4
0
            SourceTables=molecule,
            Environment={
                "T": T,
                "p": pressure_bar / 1.01315,
            },  # K  # atm
            GammaL="gamma_self",
            WavenumberStep=dnu,
            HITRAN_units=False,
        )
        return nu, coef

    t0 = time()
    nu, coef = calc_hapi()
    t0 = time() - t0
    print(("Calculated with HAPI in {0:.2f}s".format(t0)))

    s_hapi = Spectrum.from_array(nu,
                                 coef,
                                 "abscoeff",
                                 waveunit="cm-1",
                                 unit="cm-1")
    s_hapi.name = "HAPI ({0:.1f}s)".format(t0)

    plot_diff(s_hapi, s, "abscoeff")

    print(("Calculated with RADIS in {0:.2f}s".format(
        s.conditions["calculation_time"])))
    print(("Number of lines in RADIS:", len(sf.df0)))

#    plt.savefig('radis_vs_hapi_test_large_ch4.pdf')
예제 #5
0
    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)
        return nu, coef

    t0 = time()
    nu, coef = calc_hapi()
    t0 = time() - t0
    print(('Calculated with HAPI in {0:.2f}s'.format(t0)))

    s_hapi = Spectrum.from_array(nu,
                                 coef,
                                 'abscoeff',
                                 waveunit='cm-1',
                                 unit='cm-1')
    s_hapi.name = 'HAPI ({0:.1f}s)'.format(t0)

    plot_diff(s_hapi, s, 'abscoeff')

    print(('Calculated with RADIS in {0:.2f}s'.format(
        s.conditions['calculation_time'])))
    print(('Number of lines in RADIS:', len(sf.df0)))

#    plt.savefig('radis_vs_hapi_test_large_ch4.pdf')
예제 #6
0
import matplotlib.pyplot as plt
from scipy.optimize import minimize

# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
#                 USER SECTION    (change this as you want)
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

# %% Get Fitted Data

# Data from Dang, adapted by Klarenaar, digitized by us
s_exp = Spectrum.from_txt(
    getValidationCase('test_CO2_3Tvib_vs_klarenaar_data' +
                      '\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,