Example #1
0
def test_rtmodit():
    """MODIT vs LPF."""
    xsmode = 'MODIT'
    nus, wav, res = nugrid(2000.0, 2100.0, 40000, 'cm-1', xsmode=xsmode)
    Parr = np.logspace(-8, 2, 100)  # 100 layers from 10^-8 bar to 10^2 bar
    Tarr = 500.*(Parr/Parr[-1])**0.02

    autort = AutoRT(nus, 1.e5, 2.33, Tarr, Parr,
                    xsmode=xsmode)  # g=1.e5 cm/s2, mmw=2.33
    autort.addcia('H2-H2', 0.74, 0.74)  # CIA, mmr(H)=0.74
    autort.addmol('ExoMol', 'CO', 0.01)  # CO line, mmr(CO)=0.01
    F0 = autort.rtrun()

    xsmode = 'LPF'
    autort = AutoRT(nus, 1.e5, 2.33, Tarr, Parr,
                    xsmode=xsmode)  # g=1.e5 cm/s2, mmw=2.33
    autort.addcia('H2-H2', 0.74, 0.74)  # CIA, mmr(H)=0.74
    autort.addmol('ExoMol', 'CO', 0.01)  # CO line, mmr(CO)=0.01
    F1 = autort.rtrun()

    dif = np.sum((F0-F1)**2)/len(F0)/np.median(F0)
    assert dif < 0.001
