Skip to content

Commit

Permalink
index.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
HajimeKawahara committed Oct 5, 2024
1 parent 4694611 commit 0c3cfce
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 60 deletions.
7 changes: 4 additions & 3 deletions documents/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ References
`ApJS 258, 31 (2022) <https://iopscience.iop.org/article/10.3847/1538-4365/ac3b4d>`_
(Paper I)

- Kawahara et al., 2024, in prep. (Paper II)


License & Attribution
---------------------

Copyright 2021-2023, Contributors
Copyright 2021-2024, Contributors

- `Hajime Kawahara <http://secondearths.sakura.ne.jp/en/index.html>`_ (@HajimeKawahara, maintainer)
- `Yui Kawashima <https://sites.google.com/view/yuikawashima/home>`_ (@ykawashima, co-maintainer)
Expand All @@ -85,11 +85,12 @@ Copyright 2021-2023, Contributors
- Dirk van den Bekerom (@dcmvdbekerom)
- Daniel Kitzmann (@daniel-kitzmann)
- Brett Morris (@bmorris3)
- Erwan Pannier (@erwanp) and `RADIS <https://github.com/radis/radis>`_ community
- Erwan Pannier (@erwanp) and Nicolas Minesi (@minouHub) from `RADIS <https://github.com/radis/radis>`_ community
- Stevanus Nugroho (@astrostevanus)
- Tako Ishikawa (@chonma0ctopus)
- Yui Kasagi (@YuiKasagi)
- Shotaro Tada (@sh-tada)
- Ko Hosokawa (@KoHosokawa)

ExoJAX is free software made available under the MIT License. See the ``LICENSE``.

118 changes: 61 additions & 57 deletions tests/endtoend/reverse/reverse_premodit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Reverse modeling of Methane emission spectrum using MODIT
""" Reverse modeling of Methane emission spectrum using PreMODIT
"""

#!/usr/bin/env python
# coding: utf-8
import numpy as np
Expand Down Expand Up @@ -40,53 +41,57 @@

# loading the data
filename = pkg_resources.resource_filename(
'exojax', 'data/testdata/' + SAMPLE_SPECTRA_CH4_NEW)
"exojax", "data/testdata/" + SAMPLE_SPECTRA_CH4_NEW
)
dat = pd.read_csv(filename, delimiter=",", names=("wavenumber", "flux"))
nusd = dat['wavenumber'].values
flux = dat['flux'].values
nusd = dat["wavenumber"].values
flux = dat["flux"].values
wavd = nu2wav(nusd, wavelength_order="ascending")

sigmain = 0.05
norm = 20000
nflux = flux / norm + np.random.normal(0, sigmain, len(wavd))

Nx = 7500
nu_grid, wav, res = wavenumber_grid(np.min(wavd) - 10.0,
np.max(wavd) + 10.0,
Nx,
unit='AA',
xsmode='premodit', wavelength_order="ascending")
nu_grid, wav, res = wavenumber_grid(
np.min(wavd) - 10.0,
np.max(wavd) + 10.0,
Nx,
unit="AA",
xsmode="premodit",
wavelength_order="ascending",
)

Tlow = 400.0
Thigh = 1500.0
art = ArtEmisPure(nu_grid, pressure_top=1.e-8, pressure_btm=1.e2, nlayer=100)
art = ArtEmisPure(nu_grid, pressure_top=1.0e-8, pressure_btm=1.0e2, nlayer=100)
art.change_temperature_range(Tlow, Thigh)
Mp = 33.2

Rinst = 100000.
Rinst = 100000.0
beta_inst = resolution_to_gaussian_std(Rinst)

### CH4 setting (PREMODIT)
mdb = MdbExomol('.database/CH4/12C-1H4/YT10to10/',
nurange=nu_grid,
gpu_transfer=False)
print('N=', len(mdb.nu_lines))
mdb = MdbExomol(".database/CH4/12C-1H4/YT10to10/", nurange=nu_grid, gpu_transfer=False)
print("N=", len(mdb.nu_lines))
diffmode = 0
opa = OpaPremodit(mdb=mdb,
nu_grid=nu_grid,
diffmode=diffmode,
auto_trange=[Tlow, Thigh],
dit_grid_resolution=0.2)
opa = OpaPremodit(
mdb=mdb,
nu_grid=nu_grid,
diffmode=diffmode,
auto_trange=[Tlow, Thigh],
dit_grid_resolution=0.2,
)

## CIA setting
cdbH2H2 = CdbCIA('.database/H2-H2_2011.cia', nu_grid)
cdbH2H2 = CdbCIA(".database/H2-H2_2011.cia", nu_grid)
opcia = OpaCIA(cdb=cdbH2H2, nu_grid=nu_grid)
mmw = 2.33 # mean molecular weight
mmrH2 = 0.74
molmassH2 = molinfo.molmass_isotope('H2')
vmrH2 = (mmrH2 * mmw / molmassH2) # VMR
molmassH2 = molinfo.molmass_isotope("H2")
vmrH2 = mmrH2 * mmw / molmassH2 # VMR

#settings before HMC
# settings before HMC
vsini_max = 100.0
vr_array = velocity_grid(res, vsini_max)

Expand All @@ -95,15 +100,14 @@

