コード例 #1
0
ファイル: autospec.py プロジェクト: HajimeKawahara/exojax
    def addcia(self, interaction, mmr1, mmr2):
        """
        Args:
           interaction: e.g. H2-H2, H2-He
           mmr1: mass mixing ratio for molecule 1
           mmr2: mass mixing ratio for molecule 2

        """
        mol1, mol2 = defcia.interaction2mols(interaction)
        molmass1 = molinfo.molmass(mol1)
        molmass2 = molinfo.molmass(mol2)
        vmr1 = (mmr1 * self.mmw / molmass1)
        vmr2 = (mmr2 * self.mmw / molmass2)
        ciapath = pathlib.Path(self.databasedir) / \
            pathlib.Path(defcia.ciafile(interaction))
        cdb = contdb.CdbCIA(str(ciapath), [self.nus[0], self.nus[-1]])
        dtauc = dtauCIA(self.nus, self.Tarr, self.Parr, self.dParr, vmr1, vmr2,
                        self.mmw, self.gravity, cdb.nucia, cdb.tcia, cdb.logac)
        self.dtau = self.dtau + dtauc
コード例 #2
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

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]
print(jnp.min(Tmax))
コード例 #3
0
ファイル: complpf.py プロジェクト: HajimeKawahara/exojax
#loading spectrum
dat = pd.read_csv("../data/luhman16a_spectra_detector1.csv", delimiter=",")
wavd = (dat["wavelength_micron"].values) * 1.e4  #AA
nusd = 1.e8 / wavd[::-1]
fobs = (dat["normalized_flux"].values)[::-1]
err = (dat["err_normalized_flux"].values)[::-1]

#ATMOSPHERE
NP = 100
Parr, dParr, k = rt.pressure_layer(NP=NP)
mmw = 2.33  #mean molecular weight
R = 100000.
beta = c / (2.0 * np.sqrt(2.0 * np.log(2.0)) * R)  #IP sigma need check
ONEARR = np.ones_like(Parr)  #ones_array for MMR
molmassCO = molinfo.molmass("CO")  #molecular mass (CO)
molmassH2O = molinfo.molmass("H2O")  #molecular mass (H2O)

#LOADING CIA
mmrH2 = 0.74
mmrHe = 0.25
molmassH2 = molinfo.molmass("H2")
molmassHe = molinfo.molmass("He")
vmrH2 = (mmrH2 * mmw / molmassH2)
vmrHe = (mmrHe * mmw / molmassHe)

#LINES
g = 10**(5.0)
T0c = 1700.0
Tarr = T0c * np.ones_like(Parr)
maxMMR_CO = 0.01
コード例 #4
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))
コード例 #5
0
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
mdbH2O = moldb.MdbExomol('.database/H2O/1H2-16O/POKAZATEL/', nus, crit=1.e-50)
mdbCO = moldb.MdbExomol('.database/CO/12C-16O/Li2015/', nus)
cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)
print('N=', len(mdbH2O.nu_lines))

# Reference pressure for a T-P model
コード例 #6
0
sigmain = 0.05
norm = 20000
nflux = flux / norm + np.random.normal(0, sigmain, len(wavd))

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

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

#
Mp = 33.2
mdbCH4 = moldb.MdbExomol('.database/CH4/12C-1H4/YT10to10/', nus, crit=1.e-30)
cdbH2H2 = contdb.CdbCIA('.database/H2-H2_2011.cia', nus)
print('N=', len(mdbCH4.nu_lines))

