<jupyter_start><jupyter_text>Getting Started  Preparing a radiative transfer object After installation has finished, let's try to calculate a first spectrum!You can simply load petitRADTRANS by typing:<jupyter_code>import numpy as np
from petitRADTRANS import Radtrans<jupyter_output><empty_output><jupyter_text>An instance of a radiative transfer object can then be created like this:<jupyter_code>atmosphere = Radtrans(line_species = ['H2O', 'CO_all_iso', 'CH4', 'CO2', 'Na', 'K'], \
      rayleigh_species = ['H2', 'He'], \
      continuum_opacities = ['H2-H2', 'H2-He'], \
      wlen_bords_micron = [0.3, 15])<jupyter_output>Read CIA opacities for H2-H2...
  Read CIA opacities for H2-He...
 Done.<jupyter_text>This will create an object ready to calculate spectra once the atmospheric parameters (temperature, abundances, mean molecular weight etc.) are set. Here we asked for the following molecular or atomic line absorbers to be inlcuded: $\rm H_2O$, $\rm CO$,  $\rm CH_4$, $\rm CO_2$, $\rm Na$, and $\rm K$. Additionally, the Rayleigh scattering cross-sections for $\rm H_2$ and $\rm He$ were loaded, as well as the collision induced absorption (CIA) cross-sections for the $\rm H_2$-$\rm H_2$ and $\rm H_2$-$\rm He$ pairs. The wavelength range that was loaded for the opacities here extends from 0.3 to 15 microns. Now, let's define the pressures of the atmospheric layers.Note that the pressures **must** always be sorted in increasing order, and be equidistant in log-space. The pressure is in units of **bar**, although all other units in *petitRADTRANS* are in cgs. Typically include of the order of 100 layers in your computations:<jupyter_code>pressures = np.logspace(-6, 2, 100)<jupyter_output><empty_output><jupyter_text>**Units in petitRADTRANS:** all units in *petitRADTRANS* are in cgs, **except for pressure**, which is in bars, **and the mean molecular weight (MMW)**, which is in units of atomic mass units.<jupyter_code>atmosphere.setup_opa_structure(pressures)<jupyter_output><empty_output><jupyter_text>And we are done! These steps only need to be carried out once, after this we are free to play with this radiative transfer object, for example change the temperature, abundances, etc. Only if additional opacity species need to be loaded is it necessary to create a new Radtrans instance.  Calculating a transmission spectrum Let's calculate a first spectrum for a hot Jupiter, first in transmission. Let's assume an isothermal temperature profile, for now. We start by specifing the temperature array, and abundance dictionery, containing the mass fractions of the atmospheric material, at every layer, and the atmospheric mean molecular weight, at every layer, in units of amu:<jupyter_code>temperature = 1200. * np.ones_like(pressures)

mass_fractions = {}
mass_fractions['H2'] = 0.74 * np.ones_like(temperature)
mass_fractions['He'] = 0.24 * np.ones_like(temperature)
mass_fractions['H2O'] = 0.001 * np.ones_like(temperature)
mass_fractions['CO_all_iso'] = 0.01 * np.ones_like(temperature)
mass_fractions['CO2'] = 0.00001 * np.ones_like(temperature)
mass_fractions['CH4'] = 0.000001 * np.ones_like(temperature)
mass_fractions['Na'] = 0.00001 * np.ones_like(temperature)
mass_fractions['K'] = 0.000001 * np.ones_like(temperature)

MMW = 2.33 * np.ones_like(temperature)<jupyter_output><empty_output><jupyter_text>**Note that these are freely made up values, however. The P-T profile of a real planet may well be different, and not isothermal. Also the abundances are just made up for this simple example here** (see ["Interpolating chemical equilibrium abundances"](poor_man.html) for how to improve this.) **Abundances in petitRADTRANS:** abundances in pRT are in units of **mass fractions**, not number fractions (aka volume mixing ratio, VMR). You can convert between mass fractions and VMRs by using\begin{equation}X_i = \frac{\mu_i}{\mu}n_i,\end{equation}where $X_i$ is the mass fraction of species $i$, $\mu_i$ the mass of a single molecule/atom/ion/... of species $i$, $\mu$ is the atmospheric mean molecular weight, and $n_i$ is the VMR of species $i$. Next, let's assume a planetary radius and gravity at a given pressure $P_0=0.01$ bar in the atmosphere, and we are all set!<jupyter_code>from petitRADTRANS import nat_cst as nc
R_pl = 1.838*nc.r_jup_mean
gravity = 1e1**2.45
P0 = 0.01<jupyter_output><empty_output><jupyter_text>Now we simply generate a transmission spectrum by typing:<jupyter_code>atmosphere.calc_transm(temperature, mass_fractions, gravity, MMW, R_pl=R_pl, P0_bar=P0)<jupyter_output><empty_output><jupyter_text>Let's plot the transit radius!<jupyter_code>import pylab as plt
plt.rcParams['figure.figsize'] = (10, 6)

