Opacity-grid Tutorial

To speed up the spectrum calculations, the Pyrat Bay can compute cross-section tables that sample the LBL opacities over a pressure, temperature, and wavenumber grid. This is particularly useful when planning to model several spectra, and is required for MCMC runs.

Sample Configuration File

Here is an example of an opacity-table configuration file (opacity.cfg):

[pyrat]

# Pyrat Bay run mode, select from: [tli atmosphere spectrum opacity mcmc]
runmode = opacity

# Atmospheric model:
atmfile  = WASP-00b.atm

# Wavelength sampling boundaries:
wllow  =  1.0 um
wlhigh =  5.0 um
# Wavenumber sampling rate and oversampling factor:
wnstep  = 1.0
wnosamp = 2160

# TLI opacity files:
tlifile = ./HITRAN_H2O_0.3-5.0um.tli

# Opacity file name:
extfile = ./exttable_100-3000K_1.0-5.0um.npz
# Opacity-grid temperature boundaries, and sampling rate (in Kelvin degrees):
tmin  =  100
tmax  = 3000
tstep =  100

# Number of CPUs for parallel processing:
ncpu = 7

# Verbosity level (<0:errors, 0:warnings, 1:headlines, 2:details, 3:debug):
verb = 2

The exttable key sets the name of the opacity table (which is stored as a Numpy npz file, thus, the file must have a .npz extension). The tmin, tmax, and tstep keys set the boundaries and sampling rate of the temperature grid. The pressure grid will be taken from the atmospheric model, and the wavenumber grid will be taken from the wavelength/wavenumber keys in the configuration file.

The tlifile key determines the LBL opacities to include in the opacity table. Note that one can include opacities from multiple species into a single opacity table.

Once this opacity table is created, runs that generate spectra will interpolate from this table to compute extinction coefficients, which is much faster than rather than the LBL calculations.

Opacity Table as Input/output

Depending on the runmode, whether extfile is set in the configuration file, and whether the extinction file already exists, Pyrat Bay will operate differently. The following table describes what the code will output:

runmode

extfile

File exists

Output

opacity

defined

No

Generate new opacity table

defined

Yes

Overwrite existing opacity table

undefined

Error

spectrum

defined

Yes

Use existing table to compute spectrum

defined

No

Generate grid and compute spectrum

undefined

LBL-opacity spectrum calculation

mcmc

defined

Same as runmode = spectrum

undefined

Error

Note

When the opacity table is an output, the configuration file must specify a single file for extfile (which may contain opacity for multiple species though). However, when the opacity table is an input, the extfile may contain multiple opacity tables (as long as all of them use the same pressure, temperature, and wavenumber gridding).

Examples

Note

Before running this example, make sure that you have generated the TLI file from the TLI Example, generated the atmospheric profiles from the Abundance-profile Examples, and download the configuration file shown above, e.g., with these shell commands:

tutorial_path=https://raw.githubusercontent.com/pcubillos/pyratbay/master/examples/tutorial
wget $tutorial_path/opacity.cfg

As in a spectrum run, an opacity run returns a ‘pyrat’ object in an interactive run. The following Python script computes an opacity file using the configuration file found at the top of this tutorial:

import pyratbay as pb

pyrat = pb.run('opacity.cfg')