# Reference pressure for a T-P model
Pref = 1.0  # bar
ONEARR = np.ones_like(Parr)
ONEWAV = jnp.ones_like(nflux)
コード例 #7
0
ファイル: autospec.py プロジェクト: HajimeKawahara/exojax
    def xsmatrix(self, Tarr, Parr):
        """cross section matrix.

        Args:
           Tarr: temperature layer (K)
           Parr: pressure layer (bar)

        Returns:
           cross section (cm2)
        """
        mdb = self.mdb
        if self.database == 'ExoMol':
            qt = vmap(mdb.qr_interp)(Tarr)
            gammaLMP = jit(vmap(gamma_exomol,
                                (0, 0, None, None)))(Parr, Tarr, mdb.n_Texp,
                                                     mdb.alpha_ref)
            gammaLMN = gamma_natural(mdb.A)
            gammaLM = gammaLMP + gammaLMN[None, :]
            self.molmass = mdb.molmass
            SijM = jit(vmap(SijT, (0, None, None, None, 0)))(Tarr, mdb.logsij0,
                                                             mdb.nu_lines,
                                                             mdb.elower, qt)

        elif self.database == 'HITRAN' or self.database == 'HITEMP':
            qt = mdb.Qr_layer(Tarr)
            gammaLM = jit(vmap(gamma_hitran, (0, 0, 0, None, None, None)))(Parr, Tarr, Parr, mdb.n_air, mdb.gamma_air, mdb.gamma_self)\
                + gamma_natural(mdb.A)
            self.molmass = molinfo.molmass(self.molecules)
            SijM = jit(vmap(SijT, (0, None, None, None, 0)))(Tarr, mdb.logsij0,
                                                             mdb.nu_lines,
                                                             mdb.elower, qt)

        print('# of lines', len(mdb.nu_lines))
        memory_size = 15.0
        d = int(memory_size / (len(mdb.nu_lines) * 4 / 1024. / 1024.)) + 1
        d2 = 100
        Nlayer, Nline = np.shape(SijM)
        if self.xsmode == 'auto':
            xsmode = self.select_xsmode(Nline)
        else:
            xsmode = self.xsmode
        print('xsmode=', xsmode)

        if xsmode == 'lpf' or xsmode == 'LPF':
            sigmaDM = jit(vmap(doppler_sigma,
                               (None, 0, None)))(mdb.nu_lines, Tarr,
                                                 self.molmass)
            Nj = int(Nline / d2)
            xsm = []
            for i in tqdm.tqdm(range(0, int(len(self.nus) / d) + 1)):
                s = int(i * d)
                e = int((i + 1) * d)
                e = min(e, len(self.nus))
                xsmtmp = np.zeros((Nlayer, e - s))
                for j in range(0, Nj + 1):
                    s2 = int(j * d2)
                    e2 = int((j + 1) * d2)
                    e2 = min(e2, Nline)
                    numatrix = make_numatrix0(self.nus[s:e],
                                              mdb.nu_lines[s2:e2])
                    xsmtmp = xsmtmp +\
                        lpf.xsmatrix(
                            numatrix, sigmaDM[:, s2:e2], gammaLM[:, s2:e2], SijM[:, s2:e2])
                if i == 0:
                    xsm = np.copy(xsmtmp.T)
                else:
                    xsm = np.concatenate([xsm, xsmtmp.T])
            xsm = xsm.T
        elif xsmode == 'modit' or xsmode == 'MODIT':
            cnu, indexnu, R_mol, pmarray = initspec.init_modit(
                mdb.nu_lines, self.nus)
            nsigmaDl = normalized_doppler_sigma(Tarr, self.molmass,
                                                R_mol)[:, np.newaxis]
            ngammaLM = gammaLM / (mdb.nu_lines / R_mol)
            dgm_ngammaL = modit.dgmatrix(ngammaLM, 0.1)
            xsm = modit.xsmatrix(cnu, indexnu, R_mol, pmarray, nsigmaDl,
                                 ngammaLM, SijM, self.nus, dgm_ngammaL)
            xsm = self.nonnegative_xsm(xsm)
        elif xsmode == 'dit' or xsmode == 'DIT':
            cnu, indexnu, pmarray = initspec.init_dit(mdb.nu_lines, self.nus)
            sigmaDM = jit(vmap(doppler_sigma,
                               (None, 0, None)))(mdb.nu_lines, Tarr,
                                                 self.molmass)
            dgm_sigmaD = dit.dgmatrix(sigmaDM, 0.1)
            dgm_gammaL = dit.dgmatrix(gammaLM, 0.2)
            xsm = dit.xsmatrix(cnu, indexnu, pmarray, sigmaDM, gammaLM, SijM,
                               self.nus, dgm_sigmaD, dgm_gammaL)
            xsm = self.nonnegative_xsm(xsm)
        else:
            print('No such xsmode=', xsmode)
            xsm = None

        return xsm
