petitRADTRANS.radtrans
¶
Module Contents¶
Classes¶
Class defining objects for carrying out spectral calculations for a 
Functions¶

" 
 class petitRADTRANS.radtrans.Radtrans(line_species=None, rayleigh_species=None, cloud_species=None, continuum_opacities=None, wlen_bords_micron=None, mode='ck', test_ck_shuffle_comp=False, do_scat_emis=False, lbl_opacity_sampling=None, pressures=None, temperatures=None, stellar_intensity=None, geometry='dayside_ave', mu_star=1.0, semimajoraxis=None, hack_cloud_photospheric_tau=None, path_input_data=os.environ.get('pRT_input_data_path'))¶
Bases:
petitRADTRANS._read_opacities.ReadOpacities
Class defining objects for carrying out spectral calculations for a given set of opacities
 Args:
 line_species (Optional):
list of strings, denoting which line absorber species to include.
 rayleigh_species (Optional):
list of strings, denoting which Rayleigh scattering species to include.
 cloud_species (Optional):
list of strings, denoting which cloud opacity species to include.
 continuum_opacities (Optional):
list of strings, denoting which continuum absorber species to include.
 wlen_bords_micron (Optional):
list containing left and right border of wavelength region to be considered, in micron. If nothing else is specified, it will be equal to
[0.05, 300]
, hence using the full petitRADTRANS wavelength range (0.11 to 250 microns for'ck'
mode, 0.3 to 30 microns for the'lbl'
mode). The larger the range the longer the computation time. mode (Optional[string]):
if equal to
'ck'
: use lowresolution mode, at \(\\lambda/\\Delta \\lambda = 1000\), with the correlatedk assumption. if equal to'lbl'
: use highresolution mode, at \(\\lambda/\\Delta \\lambda = 10^6\), with a linebyline treatment. do_scat_emis (Optional[bool]):
Will be
False
by default. IfTrue
scattering will be included in the emission spectral calculations. Note that this increases the runtime of pRT! lbl_opacity_sampling (Optional[int]):
Will be
None
by default. If integer positive value, and ifmode == 'lbl'
isTrue
, then this will only consider every lbl_opacity_samplingnth point of the highresolution opacities. This may be desired in the case where mediumresolution spectra are required with a \(\\lambda/\\Delta \\lambda > 1000\), but much smaller than \(10^6\), which is the resolution of thelbl
mode. In this case it may make sense to carry out the calculations with lbl_opacity_sampling = 10, for example, and then rebinning to the final desired resolution: this may save time! The user should verify whether this leads to solutions which are identical to the rebinned results of the fiducial \(10^6\) resolution. If not, this parameter must not be used.
 _check_cloud_effect(mass_mixing_ratios)¶
Check if the clouds have any effect, i.e. if the MMR is greater than 0.
 Args:
mass_mixing_ratios: atmospheric mass mixing ratios
Returns:
 _init_line_opacities_parameters()¶
 _init_pressure_dependent_parameters(pressures)¶
Setup opacity arrays at atmospheric structure dimensions, and set the atmospheric pressure array.
 Args:
 pressures:
the atmospheric pressure (1d numpy array, sorted in increasing order), in units of bar. Will be converted to cgs internally.
 static calc_borders(x)¶
 setup_opa_structure(P)¶
Setup opacity arrays at atmospheric structure dimensions, and set the atmospheric pressure array.
 Args:
 P:
the atmospheric pressure (1d numpy array, sorted in increasing order), in units of bar. Will be converted to cgs internally.
 interpolate_species_opa(temp)¶
 interpolate_cia(key, mfrac)¶
 mix_opa_tot(abundances, mmw, gravity, sigma_lnorm=None, fsed=None, Kzz=None, radius=None, add_cloud_scat_as_abs=None, dist='lognormal', a_hans=None, b_hans=None, give_absorption_opacity=None, give_scattering_opacity=None)¶
 calc_cloud_opacity(abundances, mmw, gravity, sigma_lnorm, fsed=None, Kzz=None, radius=None, add_cloud_scat_as_abs=None, dist='lognormal', a_hans=None, b_hans=None)¶
 add_rayleigh(abundances)¶
 calc_opt_depth(gravity, cloud_wlen=None)¶
 calc_RT(contribution)¶
