コード例 #1
0
def import_hitran_and_populate_particles_table():
    start_time = time.time()
    '''
    #change file to loadable version
    with open('/home/toma/Desktop/molecule_properties.txt', 'r') as f: 
        outfile = open('/home/toma/Desktop/molecule_properties (copy).txt', 'w')
        for line in f: 
            data = line.split()
            data.pop(1)
            for i in data:
                outfile.write("%s " % i)
            outfile.write('\n')
        outfile.close()
    f.close()
    '''

    version_name = 'HITRAN_2016'
    reference_link = r'https://www.sciencedirect.com/science/article/pii/S0022407317301073?via%3Dihub'

    #everything is in string though to be noticed
    #length of lists are 124
    mol_ids, iso_ids, iso_names, iso_abundances, iso_masses, mol_names = \
    np.loadtxt('/home/toma/Desktop/molecule_properties (copy).txt', dtype='str', skiprows=1, usecols=(1, 2, 3, 4, 5, 6), unpack=True)

    for i in range(len(mol_ids)):

        particle_property_query = "INSERT INTO particles VALUES('%s', '%s', '%s', '%s', '%s', null);" % (mol_names[i], iso_names[i], \
                                                               iso_abundances[i], iso_masses[i], 1) #this one is temporary
        #insert each molecule's properties into particles table
        sql_order(particle_property_query)

        #then, fetch all the data from HITRAN using HAPI
        hapi.db_begin('data')
        #becasue cannot choose inifinity as upper limit, use a giant number instead
        #gpp is upper state degeneracy
        hapi.fetch(mol_names[i], int(mol_ids[i]), int(iso_ids[i]), 0, 1e9, Parameters=['nu', 'a', 'gamma_air', 'n_air', 'delta_air', \
                   'elower', 'gpp', 'gamma_H2', 'n_H2', 'delta_H2', 'gamma_He', 'n_He', 'delta_He'])

        #open the file and use insert_hitran.py to insert all parameters into transitions table
        filename = '/home/toma/Desktop/linelists-database/data/{}.data'.format(
            mol_names[i])

        insert_hitran.insert_hitran(filename, version_name, i + 1,
                                    reference_link)

        #delete the files since the files are named by HAPI using mol_name instead of iso_name
        #s.t. python wont get confused in the for loop
        header_filename = '/home/toma/Desktop/linelists-database/data/{}.header'.format(
            mol_names[i])
        os.remove(filename)
        os.remove(header_filename)

    print("Finished in %s seconds" % (time.time() - start_time))
コード例 #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
コード例 #3
0
def test_broadening_vs_hapi(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 hapi import absorptionCoefficient_Voigt, db_begin, fetch, tableList

    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
    hapi_data_path = join(dirname(__file__),
                          __file__.replace(".py", "_HAPIdata"))

    db_begin(hapi_data_path)
    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,
            "p": p / 1.01325,
        },  # K  # 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(path=join(hapi_data_path, "CO.data"),
                     format="hitran",
                     parfuncfmt="hapi")
    #    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
コード例 #4
0
ファイル: preprocess.py プロジェクト: cullinkin/radiate
def create(molecules, nu_min, nu_max):
    for molecule, spec in molecules.items():
        print(f"\n***** Loading Molecule: {molecule} *****\n")
        print(f"*** Minimum Wave Number (nu): {nu_min} ***")
        print(f"*** Maximum Wave Number (nu): {nu_max} ***")
        fetch(molecule, spec[0], spec[1], nu_min, nu_max)
コード例 #5
0
ファイル: main.py プロジェクト: lmachucf1621/Absorption
# Import external libraries
from hapi import absorptionCoefficient_Lorentz, transmittanceSpectrum, fetch
from numpy import savetxt, shape, array

# Spectral range of interest - um
lmin = 2.0  # min wavelength
lmax = 3.0  # max wavelength
kmin = 10**4 / lmax  # min wavenumber
kmax = 10**4 / lmin  # max wavenumber

# Molecular species of interest
nmol = 'H2O'

# Fetch the HITRAN data for the molecule of interest
fetch(nmol, 1, 1, kmin, kmax)

# Compute the absorption/extinction coefficient - cm^-1
kmat, abscoeff = absorptionCoefficient_Lorentz(SourceTables = nmol, \
                                               WavenumberStep = 0.5, \
                                               HITRAN_units = False)

# Process the data to be exported
data = array([10**4 / kmat * 1000, abscoeff]).T
data = data[::-1]

# Export the processed data
filename = './Data/abscoeff' + nmol + '.txt'
savetxt(filename, data, fmt=['%.4E', '%.4E'])

# End of file
コード例 #6
0
ファイル: run_airglowOE.py プロジェクト: Kang-Sun-CfA/Methane
    D_n_nO2 = control['delta number of loosen O2 layers']
    if control['if A band']:
        S_startWavelength = control['sigma start wavelength']
        S_endWavelength = control['sigma end wavelength']
        S_minTH = control['sigma min tangent height']
        S_maxTH = control['sigma max tangent height']
        S_w1_step = control['sigma w1 step']
        S_n_nO2 = control['sigma number of loosen O2 layers']

# load hitran database
db_begin(control['hitran database path'])
if not os.path.exists(
        os.path.join(
            control['hitran database path'], 'O2_{:.1f}-{:.1f}.data'.format(
                D_startWavelength, D_endWavelength))):
    fetch('O2_{:.1f}-{:.1f}'.format(D_startWavelength, D_endWavelength), 7, 1,
          1e7 / D_endWavelength, 1e7 / D_startWavelength)
if control['if A band']:
    if not os.path.exists(
            os.path.join(
                control['hitran database path'],
                'O2_{:.1f}-{:.1f}.data'.format(S_startWavelength,
                                               S_endWavelength))):
        fetch('O2_{:.1f}-{:.1f}'.format(S_startWavelength, S_endWavelength), 7,
              1, 1e7 / S_endWavelength, 1e7 / S_startWavelength)

# load singlet delta band data
s.loadData(if_close_file=False, startWavelength=1200, endWavelength=1340)
# parse data to regular along-track/across track grids, usually 30 along-track, 8 across-track
D_granules = s.divideProfiles(
    radiancePerElectron=control['delta radiance per electron'])
D_ngranule = len(D_granules)