コード例 #8
0
ファイル: autospec.py プロジェクト: HajimeKawahara/exojax
    def xsection(self, T, P):
        """cross section.

        Args:
           T: temperature (K)
           P: pressure (bar)

        Returns:
           cross section (cm2)
        """

        mdb = self.mdb
        if self.database == 'ExoMol':
            gammaL = gamma_exomol(P, T, mdb.n_Texp,
                                  mdb.alpha_ref) + gamma_natural(mdb.A)
            molmass = mdb.molmass
        elif self.database == 'HITRAN' or self.database == 'HITEMP':
            gammaL = gamma_hitran(P, T, P, mdb.n_air, mdb.gamma_air,
                                  mdb.gamma_self) + gamma_natural(mdb.A)
            molmass = molinfo.molmass(self.molecules)

        Sij = self.linest(T)
        if self.xsmode == 'auto':
            xsmode = self.select_xsmode(len(mdb.nu_lines))
        else:
            xsmode = self.xsmode

        if xsmode == 'lpf' or xsmode == 'LPF':
            sigmaD = doppler_sigma(mdb.nu_lines, T, molmass)
            xsv = xsection(self.nus,
                           mdb.nu_lines,
                           sigmaD,
                           gammaL,
                           Sij,
                           memory_size=self.memory_size)
        elif xsmode == 'modit' or xsmode == 'MODIT':
            checknus = check_scale_nugrid(self.nus, gridmode='ESLOG')
            nus = self.autonus(checknus, 'ESLOG')
            cnu, indexnu, R_mol, pmarray = initspec.init_modit(
                mdb.nu_lines, nus)
            nsigmaD = normalized_doppler_sigma(T, molmass, R_mol)
            ngammaL = gammaL / (mdb.nu_lines / R_mol)
            ngammaL_grid = modit.ditgrid(ngammaL, res=0.1)
            xsv = modit.xsvector(cnu, indexnu, R_mol, pmarray, nsigmaD,
                                 ngammaL, Sij, nus, ngammaL_grid)
            if ~checknus and self.autogridconv:
                xsv = jnp.interp(self.nus, nus, xsv)
        elif xsmode == 'dit' or xsmode == 'DIT':
            sigmaD = doppler_sigma(mdb.nu_lines, T, molmass)
            checknus = check_scale_nugrid(self.nus, gridmode='ESLIN')
            nus = self.autonus(checknus, 'ESLIN')
            sigmaD_grid = dit.ditgrid(sigmaD, res=0.1)
            gammaL_grid = dit.ditgrid(gammaL, res=0.1)
            cnu, indexnu, pmarray = initspec.init_dit(mdb.nu_lines, nus)
            xsv = dit.xsvector(cnu, indexnu, pmarray, sigmaD, gammaL, Sij, nus,
                               sigmaD_grid, gammaL_grid)
            if ~checknus and self.autogridconv:
                xsv = jnp.interp(self.nus, nus, xsv)
        else:
            print('Error:', xsmode, ' is unavailable (auto/LPF/DIT).')
            xsv = None
        return xsv
コード例 #9
0
ファイル: coratio.py プロジェクト: HajimeKawahara/exojax
def Rpg(Mp, logg):
    #R from logg and M in MJ, RJ
    return np.sqrt(2478.58 * Mp / 10**logg)


def est(val, N=3):
    per = np.percentile(val, [5, 95])
    med = np.round(np.median(val), N)
    per0 = np.round(per[0] - med, N)
    per1 = np.round(per[1] - med, N)

    print(str(med) + '_{' + str(per0) + '}^{' + str(per1) + '}')


p = np.load("npz/savepos.npz", allow_pickle=True)["arr_0"][0]
mCO = molinfo.molmass("CO")  #molecular mass (CO)
mH2O = molinfo.molmass("H2O")  #molecular mass (CO)
T0 = p["T0"]
mmrCO = p["MMR_CO"]
mmrH2O = p["MMR_H2O"]
corat = (1.0 + (mCO * mmrH2O) / (mH2O * mmrCO))**-1
est(T0)
est(corat)
est(mmrCO, 4)
est(mmrH2O, 4)

#plt.hist(corat,bins=100)
#plt.savefig("coratio.pdf", bbox_inches="tight", pad_inches=0.0)
#plt.show()