Calculate the flux.
 calc_tr_rad(P0_bar, R_pl, gravity, mmw, contribution, variable_gravity)¶
 calc_flux(temp, abunds, gravity, mmw, R_pl=None, sigma_lnorm=None, fsed=None, Kzz=None, radius=None, contribution=False, gray_opacity=None, Pcloud=None, kappa_zero=None, gamma_scat=None, add_cloud_scat_as_abs=None, Tstar=None, Rstar=None, semimajoraxis=None, geometry='dayside_ave', theta_star=0, hack_cloud_photospheric_tau=None, dist='lognormal', a_hans=None, b_hans=None, stellar_intensity=None, give_absorption_opacity=None, give_scattering_opacity=None, cloud_wlen=None)¶
Method to calculate the atmosphere’s emitted flux (emission spectrum).
 Args:
 temp:
the atmospheric temperature in K, at each atmospheric layer (1d numpy array, same length as pressure array).
 abunds:
dictionary of mass fractions for all atmospheric absorbers. Dictionary keys are the species names. Every mass fraction array has same length as pressure array.
 gravity (float):
Surface gravity in cgs. Vertically constant for emission spectra.
 mmw:
the atmospheric mean molecular weight in amu, at each atmospheric layer (1d numpy array, same length as pressure array).
 R_pl: planet radius at maximum pressure in cm. If specified, the planet’s changing photospheric radius
as function of wavelength will be calculated and saved in the self.phot_radius attribute (in cm).
 sigma_lnorm (Optional[float]):
width of the lognormal cloud particle size distribution
 fsed (Optional[float]):
cloud settling parameter
 Kzz (Optional):
the atmospheric eddy diffusion coeffiecient in cgs untis (i.e. \(\rm cm^2/s\)), at each atmospheric layer (1d numpy array, same length as pressure array).
 radius (Optional):
dictionary of mean particle radii for all cloud species. Dictionary keys are the cloud species names. Every radius array has same length as pressure array.
 contribution (Optional[bool]):
If
True
the emission contribution function will be calculated. Default isFalse
. gray_opacity (Optional[float]):
Gray opacity value, to be added to the opacity at all pressures and wavelengths (units \(\rm cm^2/g\))
 Pcloud (Optional[float]):
Pressure, in bar, where opaque cloud deck is added to the absorption opacity.
 kappa_zero (Optional[float]):
Scattering opacity at 0.35 micron, in cgs units (cm^2/g).
 gamma_scat (Optional[float]):
Has to be given if kappa_zero is definded, this is the wavelength powerlaw index of the parametrized scattering opacity.
 add_cloud_scat_as_abs (Optional[bool]):
If
True
, 20 % of the cloud scattering opacity will be added to the absorption opacity, introduced to test for the effect of neglecting scattering. Tstar (Optional[float]):
The temperature of the host star in K, used only if the scattering is considered. If not specified, the direct light contribution is not calculated.
 Rstar (Optional[float]):
The radius of the star in cm. If specified, used to scale the to scale the stellar flux, otherwise it uses PHOENIX radius.
 semimajoraxis (Optional[float]):
The distance of the planet from the star. Used to scale the stellar flux when the scattering of the direct light is considered.
 geometry (Optional[string]):
if equal to
'dayside_ave'
: use the dayside average geometry. if equal to'planetary_ave'
: use the planetary average geometry. if equal to'nonisotropic'
: use the nonisotropic geometry. theta_star (Optional[float]):
Inclination angle of the direct light with respect to the normal to the atmosphere. Used only in the nonisotropic geometry scenario.
 hack_cloud_photospheric_tau (Optional[float]):