def frun(Tarr, MMR_CH4, Mp, Rp, u1, u2, RV, vsini):
g = gravity_jupiter(Rp=Rp, Mp=Mp) # gravity in the unit of Jupiter
#molecule
# molecule
xsmatrix = opa.xsmatrix(Tarr, art.pressure)
mmr_arr = art.constant_mmr_profile(MMR_CH4)
dtaumCH4 = art.opacity_profile_xs(xsmatrix, mmr_arr, opa.mdb.molmass, g)
#continuum
# continuum
logacia_matrix = opcia.logacia_matrix(Tarr)
dtaucH2H2 = art.opacity_profile_cia(logacia_matrix, Tarr, vmrH2, vmrH2,
mmw, g)
#total tau
dtaucH2H2 = art.opacity_profile_cia(logacia_matrix, Tarr, vmrH2, vmrH2, mmw, g)
# total tau
dtau = dtaumCH4 + dtaucH2H2
F0 = art.run(dtau, Tarr) / norm
Frot = convolve_rigid_rotation(F0, vr_array, vsini, u1, u2)
Expand All @@ -112,7 +116,8 @@ def frun(Tarr, MMR_CH4, Mp, Rp, u1, u2, RV, vsini):


import matplotlib.pyplot as plt
#g = gravity_jupiter(0.88, 33.2)

# g = gravity_jupiter(0.88, 33.2)
Rp = 0.88
Mp = 33.2
alpha = 0.1
Expand All @@ -136,23 +141,23 @@ def frun(Tarr, MMR_CH4, Mp, Rp, u1, u2, RV, vsini):


def model_c(y1):
Rp = numpyro.sample('Rp', dist.Uniform(0.4, 1.2))
RV = numpyro.sample('RV', dist.Uniform(5.0, 15.0))
MMR_CH4 = numpyro.sample('MMR_CH4', dist.Uniform(0.0, 0.015))
T0 = numpyro.sample('T0', dist.Uniform(1000.0, 1500.0))
alpha = numpyro.sample('alpha', dist.Uniform(0.05, 0.2))
vsini = numpyro.sample('vsini', dist.Uniform(15.0, 25.0))
Rp = numpyro.sample("Rp", dist.Uniform(0.4, 1.2))
RV = numpyro.sample("RV", dist.Uniform(5.0, 15.0))
MMR_CH4 = numpyro.sample("MMR_CH4", dist.Uniform(0.0, 0.015))
T0 = numpyro.sample("T0", dist.Uniform(1000.0, 1500.0))
alpha = numpyro.sample("alpha", dist.Uniform(0.05, 0.2))
vsini = numpyro.sample("vsini", dist.Uniform(15.0, 25.0))
u1 = 0.0
u2 = 0.0
Tarr = art.powerlaw_temperature(T0, alpha)
mu = frun(Tarr, MMR_CH4, Mp, Rp, u1, u2, RV, vsini)
numpyro.sample('y1', dist.Normal(mu, sigmain), obs=y1)
numpyro.sample("y1", dist.Normal(mu, sigmain), obs=y1)


rng_key = random.PRNGKey(0)
rng_key, rng_key_ = random.split(rng_key)
num_warmup, num_samples = 500, 1000
#kernel = NUTS(model_c, forward_mode_differentiation=True)
# kernel = NUTS(model_c, forward_mode_differentiation=True)
kernel = NUTS(model_c, forward_mode_differentiation=False)

mcmc = MCMC(kernel, num_warmup=num_warmup, num_samples=num_samples)
Expand All @@ -161,32 +166,31 @@ def model_c(y1):

# SAMPLING
posterior_sample = mcmc.get_samples()
pred = Predictive(model_c, posterior_sample, return_sites=['y1'])
pred = Predictive(model_c, posterior_sample, return_sites=["y1"])
predictions = pred(rng_key_, y1=None)
median_mu1 = jnp.median(predictions['y1'], axis=0)
hpdi_mu1 = hpdi(predictions['y1'], 0.9)
median_mu1 = jnp.median(predictions["y1"], axis=0)
hpdi_mu1 = hpdi(predictions["y1"], 0.9)

# PLOT
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(20, 6.0))
ax.plot(wavd[::-1], median_mu1, color='C0')
ax.plot(wavd[::-1], nflux, '+', color='black', label='data')
ax.fill_between(wavd[::-1],
hpdi_mu1[0],
hpdi_mu1[1],
alpha=0.3,
interpolate=True,
color='C0',
label='90% area')
plt.xlabel('wavelength ($\AA$)', fontsize=16)
ax.plot(wavd[::-1], median_mu1, color="C0")
ax.plot(wavd[::-1], nflux, "+", color="black", label="data")
ax.fill_between(
wavd[::-1],
hpdi_mu1[0],
hpdi_mu1[1],
alpha=0.3,
interpolate=True,
color="C0",
label="90% area",
)
plt.xlabel("wavelength ($\AA$)", fontsize=16)
plt.legend(fontsize=16)
plt.tick_params(labelsize=16)
plt.savefig("pred_diffmode" + str(diffmode) + ".png")
plt.close()

pararr = ['Rp', 'T0', 'alpha', 'MMR_CH4', 'vsini', 'RV']
arviz.plot_pair(arviz.from_numpyro(mcmc),
kind='kde',
divergences=False,
marginals=True)
pararr = ["Rp", "T0", "alpha", "MMR_CH4", "vsini", "RV"]
arviz.plot_pair(arviz.from_numpyro(mcmc), kind="kde", divergences=False, marginals=True)
plt.savefig("corner_diffmode" + str(diffmode) + ".png")
#plt.show()
# plt.show()

0 comments on commit 0c3cfce

Please sign in to comment.