<jupyter_start><jupyter_text>Utility functions The petitRADTRANS.nat_cst package contains some useful utility functions for generating spectra and observables, the use of which are shown below. It also contains useful constants, see [the nat_cst code documentation](../code_nat_cst.html). First we load the package:<jupyter_code>from petitRADTRANS import nat_cst as nc<jupyter_output><empty_output><jupyter_text>Planck function The planck function $B_\nu(T)$, in units of erg/cm$^2$/s/Hz/steradian, for a given frequency array, can be generated like this:<jupyter_code># Define wavelength array, in cm
lamb = np.logspace(-5,-2,100)
# Convert to frequencies
freq = nc.c / lamb
# Calculate Planck function at 5750 K
planck = nc.b(5750., freq)<jupyter_output><empty_output><jupyter_text>Let's plot the Planck function:<jupyter_code># Plot Planck function
import pylab as plt
plt.rcParams['figure.figsize'] = (10, 6)
plt.plot(lamb/1e-4, planck)
plt.xscale('log')
plt.xlabel('Wavelength (micron)')
plt.ylabel('Intensity (erg/cm$^2$/s/Hz/sterad)')
plt.show()
plt.clf()<jupyter_output><empty_output><jupyter_text>PHOENIX and ATLAS9 stellar model spectra Within petitRADTRANS the PHOENIX and ATLAS9 stellar spectra can be used, as described in Appendix A of [van Boekel et al. (2012)](http://adsabs.harvard.edu/abs/2012SPIE.8442E..1FV). The PHOENIX model refrence, for stellar effective temperatures  10,000 K are Kurucz [(1979](http://adsabs.harvard.edu/abs/1979ApJS...40....1K), [1992](http://adsabs.harvard.edu/abs/1992IAUS..149..225K), [1994)](http://adsabs.harvard.edu/abs/1994KurCD..19.....K). The models can be acessed like this, this is for a 5750 K effective temperature star on the main sequence:<jupyter_code>stellar_spec = nc.get_PHOENIX_spec(5750)
wlen_in_cm = stellar_spec[:,0]
flux_star = stellar_spec[:,1]<jupyter_output><empty_output><jupyter_text>Let's plot the spectrum, and also overplot the black body flux from the previous section (note the required factor of $\pi$ to convert the black body intensity to flux):<jupyter_code>import pylab as plt
plt.plot(wlen_in_cm/1e-4, flux_star, label = 'PHOENIX model')
plt.plot(lamb/1e-4, np.pi*planck, label = 'black body flux')
plt.title(r'$T_{\rm eff}=5750$ K')
plt.xscale('log')
plt.xlabel('Wavelength (micron)')
plt.ylabel('Surface flux (erg/cm$^2$/s/Hz/sterad)')
plt.legend(loc = 'best', frameon = False)
plt.show()
plt.clf()<jupyter_output><empty_output><jupyter_text>Guillot temperature model In petitRADTRANS, one can use 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}$ the atmospheric opacity in the IR wavelengths (i.e. the cross-section per unit mass), $g$ the atmospheric surface gravity, $\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. Let's define an example, all units are cgs units, except for the pressure, which is in bars:<jupyter_code>kappa_IR = 0.01
gamma = 0.4
T_int = 200.
T_equ = 1500.
gravity = 1e1**2.45

pressures = np.logspace(-6, 2, 100)

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>
{'fraction_non_alphanumeric': 0.14908136482939632, 'fraction_numerical': 0.04041994750656168, 'mean_word_length': 5.805357142857143, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '400526', 'license': 'MIT', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1347, 'n_words': 358, 'path': 'docs/content/notebooks/nat_cst_utility.ipynb', 'repo_name': 'nborsato/petitRADTRANS', 'size': '3810'}