Median optical depth (across
wlen_bords_micron
) of the clouds from the top of the atmosphere down to the gasonly photosphere. This parameter can be used for enforcing the presence of clouds in the photospheric region. dist (Optional[string]):
The cloud particle size distribution to use. Can be either ‘lognormal’ (default) or ‘hansen’. If hansen, the b_hans parameters must be used.
 a_hans (Optional[dict]):
A dictionary of the ‘a’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. Equivilant to radius arg. If a_hans is not included and dist is “hansen”, then it will be computed using Kzz and fsed (recommended).
 b_hans (Optional[dict]):
A dictionary of the ‘b’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. This is the width of the hansen distribution normalized by the particle area (1/a_hans^2)
 give_absorption_opacity (Optional[function]):
A python function that takes wavelength arrays in microns and pressure arrays in bars as input, and returns an absorption opacity matrix in units of cm^2/g, in the shape of number of wavelength points x number of pressure points. This opacity will then be added to the atmospheric absorption opacity. This must not be used to add atomic / molecular line opacities in lowresolution mode (ck), because line opacities require a proper correlatedk treatment. It may be used to add simple cloud absorption laws, for example, which have opacities that vary only slowly with wavelength, such that the current model resolution is sufficient to resolve any variations.
 stellar_intensity (Optional[array]):
The stellar intensity to use. If None, it will be calculated using a PHOENIX model.
 give_scattering_opacity (Optional[function]):
A python function that takes wavelength arrays in microns and pressure arrays in bars as input, and returns an isotropic scattering opacity matrix in units of cm^2/g, in the shape of number of wavelength points x number of pressure points. This opacity will then be added to the atmospheric absorption opacity. It may be used to add simple cloud absorption laws, for example, which have opacities that vary only slowly with wavelength, such that the current model resolution is sufficient to resolve any variations.
 cloud_wlen (Optional[Tuple[float, float]]):
Tuple with the wavelength range (in micron) that is used for calculating the median optical depth of the clouds at gasonly photosphere and then scaling the cloud optical depth to the value of
hack_cloud_photospheric_tau
. The range ofcloud_wlen
should be encompassed bywlen_bords_micron
. The full wavelength range is used whencloud_wlen=None
.
 get_star_spectrum(Tstar, distance, Rstar=None)¶
Method to get the PHOENIX spectrum of the star and rebin it to the wavelength points. If Tstar is not explicitly written, the spectrum will be 0. If the distance is not explicitly written, the code will raise an error and break to urge the user to specify the value.
 Args:
 Tstar (float):
the stellar temperature in K.
 distance (float):
the semimajor axis of the planet in cm.
 Rstar (float):
if specified, uses this radius in cm to scale the flux, otherwise it uses PHOENIX radius.
 calc_transm(temp, abunds, gravity, mmw, P0_bar, R_pl, sigma_lnorm=None, fsed=None, Kzz=None, radius=None, Pcloud=None, kappa_zero=None, gamma_scat=None, contribution=False, haze_factor=None, gray_opacity=None, variable_gravity=True, dist='lognormal', b_hans=None, a_hans=None, give_absorption_opacity=None, give_scattering_opacity=None)¶
Method to calculate the atmosphere’s transmission radius (for the transmission spectrum).
 Args:
 temp:
the atmospheric temperature in K, at each atmospheric layer (1d numpy array, same length as pressure array).
 abunds:
dictionary of mass fractions for all atmospheric absorbers. Dictionary keys are the species names. Every mass fraction array has same length as pressure array.
 gravity (float):
Surface gravity in cgs at reference radius and pressure.
 mmw:
the atmospheric mean molecular weight in amu, at each atmospheric layer (1d numpy array, same length as pressure array).
 P0_bar (float):
Reference pressure P0 in bar where R(P=P0) = R_pl, where R_pl is the reference radius (parameter of this method), and g(P=P0) = gravity, where gravity is the reference gravity (parameter of this method)
 R_pl (float):
Reference radius R_pl, in cm.
 sigma_lnorm (Optional[float]):
width of the lognormal cloud particle size distribution
 fsed (Optional[float]):
cloud settling parameter
 Kzz (Optional):