plt.plot(nc.c/atmosphere.freq/1e-4, atmosphere.transm_rad/nc.r_jup_mean)

plt.xscale('log')
plt.xlabel('Wavelength (microns)')
plt.ylabel(r'Transit radius ($\rm R_{Jup}$)')
plt.show()
plt.clf()<jupyter_output><empty_output><jupyter_text>Calculating an emission spectrum **Scattering and petitRADTRANS:** scattering is included for emission spectra in petitRADTRANS only if requested specifically when generating the Radtrans object, as it increases the runtime (see ["Scattering for Emission Spectra"](emis_scat.html) for an example how to do this). We neglect the scattering here. Let's calculate an emission spectrum. Using an isothermal temperature structure as above would simply result in a black body spectrum:<jupyter_code>atmosphere.calc_flux(temperature, mass_fractions, gravity, MMW)

plt.plot(nc.c/atmosphere.freq/1e-4, atmosphere.flux/1e-6)

plt.xscale('log')
plt.xlabel('Wavelength (microns)')
plt.ylabel(r'Planet flux $F_\nu$ (10$^{-6}$ erg cm$^{-2}$ s$^{-1}$ Hz$^{-1}$)')
plt.show()
plt.clf()<jupyter_output><empty_output><jupyter_text>So let's try something different instead, namely the often-used analytical atmospheric P-T profile from [Guillot (2010)](http://adsabs.harvard.edu/abs/2010A%26A...520A..27G), his Equation 29: \begin{equation}T^4 = \frac{3T_{\rm int}^4}{4}\left(\frac{2}{3}+\tau\right) + \frac{3T_{\rm equ}^4}{4}\left[\frac{2}{3}+\frac{1}{\gamma\sqrt{3}}+\left(\frac{\gamma}{\sqrt{3}}-\frac{1}{\gamma\sqrt{3}}\right)e^{-\gamma\tau\sqrt{3}}\right]\end{equation} with $\tau = P\kappa_{\rm IR}/g$. Here, $\tau$ is the optical depth, $P$ the pressure, $\kappa_{\rm IR}$ is the atmospheric opacity in the IR wavelengths (i.e. the cross-section per unit mass), $\gamma$ is the ratio between the optical and IR opacity, $T_{\rm equ}$ the atmospheric equilibrium temperature, and $T_{\rm int}$ is the planetary internal temperature.<jupyter_code>kappa_IR = 0.01
gamma = 0.4
T_int = 200.
T_equ = 1500.

temperature = nc.guillot_global(pressures, kappa_IR, gamma, gravity, T_int, T_equ)<jupyter_output><empty_output><jupyter_text>Let's plot the P-T profile:<jupyter_code>plt.plot(temperature, pressures)
plt.yscale('log')
plt.ylim([1e2, 1e-6])
plt.xlabel('T (K)')
plt.ylabel('P (bar)')
plt.show()
plt.clf()<jupyter_output><empty_output><jupyter_text>An recalculate the spectrum:<jupyter_code>atmosphere.calc_flux(temperature, mass_fractions, gravity, MMW)

plt.plot(nc.c/atmosphere.freq/1e-4, atmosphere.flux/1e-6)

plt.xscale('log')
plt.xlabel('Wavelength (microns)')
plt.ylabel(r'Planet flux $F_\nu$ (10$^{-6}$ erg cm$^{-2}$ s$^{-1}$ Hz$^{-1}$)')
plt.show()
plt.clf()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12643835616438356, 'fraction_numerical': 0.024246575342465753, 'mean_word_length': 5.810634328358209, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '128614', 'license': 'MIT', 'n_tokens_mistral': 2576, 'n_tokens_neox': 2357, 'n_words': 768, 'path': 'docs/content/notebooks/getting_started.ipynb', 'repo_name': 'nborsato/petitRADTRANS', 'size': '7300'}