Example #2
0
    """

    fnu, dnu, Nz = divwavnum(nu, Nz)
    fhatnu, dhatnu, Nz = divwavnum(hatnu, Nz)
    dd = subtract_nu(dnu, dhatnu)
    numatrix0 = add_nu(dd, fnu, fhatnu, Nz)
    return numatrix0


if __name__ == '__main__':
    import matplotlib.pyplot as plt
    from exojax.spec.rtransfer import nugrid
    from exojax.spec import moldb
    import time
    import numpy as np
    nus, wav, res = nugrid(22920, 23000, 1000, unit='AA')
    mdbCO = moldb.MdbExomol('.database/CO/12C-16O/Li2015', nus, crit=1.e-46)
    ts = time.time()
    numatrix = make_numatrix0(nus, mdbCO.nu_lines)
    print(np.median(numatrix))
    te = time.time()
    print(te-ts, 'sec')

    ts = time.time()
    numatrixc = make_numatrix0_device(nus, mdbCO.nu_lines)
    print(np.median(numatrix))
    te = time.time()
    print(te-ts, 'sec')

    print(np.sum((numatrixc-numatrix)**2))
Example #3
0
def test_VALD_MODIT():

    #wavelength range
    wls, wll = 10395, 10405

    #Set a model atmospheric layers, wavenumber range for the model, an instrument
    NP = 100
    Parr, dParr, k = pressure_layer(NP=NP)
    Pref = 1.0  #bar
    ONEARR = np.ones_like(Parr)

    Nx = 2000
    nus, wav, res = nugrid(wls - 5.0, wll + 5.0, Nx, unit="AA", xsmode="modit")

    Rinst = 100000.  #instrumental spectral resolution
    beta_inst = R2STD(
        Rinst)  #equivalent to beta=c/(2.0*np.sqrt(2.0*np.log(2.0))*R)

    #atoms and ions from VALD
    adbV = moldb.AdbVald(
        path_ValdLineList, nus, crit=1e-100
    )  #The crit is defined just in case some weak lines may cause an error that results in a gamma of 0... (220219)
    asdb = moldb.AdbSepVald(adbV)

    #molecules from exomol
    mdbH2O = moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL',
                             nus,
                             crit=1e-50)  #,crit = 1e-40)
    mdbTiO = moldb.MdbExomol('.database/TiO/48Ti-16O/Toto', nus,
                             crit=1e-50)  #,crit = 1e-50)
    mdbOH = moldb.MdbExomol('.database/OH/16O-1H/MoLLIST', nus)
    mdbFeH = moldb.MdbExomol('.database/FeH/56Fe-1H/MoLLIST', nus)

    #CIA
    cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)

    #molecular mass
    molmassH2O = molinfo.molmass("H2O")
    molmassTiO = molinfo.molmass("TiO")
    molmassOH = molinfo.molmass("OH")
    molmassFeH = molinfo.molmass("FeH")
    molmassH = molinfo.molmass("H")
    molmassH2 = molinfo.molmass("H2")

    #Initialization of MODIT (for separate VALD species, and exomol molecules(e.g., FeH))
    cnuS, indexnuS, R, pmarray = initspec.init_modit_vald(
        asdb.nu_lines, nus, asdb.N_usp)
    cnu_FeH, indexnu_FeH, R, pmarray = initspec.init_modit(
        mdbFeH.nu_lines, nus)
    cnu_H2O, indexnu_H2O, R, pmarray = initspec.init_modit(
        mdbH2O.nu_lines, nus)
    cnu_OH, indexnu_OH, R, pmarray = initspec.init_modit(mdbOH.nu_lines, nus)
    cnu_TiO, indexnu_TiO, R, pmarray = initspec.init_modit(
        mdbTiO.nu_lines, nus)

    #sampling the max/min of temperature profiles
    fT = lambda T0, alpha: T0[:, None] * (Parr[None, :] / Pref)**alpha[:, None]
    T0_test = np.array([1500.0, 4000.0, 1500.0, 4000.0])
    alpha_test = np.array([0.2, 0.2, 0.05, 0.05])
    res = 0.2

    #Assume typical atmosphere
    H_He_HH_VMR_ref = [0.1, 0.15, 0.75]
    PH_ref = Parr * H_He_HH_VMR_ref[0]
    PHe_ref = Parr * H_He_HH_VMR_ref[1]
    PHH_ref = Parr * H_He_HH_VMR_ref[2]

    #Precomputing dgm_ngammaL
    dgm_ngammaL_VALD = setdgm_vald_all(asdb, PH_ref, PHe_ref, PHH_ref, R, fT,
                                       res, T0_test, alpha_test)
    dgm_ngammaL_FeH = setdgm_exomol(mdbFeH, fT, Parr, R, molmassFeH, res,
                                    T0_test, alpha_test)
    dgm_ngammaL_H2O = setdgm_exomol(mdbH2O, fT, Parr, R, molmassH2O, res,
                                    T0_test, alpha_test)
    dgm_ngammaL_OH = setdgm_exomol(mdbOH, fT, Parr, R, molmassOH, res, T0_test,
                                   alpha_test)
    dgm_ngammaL_TiO = setdgm_exomol(mdbTiO, fT, Parr, R, molmassTiO, res,
                                    T0_test, alpha_test)

    T0 = 3000.
    alpha = 0.07
    Mp = 0.155 * 1.99e33 / 1.90e30
    Rp = 0.186 * 6.96e10 / 6.99e9
    u1 = 0.0
    u2 = 0.0
    RV = 0.00
    vsini = 2.0

    mmw = 2.33 * ONEARR  #mean molecular weight
    log_e_H = -4.2
    VMR_H = 0.09
    VMR_H2 = 0.77
    VMR_FeH = 10**-8
    VMR_H2O = 10**-4
    VMR_OH = 10**-4
    VMR_TiO = 10**-8
    A_Fe = 1.5
    A_Ti = 1.2

    adjust_continuum = 0.99

    ga = 2478.57730044555 * Mp / Rp**2
    Tarr = T0 * (Parr / Pref)**alpha
    PH = Parr * VMR_H
    PHe = Parr * (1 - VMR_H - VMR_H2)
    PHH = Parr * VMR_H2
    VMR_e = VMR_H * 10**log_e_H

    #VMR of atoms and ions (+Abundance modification)
    mods_ID = jnp.array([[26, 1], [22, 1]])
    mods = jnp.array([A_Fe, A_Ti])
    VMR_uspecies = atomll.get_VMR_uspecies(asdb.uspecies, mods_ID, mods)
    VMR_uspecies = VMR_uspecies[:, None] * ONEARR

    #Compute delta tau

    #Atom & ions (VALD)
    SijMS, ngammaLMS, nsigmaDlS = vald_all(asdb, Tarr, PH, PHe, PHH, R)
    xsmS = xsmatrix_vald(cnuS, indexnuS, R, pmarray, nsigmaDlS, ngammaLMS,
                         SijMS, nus, dgm_ngammaL_VALD)
    dtauatom = dtauVALD(dParr, xsmS, VMR_uspecies, mmw, ga)

    #FeH
    SijM_FeH, ngammaLM_FeH, nsigmaDl_FeH = exomol(mdbFeH, Tarr, Parr, R,
                                                  molmassFeH)
    xsm_FeH = xsmatrix(cnu_FeH, indexnu_FeH, R, pmarray, nsigmaDl_FeH,
                       ngammaLM_FeH, SijM_FeH, nus, dgm_ngammaL_FeH)
    dtaum_FeH = dtauM_mmwl(dParr, jnp.abs(xsm_FeH), VMR_FeH * ONEARR, mmw, ga)

    #H2O
    SijM_H2O, ngammaLM_H2O, nsigmaDl_H2O = exomol(mdbH2O, Tarr, Parr, R,
                                                  molmassH2O)
    xsm_H2O = xsmatrix(cnu_H2O, indexnu_H2O, R, pmarray, nsigmaDl_H2O,
                       ngammaLM_H2O, SijM_H2O, nus, dgm_ngammaL_H2O)
    dtaum_H2O = dtauM_mmwl(dParr, jnp.abs(xsm_H2O), VMR_H2O * ONEARR, mmw, ga)

    #OH
    SijM_OH, ngammaLM_OH, nsigmaDl_OH = exomol(mdbOH, Tarr, Parr, R, molmassOH)
    xsm_OH = xsmatrix(cnu_OH, indexnu_OH, R, pmarray, nsigmaDl_OH, ngammaLM_OH,
                      SijM_OH, nus, dgm_ngammaL_OH)
    dtaum_OH = dtauM_mmwl(dParr, jnp.abs(xsm_OH), VMR_OH * ONEARR, mmw, ga)

    #TiO
    SijM_TiO, ngammaLM_TiO, nsigmaDl_TiO = exomol(mdbTiO, Tarr, Parr, R,
                                                  molmassTiO)
    xsm_TiO = xsmatrix(cnu_TiO, indexnu_TiO, R, pmarray, nsigmaDl_TiO,
                       ngammaLM_TiO, SijM_TiO, nus, dgm_ngammaL_TiO)
    dtaum_TiO = dtauM_mmwl(dParr, jnp.abs(xsm_TiO), VMR_TiO * ONEARR, mmw, ga)

    #Hminus
    dtau_Hm = dtauHminus_mmwl(nus, Tarr, Parr, dParr, VMR_e * ONEARR,
                              VMR_H * ONEARR, mmw, ga)

    #CIA
    dtauc_H2H2 = dtauCIA_mmwl(nus, Tarr, Parr, dParr, VMR_H2 * ONEARR,
                              VMR_H2 * ONEARR, mmw, ga, cdbH2H2.nucia,
                              cdbH2H2.tcia, cdbH2H2.logac)

    #Summations
    dtau = dtauatom + dtaum_FeH + dtaum_H2O + dtaum_OH + dtaum_TiO + dtau_Hm + dtauc_H2H2

    sourcef = planck.piBarr(Tarr, nus)
    F0 = rtrun(dtau, sourcef)
    Frot = response.rigidrot(nus, F0, vsini, u1, u2)
    wavd = jnp.linspace(wls, wll, 500)
    nusd = jnp.array(1.e8 / wavd[::-1])
    mu = response.ipgauss_sampling(nusd, nus, Frot, beta_inst, RV)
    mu = mu / jnp.nanmax(mu) * adjust_continuum

    assert (np.all(~np.isnan(mu)) * \
            np.all(mu != 0) * \
            np.all(abs(mu) != np.inf))
Example #4
0
from exojax.spec.rtransfer import nugrid
from exojax.spec import moldb, molinfo
from exojax.spec.exomol import gamma_exomol
from exojax.spec import SijT, doppler_sigma, gamma_natural
from exojax.spec import planck
import jax.numpy as jnp
from jax import vmap, jit
import numpy as np
import matplotlib.pyplot as plt

N = 1500
# nus,wav,res=nugrid(23365,23385,N,unit="AA")
nus, wav, res = nugrid(23200, 23300, N, unit='AA')
mdbM = moldb.MdbExomol('.database/CH4/12C-1H4/YT34to10', nus)

q = mdbM.qr_interp(1300.0)
S = SijT(1300.0, mdbM.logsij0, mdbM.nu_lines, mdbM.elower, q)
mask = S > 1.e-28
mdbM.masking(mask)

hcperk = 1.4387773538277202
Tfixx = 1300.0
qtT = mdbM.qr_interp(Tfixx)
logSijTx = np.log10(SijT(Tfixx, mdbM.logsij0, mdbM.nu_lines, mdbM.elower, qtT))

fig = plt.figure(figsize=(10, 5.5))
c = plt.scatter(1.e8 / mdbM.nu_lines, hcperk * mdbM.elower, c=logSijTx)
plt.yscale('log')
plt.show()
Example #5
0
flux = flux[mask]
wavd = wavd[mask]
plt.plot(wavd, flux, alpha=0.7, color='C2', label='cleaned')
plt.legend()
plt.ylim(-1000, 5000)
plt.show()

nflux = flux[::-1] / np.median(flux)
nusd = jnp.array(1.e8 / wavd[::-1])

NP = 100
Parr, dParr, k = rt.pressure_layer(NP=NP)
Nx = 5000
nus, wav, res = nugrid(np.min(wavd) - 10.0,
                       np.max(wavd) + 10.0,
                       Nx,
                       unit='AA',
                       xsmode='modit')
Rinst = 100000.
beta_inst = R2STD(Rinst)

molmassH2O = molinfo.molmass('H2O')
molmassCO = molinfo.molmass('CO')

mmw = 2.33  # mean molecular weight
mmrH2 = 0.74
molmassH2 = molinfo.molmass('H2')
vmrH2 = (mmrH2 * mmw / molmassH2)  # VMR

#
Mp = 33.2
Example #6
0
wavd = dat['wav'].values
flux = dat['flux'].values
nusd = jnp.array(1.e8/wavd[::-1])
sigmain = 0.05
norm = 40000
nflux = flux/norm+np.random.normal(0, sigmain, len(wavd))


# The model is almost same as the forward modeling, but we will infer here Rp, RV, MMR_CO, T0, alpha, and Vsini.
# In[7]:


NP = 100
Parr, dParr, k = rt.pressure_layer(NP=NP)
Nx = 1500
nus, wav, res = nugrid(np.min(wavd)-5.0, np.max(wavd)+5.0, Nx, unit='AA')

R = 100000.
beta = c/(2.0*np.sqrt(2.0*np.log(2.0))*R)

molmassCO = molinfo.molmass('CO')
mmw = 2.33  # mean molecular weight
mmrH2 = 0.74
molmassH2 = molinfo.molmass('H2')
vmrH2 = (mmrH2*mmw/molmassH2)  # VMR

Mp = 33.2  # fixing mass...

# Loading the molecular database of CO and the CIA
# In[8]:
Example #7
0
vmrHe = (mmrHe * mmw / molmassHe)

#LINES
g = 10**(5.0)
T0c = 1700.0
Tarr = T0c * np.ones_like(Parr)
maxMMR_CO = 0.01
maxMMR_H2O = 0.005

###########################################################
#Loading Molecular datanase and  Reducing Molecular Lines
###########################################################
Nx = 3000
ws = 22876.0
we = 23010.0
nus, wav, res = nugrid(ws - 5.0, we + 5.0, Nx, unit="AA", xsmode="modit")
#loading molecular database
mdbCO = moldb.MdbExomol('.database/CO/12C-16O/Li2015', nus)
mdbH2O = moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL', nus, crit=1.e-46)
#LOADING CIA
cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)
cdbH2He = contdb.CdbCIA('.database/H2-He_2011.cia', nus)


def ap(fobs, nusd, ws, we, Nx):
    mask = (ws < wavd[::-1]) * (wavd[::-1] < we)
    #additional mask to remove a strong telluric
    mask = mask * ((22898.5 > wavd[::-1]) + (wavd[::-1] > 22899.5))
    fobsx = fobs[mask]
    nusdx = nusd[mask]
    wavdx = 1.e8 / nusdx[::-1]
Example #8
0
Pref = 1.0  # Reference pressure for a T-P model (bar)
NP = 100
Parr, dParr, k = pressure_layer(NP=NP)
mmw = 2.33  #mean molecular weight
ONEARR = np.ones_like(Parr)  #ones_array for MMR
molmassCO = molinfo.molmass("CO")  #molecular mass (CO)
molmassH2O = molinfo.molmass("H2O")  #molecular mass (H2O)

# Instrument
beta = R2STD(100000.)  #std of gaussian from R=100000.

# Loading Molecular datanase and  Reducing Molecular Lines
Nx = 4500  # number of wavenumber bins (nugrid) for fit
ws = 22876.0  # AA
we = 23010.0  # AA
nus, wav, res = nugrid(ws - 5.0, we + 5.0, Nx, unit="AA")

# Masking data
mask = (ws < wavd[::-1]) * (wavd[::-1] < we)  # data fitting range
mask = mask * (
    (22898.5 > wavd[::-1]) +
    (wavd[::-1] > 22899.5))  # Additional mask to remove a strong telluric
fobsx = fobs[mask]
nusdx = nusd[mask]
wavdx = 1.e8 / nusdx[::-1]
errx = err[mask]

# Loading molecular database
mdbCO = moldb.MdbExomol('.database/CO/12C-16O/Li2015', nus)
mdbH2O = moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL', nus, crit=1.e-46)
Example #9
0
def ap(fobs, nusd, ws, we, Nx):
    mask = (ws < wavd[::-1]) * (wavd[::-1] < we)
    #additional mask
    mask = mask * ((22898.5 > wavd[::-1]) + (wavd[::-1] > 22899.5))

    fobsx = fobs[mask]
    nusdx = nusd[mask]
    wavdx = 1.e8 / nusdx[::-1]
    errx = err[mask]
    nus, wav, res = nugrid(ws - 5.0, we + 5.0, Nx, unit="AA")
    #loading molecular database
    #mdbCO=moldb.MdbExomol('.database/CO/12C-16O/Li2015',nus)
    mdbCO = moldb.MdbHit('05_HITEMP2019.par.bz2', nus)
    mdbCO.ExomolQT('.database/CO/12C-16O/Li2015')

    ##use HITEMP later
    mdbH2O = moldb.MdbExomol('H2O/1H2-16O/POKAZATEL', nus, crit=1.e-45)
    #    mdbH2O=moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL',nus)

    print("resolution=", res)

    #LOADING CIA
    cdbH2H2 = contdb.CdbCIA('H2-H2_2011.cia', nus)
    cdbH2He = contdb.CdbCIA('H2-He_2011.cia', nus)

    ### REDUCING UNNECESSARY LINES
    #######################################################

    #1. CO
    Tarr = T0c * np.ones_like(Parr)
    qt = vmap(mdbCO.qr_interp)(Tarr)
    #    gammaL = gamma_hitran(Pfix,Tfix, Ppart, mdbCO.n_air, \
    #                          mdbCO.gamma_air, mdbCO.gamma_self) \
    gammaLMP = jit(vmap(gamma_hitran,(0,0,0,None,None,None)))\
        (Parr*0.99,Tarr,Parr*0.01,mdbCO.n_air,mdbCO.gamma_air,mdbCO.gamma_self)
    gammaLMN = gamma_natural(mdbCO.A)

    #(Nlayer, Nlines)+(None, Nlines)=(Nlayers, Nlines)
    gammaLM = gammaLMP + gammaLMN[None, :]

    SijM=jit(vmap(SijT,(0,None,None,None,0)))\
        (Tarr,mdbCO.logsij0,mdbCO.nu_lines,mdbCO.elower,qt)
    sigmaDM=jit(vmap(doppler_sigma,(None,0,None)))\
        (mdbCO.nu_lines,Tarr,molmassCO)

    mask_CO, maxcf, maxcia = mask_weakline(mdbCO, Parr, dParr, Tarr, SijM,
                                           gammaLM, sigmaDM,
                                           maxMMR_CO * ONEARR, molmassCO, mmw,
                                           g, vmrH2, cdbH2H2)
    mdbCO.masking(mask_CO)

    plot_maxpoint(mask_CO, Parr, maxcf, maxcia, mol="CO")
    plt.savefig("npz/maxpoint_CO.pdf", bbox_inches="tight", pad_inches=0.0)
    #2. H2O
    T0xarr = list(range(500, 1800, 100))
    for k, T0x in enumerate(T0xarr):
        Tarr = T0x * np.ones_like(Parr)

        qt = vmap(mdbH2O.qr_interp)(Tarr)
        gammaLMP = jit(vmap(gamma_exomol,(0,0,None,None)))\
            (Parr,Tarr,mdbH2O.n_Texp,mdbH2O.alpha_ref)
        gammaLMN = gamma_natural(mdbH2O.A)
        gammaLM = gammaLMP + gammaLMN[None, :]
        SijM=jit(vmap(SijT,(0,None,None,None,0)))\
            (Tarr,mdbH2O.logsij0,mdbH2O.nu_lines,mdbH2O.elower,qt)
        sigmaDM=jit(vmap(doppler_sigma,(None,0,None)))\
            (mdbH2O.nu_lines,Tarr,molmassH2O)

        mask_H2O_tmp, maxcf, maxcia = mask_weakline(mdbH2O, Parr, dParr, Tarr,
                                                    SijM, gammaLM, sigmaDM,
                                                    maxMMR_H2O * ONEARR,
                                                    molmassH2O, mmw, g, vmrH2,
                                                    cdbH2H2)
        if k == 0:
            mask_H2O = np.copy(mask_H2O_tmp)
        else:
            mask_H2O = mask_H2O + mask_H2O_tmp

        if T0x == 1700.0:
            plot_maxpoint(mask_H2O_tmp, Parr, maxcf, maxcia, mol="H2O")
            plt.savefig("maxpoint_H2O.pdf",
                        bbox_inches="tight",
                        pad_inches=0.0)

    mdbH2O.masking(mask_H2O)
    print("Final:", len(mask_H2O), "->", np.sum(mask_H2O))

    #nu matrix
    numatrix_CO = make_numatrix0(nus, mdbCO.nu_lines)
    numatrix_H2O = make_numatrix0(nus, mdbH2O.nu_lines)
    cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)
    cdbH2He = contdb.CdbCIA('.database/H2-He_2011.cia', nus)

    return fobsx, nusdx, wavdx, errx, nus, wav, res, mdbCO, mdbH2O, numatrix_CO, numatrix_H2O, cdbH2H2, cdbH2He
Example #10
0
import matplotlib.pyplot as plt
from exojax.spec.rtransfer import nugrid
from exojax.spec import moldb, molinfo
from exojax.spec.exomol import gamma_exomol
from exojax.spec import SijT, doppler_sigma, gamma_natural
from exojax.spec import planck
import jax.numpy as jnp
from jax import vmap, jit

N = 1500
# nus,wav,res=nugrid(23365,23385,N,unit="AA")
nus, wav, res = nugrid(23425, 23450, N, unit='AA')
mdbM = moldb.MdbExomol('.database/CO/12C-16O/Li2015', nus)
# loading molecular database
# molmass=molinfo.molmass("CO") #molecular mass (CO)
# mdbM=moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL',nus,crit=1.e-45) #loading molecular dat
# molmassM=molinfo.molmass("H2O") #molecular mass (H2O)


q = mdbM.qr_interp(1500.0)
S = SijT(1500.0, mdbM.logsij0, mdbM.nu_lines, mdbM.elower, q)
mask = S > 1.e-28
mdbM.masking(mask)


Tarr = jnp.logspace(jnp.log10(800), jnp.log10(1700), 100)
qt = vmap(mdbM.qr_interp)(Tarr)
SijM = jit(vmap(SijT, (0, None, None, None, 0)))(
    Tarr, mdbM.logsij0, mdbM.nu_lines, mdbM.elower, qt)

Example #11
0
#import sys
# sys.exit()

dat = pd.read_csv('data/profile.dat')

Parr = dat['P'].values
NP = len(Parr)
Parrx, dParr, k = rt.pressure_layer(NP=NP,
                                    logPtop=np.log10(Parr[0]),
                                    logPbtm=np.log10(Parr[-1]))
Tarr = dat['T'].values
MMR = dat['C1H4'].values

#Parr, dParr, k=rt.pressure_layer(NP=NP)
#Tarr = T0*(Parr)**0.1
nus, wav, R = nugrid(15900, 16300, 30000, unit='AA', xsmode='modit')
print('R=', R)
mdbCH4 = moldb.MdbExomol('.database/CH4/12C-1H4/YT10to10/', nus, crit=1.e-36)
cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)
print('N=', len(mdbCH4.A))
molmassCH4 = molinfo.molmass('CH4')
qt = vmap(mdbCH4.qr_interp)(Tarr)
gammaLMP = jit(vmap(gamma_exomol,
                    (0, 0, None, None)))(Parr, Tarr, mdbCH4.n_Texp,
                                         mdbCH4.alpha_ref)
gammaLMN = gamma_natural(mdbCH4.A)
gammaLM = gammaLMP + gammaLMN[None, :]
nsigmaDl = normalized_doppler_sigma(Tarr, molmassCH4, R)[:, np.newaxis]
SijM = jit(vmap(SijT,
                (0, None, None, None, 0)))(Tarr, mdbCH4.logsij0,
                                           mdbCH4.nu_lines, mdbCH4.elower, qt)
Example #12
0
        val1 = np.abs(np.max(np.abs(w)) / np.median(p))
        val2 = -np.inf  # do not check
    if val1 < crit1 and val2 < crit2:
        return True
    else:
        return False


if __name__ == '__main__':
    from exojax.spec.unitconvert import wav2nu
    from exojax.spec.rtransfer import nugrid

    wav = np.linspace(22920.23000, 1000)
    nus = wav2nu(wav, inputunit='AA')
    print(check_scale_nugrid(nus, gridmode='ESLIN'))
    print('----------------------')

    nus, wav, res = nugrid(22999, 23000, 1000, 'AA')
    print(check_scale_nugrid(nus))
    nus, wav, res = nugrid(22999, 23000, 10000, 'AA')
    print(check_scale_nugrid(nus))
    nus, wav, res = nugrid(22999, 23000, 100000, 'AA')
    print(check_scale_nugrid(nus))

    nus = np.linspace(1.e8 / 23000., 1.e8 / 22999., 1000)
    print(check_scale_nugrid(nus))
    nus = np.linspace(1.e8 / 23000., 1.e8 / 22999., 10000)
    print(check_scale_nugrid(nus))
    nus = np.linspace(1.e8 / 23000., 1.e8 / 22999., 100000)
    print(check_scale_nugrid(nus))
Example #13
0
import numpy as np
from exojax.spec.rtransfer import nugrid
from exojax.spec import AutoRT
import matplotlib.pyplot as plt

xsmode = 'MODIT'
nus, wav, res = nugrid(1900.0, 2300.0, 160000, 'cm-1', xsmode=xsmode)
Parr = np.logspace(-8, 2, 100)  # 100 layers from 10^-8 bar to 10^2 bar
Tarr = 500.*(Parr/Parr[-1])**0.02

autort = AutoRT(nus, 1.e5, 2.33, Tarr, Parr,
                xsmode=xsmode)  # g=1.e5 cm/s2, mmw=2.33
autort.addcia('H2-H2', 0.74, 0.74)  # CIA, mmr(H)=0.74
autort.addmol('ExoMol', 'CO', 0.01)  # CO line, mmr(CO)=0.01
F0 = autort.rtrun()

xsmode = 'LPF'
autort = AutoRT(nus, 1.e5, 2.33, Tarr, Parr,
                xsmode=xsmode)  # g=1.e5 cm/s2, mmw=2.33
autort.addcia('H2-H2', 0.74, 0.74)  # CIA, mmr(H)=0.74
autort.addmol('ExoMol', 'CO', 0.01)  # CO line, mmr(CO)=0.01
F1 = autort.rtrun()
print('MODIT and LPF DIF=', np.sum((F0-F1)**2)/len(F0)/np.median(F0))


plt.plot(nus, F0, label='MODIT')
plt.plot(nus, F1, '.', label='LPF')
plt.legend()
plt.show()

Example #14
0
def ap(fobs, nusd, ws, we, Nx):
    mask = (ws < wavd[::-1]) * (wavd[::-1] < we)
    #additional mask to remove a strong telluric
    mask = mask * ((22898.5 > wavd[::-1]) + (wavd[::-1] > 22899.5))
    fobsx = fobs[mask]
    nusdx = nusd[mask]
    wavdx = 1.e8 / nusdx[::-1]
    errx = err[mask]
    nus, wav, res = nugrid(ws - 5.0, we + 5.0, Nx, unit="AA")
    #loading molecular database
    mdbCO = moldb.MdbExomol('.database/CO/12C-16O/Li2015', nus)
    mdbH2O = moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL',
                             nus,
                             crit=1.e-46)
    #LOADING CIA
    cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)
    cdbH2He = contdb.CdbCIA('.database/H2-He_2011.cia', nus)

    #REDUCING UNNECESSARY LINES
    #1. CO
    Tarr = T0c * np.ones_like(Parr)
    qt = vmap(mdbCO.qr_interp)(Tarr)
    gammaLMP = jit(vmap(gamma_exomol,(0,0,None,None)))\
        (Parr,Tarr,mdbCO.n_Texp,mdbCO.alpha_ref)
    gammaLMN = gamma_natural(mdbCO.A)
    gammaLM = gammaLMP + gammaLMN[None, :]
    SijM=jit(vmap(SijT,(0,None,None,None,0)))\
        (Tarr,mdbCO.logsij0,mdbCO.nu_lines,mdbCO.elower,qt)
    sigmaDM=jit(vmap(doppler_sigma,(None,0,None)))\
        (mdbCO.nu_lines,Tarr,molmassCO)
    mask_CO, maxcf, maxcia = mask_weakline(mdbCO,
                                           Parr,
                                           dParr,
                                           Tarr,
                                           SijM,
                                           gammaLM,
                                           sigmaDM,
                                           maxMMR_CO * ONEARR,
                                           molmassCO,
                                           mmw,
                                           g,
                                           vmrH2,
                                           cdbH2H2,
                                           margin=2)
    mdbCO.masking(mask_CO)

    #plot_maxpoint(mask_CO,Parr,maxcf,maxcia,mol="CO")
    #plt.savefig("maxpoint_CO.pdf", bbox_inches="tight", pad_inches=0.0)

    #2. H2O
    T0xarr = list(range(500, 1800, 100))
    for k, T0x in enumerate(T0xarr):
        Tarr = T0x * np.ones_like(Parr)
        qt = vmap(mdbH2O.qr_interp)(Tarr)
        gammaLMP = jit(vmap(gamma_exomol,(0,0,None,None)))\
            (Parr,Tarr,mdbH2O.n_Texp,mdbH2O.alpha_ref)
        gammaLMN = gamma_natural(mdbH2O.A)
        gammaLM = gammaLMP + gammaLMN[None, :]
        SijM=jit(vmap(SijT,(0,None,None,None,0)))\
            (Tarr,mdbH2O.logsij0,mdbH2O.nu_lines,mdbH2O.elower,qt)
        sigmaDM=jit(vmap(doppler_sigma,(None,0,None)))\
            (mdbH2O.nu_lines,Tarr,molmassH2O)
        mask_H2O_tmp, maxcf, maxcia = mask_weakline(mdbH2O,
                                                    Parr,
                                                    dParr,
                                                    Tarr,
                                                    SijM,
                                                    gammaLM,
                                                    sigmaDM,
                                                    maxMMR_H2O * ONEARR,
                                                    molmassH2O,
                                                    mmw,
                                                    g,
                                                    vmrH2,
                                                    cdbH2H2,
                                                    margin=2)
        if k == 0:
            mask_H2O = np.copy(mask_H2O_tmp)
        else:
            mask_H2O = mask_H2O + mask_H2O_tmp

        if k == len(T0xarr) - 1:
            print("H2O ")
            plot_maxpoint(mask_H2O_tmp, Parr, maxcf, maxcia, mol="H2O")
            plt.savefig("maxpoint_H2O.pdf",
                        bbox_inches="tight",
                        pad_inches=0.0)
            print("H2O saved")

    mdbH2O.masking(mask_H2O)
    print("Final:", len(mask_H2O), "->", np.sum(mask_H2O))
    #nu matrix
    numatrix_CO = make_numatrix0(nus, mdbCO.nu_lines)
    numatrix_H2O = make_numatrix0(nus, mdbH2O.nu_lines)

    return fobsx, nusdx, wavdx, errx, nus, wav, res, mdbCO, mdbH2O, numatrix_CO, numatrix_H2O, cdbH2H2, cdbH2He
Example #15
0
from exojax.spec import AutoXS
nus=numpy.linspace(1900.0,2300.0,200000,dtype=numpy.float64) #wavenumber (cm-1)
autoxs=AutoXS(nus,"ExoMol","CO") #using ExoMol CO (12C-16O). HITRAN and HITEMP are also supported.  
xsv=autoxs.xsection(1000.0,1.0)

plt.plot(nus,xsv)
plt.show()
plt.clf()

ls=autoxs.linest(1000.0) #line strength for T=1000K
plt.plot(autoxs.mdb.nu_lines,ls,".")
plt.show()

from exojax.spec.rtransfer import nugrid
from exojax.spec import AutoRT
nus,wav,res=nugrid(1900.0,2300.0,200000,"cm-1")
Parr=numpy.logspace(-8,2,100) #100 layers from 10^-8 bar to 10^2 bar
Tarr = 500.*(Parr/Parr[-1])**0.02    
autort=AutoRT(nus,1.e5,2.33,Tarr,Parr) #g=1.e5 cm/s2, mmw=2.33
autort.addcia("H2-H2",0.74,0.74)       #CIA, mmr(H)=0.74
autort.addcia("H2-He",0.74,0.25)       #CIA, mmr(He)=0.25
autort.addmol("ExoMol","CO",0.01)      #CO line, mmr(CO)=0.01
F=autort.rtrun()

nusobs=numpy.linspace(1900.0,2300.0,10000,dtype=numpy.float64) #observation wavenumber bin (cm-1)
Fx=autort.spectrum(nusobs,100000.0,20.0,0.0) #R=100000, vsini=10km/s, RV=0km/s

plt.plot(nus,F)
plt.plot(nus,Fx)
plt.show()
import matplotlib.pyplot as plt
from exojax.spec.rtransfer import nugrid
from exojax.spec import moldb, molinfo
from exojax.spec.exomol import gamma_exomol
from exojax.spec import SijT, doppler_sigma, gamma_natural
from exojax.spec import planck
import jax.numpy as jnp
from jax import vmap, jit

N = 1500
nus, wav, res = nugrid(22900, 22960, N, unit='AA')
# mdbM=moldb.MdbExomol('.database/CO/12C-16O/Li2015',nus)
# loading molecular database
# molmass=molinfo.molmass("CO") #molecular mass (CO)
mdbM = moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL', nus,
                       crit=1.e-45)  # loading molecular dat
molmassM = molinfo.molmass('H2O')  # molecular mass (H2O)

q = mdbM.qr_interp(1500.0)
S = SijT(1500.0, mdbM.logsij0, mdbM.nu_lines, mdbM.elower, q)
mask = S > 1.e-25
mdbM.masking(mask)

Tarr = jnp.logspace(jnp.log10(800), jnp.log10(1600), 100)
qt = vmap(mdbM.qr_interp)(Tarr)
SijM = jit(vmap(SijT,
                (0, None, None, None, 0)))(Tarr, mdbM.logsij0, mdbM.nu_lines,
                                           mdbM.elower, qt)

imax = jnp.argmax(SijM, axis=0)
Tmax = Tarr[imax]
import matplotlib.pyplot as plt
import numpy
from exojax.spec.rtransfer import nugrid
from exojax.spec import AutoRT

nus, wav, res = nugrid(1900.0, 2300.0, 200000, 'cm-1')
Parr = numpy.logspace(-8, 2, 100)  # 100 layers from 10^-8 bar to 10^2 bar
Tarr = 500. * (Parr / Parr[-1])**0.02
autort = AutoRT(nus, 1.e5, 2.33, Tarr, Parr)  # g=1.e5 cm/s2, mmw=2.33
autort.addcia('H2-H2', 0.74, 0.74)  # CIA, mmr(H)=0.74
autort.addcia('H2-He', 0.74, 0.25)  # CIA, mmr(He)=0.25
autort.addmol('ExoMol', 'CO', 0.01)  # CO line, mmr(CO)=0.01
F = autort.rtrun()

plt.plot(nus, F)
plt.show()