the atmospheric eddy diffusion coeffiecient in cgs untis (i.e. \(\rm cm^2/s\)), at each atmospheric layer (1d numpy array, same length as pressure array).
 radius (Optional):
dictionary of mean particle radii for all cloud species. Dictionary keys are the cloud species names. Every radius array has same length as pressure array.
 contribution (Optional[bool]):
If
True
the transmission and emission contribution function will be calculated. Default isFalse
. gray_opacity (Optional[float]):
Gray opacity value, to be added to the opacity at all pressures and wavelengths (units \(\rm cm^2/g\))
 Pcloud (Optional[float]):
Pressure, in bar, where opaque cloud deck is added to the absorption opacity.
 kappa_zero (Optional[float]):
Scarttering opacity at 0.35 micron, in cgs units (cm^2/g).
 gamma_scat (Optional[float]):
Has to be given if kappa_zero is definded, this is the wavelength powerlaw index of the parametrized scattering opacity.
 haze_factor (Optional[float]):
Scalar factor, increasing the gas Rayleigh scattering crosssection.
 variable_gravity (Optional[bool]):
Standard is
True
. IfFalse
the gravity will be constant as a function of pressure, during the transmission radius calculation. dist (Optional[string]):
The cloud particle size distribution to use. Can be either ‘lognormal’ (default) or ‘hansen’. If hansen, the b_hans parameters must be used.
 a_hans (Optional[dict]):
A dictionary of the ‘a’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. Equivilant to radius arg. If a_hans is not included and dist is “hansen”, then it will be computed using Kzz and fsed (recommended).
 b_hans (Optional[dict]):
A dictionary of the ‘b’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. This is the width of the hansen distribution normalized by the particle area (1/a_hans^2)
 give_absorption_opacity (Optional[function]):
A python function that takes wavelength arrays in microns and pressure arrays in bars as input, and returns an absorption opacity matrix in units of cm^2/g, in the shape of number of wavelength points x number of pressure points. This opacity will then be added to the atmospheric absorption opacity. This must not be used to add atomic / molecular line opacities in lowresolution mode (ck), because line opacities require a proper correlatedk treatment. It may be used to add simple cloud absorption laws, for example, which have opacities that vary only slowly with wavelength, such that the current model resolution is sufficient to resolve any variations.
 give_scattering_opacity (Optional[function]):
A python function that takes wavelength arrays in microns and pressure arrays in bars as input, and returns an isotropic scattering opacity matrix in units of cm^2/g, in the shape of number of wavelength points x number of pressure points. This opacity will then be added to the atmospheric absorption opacity. It may be used to add simple cloud absorption laws, for example, which have opacities that vary only slowly with wavelength, such that the current model resolution is sufficient to resolve any variations.
 calc_flux_transm(temp, abunds, gravity, mmw, P0_bar, R_pl, sigma_lnorm=None, fsed=None, Kzz=None, radius=None, Pcloud=None, kappa_zero=None, gamma_scat=None, contribution=False, gray_opacity=None, add_cloud_scat_as_abs=None, variable_gravity=True, dist='lognormal', b_hans=None, a_hans=None, give_absorption_opacity=None, give_scattering_opacity=None)¶
Method to calculate the atmosphere’s emission flux and transmission radius (for the transmission spectrum).
 Args:
 temp:
the atmospheric temperature in K, at each atmospheric layer (1d numpy array, same length as pressure array).
 abunds:
dictionary of mass fractions for all atmospheric absorbers. Dictionary keys are the species names. Every mass fraction array has same length as pressure array.
 gravity (float):
Surface gravity in cgs at reference radius and pressure, constant durng the emission spectrum calculation.
 mmw:
the atmospheric mean molecular weight in amu, at each atmospheric layer (1d numpy array, same length as pressure array).
 P0_bar (float):
Reference pressure P0 in bar where R(P=P0) = R_pl, where R_pl is the reference radius (parameter of this method), and g(P=P0) = gravity, where gravity is the reference gravity (parameter of this method)
 R_pl (float):
Reference radius R_pl, in cm.
 sigma_lnorm (Optional[float]):
width of the lognormal cloud particle size distribution
 fsed (Optional[float]):
cloud settling parameter
 Kzz (Optional):
the atmospheric eddy diffusion coeffiecient in cgs untis (i.e. \(\rm cm^2/s\)), at each atmospheric layer (1d numpy array, same length as pressure array).
 radius (Optional):
dictionary of mean particle radii for all cloud species. Dictionary keys are the cloud species names. Every radius array has same length as pressure array.
 contribution (Optional[bool]):
If
True
the transmission contribution function will be calculated. Default isFalse
. gray_opacity (Optional[float]):
Gray opacity value, to be added to the opacity at all pressures and wavelengths (units \(\rm cm^2/g\))
 Pcloud (Optional[float]):
Pressure, in bar, where opaque cloud deck is added to the absorption opacity.
 kappa_zero (Optional[float]):
Scarttering opacity at 0.35 micron, in cgs units (cm^2/g).
 gamma_scat (Optional[float]):
Has to be given if kappa_zero is definded, this is the wavelength powerlaw index of the parametrized scattering opacity.
 add_cloud_scat_as_abs (Optional[bool]):
If
True
, 20 % of the cloud scattering opacity will be added to the absorption opacity, introduced to test for the effect of neglecting scattering. variable_gravity (Optional[bool]):
Standard is
True
. IfFalse
the gravity will be constant as a function of pressure, during the transmission radius calculation. dist (Optional[string]):
The cloud particle size distribution to use. Can be either ‘lognormal’ (default) or ‘hansen’. If hansen, the b_hans parameters must be used.
 a_hans (Optional[dict]):
A dictionary of the ‘a’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. Equivilant to radius arg. If a_hans is not included and dist is “hansen”, then it will be computed using Kzz and fsed (recommended).
 b_hans (Optional[dict]):
A dictionary of the ‘b’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. This is the width of the hansen distribution normalized by the particle area (1/a_hans^2)
 give_absorption_opacity (Optional[function]):
A python function that takes wavelength arrays in microns and pressure arrays in bars as input, and returns an absorption opacity matrix in units of cm^2/g, in the shape of number of wavelength points x number of pressure points. This opacity will then be added to the atmospheric absorption opacity. This must not be used to add atomic / molecular line opacities in lowresolution mode (ck), because line opacities require a proper correlatedk treatment. It may be used to add simple cloud absorption laws, for example, which have opacities that vary only slowly with wavelength, such that the current model resolution is sufficient to resolve any variations.
 give_scattering_opacity (Optional[function]):
A python function that takes wavelength arrays in microns and pressure arrays in bars as input, and returns an isotropic scattering opacity matrix in units of cm^2/g, in the shape of number of wavelength points x number of pressure points. This opacity will then be added to the atmospheric absorption opacity. It may be used to add simple cloud absorption laws, for example, which have opacities that vary only slowly with wavelength, such that the current model resolution is sufficient to resolve any variations.
 calc_rosse_planck(temp, abunds, gravity, mmw, sigma_lnorm=None, fsed=None, Kzz=None, radius=None, contribution=False, gray_opacity=None, Pcloud=None, kappa_zero=None, gamma_scat=None, haze_factor=None, add_cloud_scat_as_abs=None, dist='lognormal', b_hans=None, a_hans=None)¶
Method to calculate the atmosphere’s Rosseland and Planck mean opacities.
 Args:
 temp:
the atmospheric temperature in K, at each atmospheric layer (1d numpy array, same length as pressure array).
 abunds:
dictionary of mass fractions for all atmospheric absorbers. Dictionary keys are the species names. Every mass fraction array has same length as pressure array.
 gravity (float):
Surface gravity in cgs. Vertically constant for emission spectra.
 mmw:
the atmospheric mean molecular weight in amu, at each atmospheric layer (1d numpy array, same length as pressure array).
 sigma_lnorm (Optional[float]):
width of the lognormal cloud particle size distribution
 fsed (Optional[float]):
cloud settling parameter
 Kzz (Optional):
the atmospheric eddy diffusion coeffiecient in cgs untis (i.e. \(\rm cm^2/s\)), at each atmospheric layer (1d numpy array, same length as pressure array).
 radius (Optional):
dictionary of mean particle radii for all cloud species. Dictionary keys are the cloud species names. Every radius array has same length as pressure array.
 contribution (Optional[bool]):
If
True
the emission contribution function will be calculated. Default isFalse
. gray_opacity (Optional[float]):
Gray opacity value, to be added to the opacity at all pressures and wavelengths (units \(\rm cm^2/g\))
 Pcloud (Optional[float]):
Pressure, in bar, where opaque cloud deck is added to the absorption opacity.
 kappa_zero (Optional[float]):
Scarttering opacity at 0.35 micron, in cgs units (cm^2/g).
 gamma_scat (Optional[float]):
Has to be given if kappa_zero is definded, this is the wavelength powerlaw index of the parametrized scattering opacity.
 haze_factor (Optional[float]):
Scalar factor, increasing the gas Rayleigh scattering crosssection.
 add_cloud_scat_as_abs (Optional[bool]):
If
True
, 20 % of the cloud scattering opacity will be added to the absorption opacity, introduced to test for the effect of neglecting scattering. dist (Optional[string]):
The cloud particle size distribution to use. Can be either ‘lognormal’ (default) or ‘hansen’. If hansen, the b_hans parameters must be used.
 a_hans (Optional[dict]):
A dictionary of the ‘a’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. Equivilant to radius arg. If a_hans is not included and dist is “hansen”, then it will be computed using Kzz and fsed (recommended).
 b_hans (Optional[dict]):
A dictionary of the ‘b’ parameter values for each included cloud species and for each atmospheric layer, formatted as the kzz argument. This is the width of the hansen distribution normalized by the particle area (1/a_hans^2)
 get_opa(temp)¶
Method to calculate and return the line opacities (assuming an abundance of 100 % for the inidividual species) of the Radtrans object. This method updates the line_struc_kappas attribute within the Radtrans class. For the low resolution (ck) mode, the wavelengthmean within every frequency bin is returned.
 Args:
 temp:
the atmospheric temperature in K, at each atmospheric layer (1d numpy array, same length as pressure array).
 Returns:
wavelength in cm (1d numpy array)
dictionary of opacities, keys are the names of the line_species dictionary, entries are 2d numpy arrays, with the shape being (number of frequencies, number of atmospheric layers). Units are cm^2/g, assuming an absorber abundance of 100 % for all respective species.
 plot_opas(species, temperature, pressure_bar, mass_fraction=None, CO=0.55, FeH=0.0, **kwargs)¶
 calc_tau_cloud(gravity)¶
Method to calculate the optical depth of the clouds as function of frequency and pressure. The array with the optical depths is set to the
tau_cloud
attribute. The optical depth is calculated from the top of the atmosphere (i.e. the smallest pressure). Therefore, below the cloud base, the optical depth is constant and equal to the value at the cloud base. Args:
 gravity (float):
Surface gravity in cgs. Vertically constant for emission spectra.
 write_out_rebin(resolution, path='', species=None, masses=None)¶
 calc_radius_hydrostatic_equilibrium(temperatures, MMWs, gravity, P0, R_pl, variable_gravity=True, pressures=None)¶
 calc_pressure_hydrostatic_equilibrium(MMW, gravity, R_pl, P0, temperature, radii, rk4=True)¶
 petitRADTRANS.radtrans.py_calc_cloud_opas(rho, rho_p, cloud_mass_fracs, r_g, sigma_n, cloud_rad_bins, cloud_radii, cloud_specs_abs_opa, cloud_specs_scat_opa, cloud_aniso)¶
” This function reimplements calc_cloud_opas from fort_spec.f90. For some reason it runs faster in python than in fortran, so we’ll use this from now on. This function integrates the cloud opacity throught the different layers of the atmosphere to get the total optical depth, scattering and anisotropic fraction.
author: Francois Rozet