# exo_k¶

@author: jeremy leconte __init__ module to load the exo_k library

## Package Contents¶

class Ktable(*filename_filters, filename=None, xtable=None, path=None, p_unit='unspecified', file_p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, search_path=None, mol=None, **kwargs)[source]

A class that handles 4D tables of k-coefficients.

Based on the Data_table class that handles basic operations common to Xtable.

Based on the Ktable_io class that incorporates all io routines (read/write_xxx for all the xxx supported formats).

Initializes k coeff table and supporting data from various sources (see below by order of precedence)

Parameters
• filename (str, optional) – Relative or absolute name of the file to be loaded.

• filename_filters (sequence of string) – As many strings as necessary to uniquely define a file in the global search path defined in Settings. This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain ‘*’.

• xtable (Xtable object) – If no filename nor filename_filters are provided, this xtable object will be used to create a ktable. In this case, wavenumber bins must be given with the wnedges keyword.

• path (str) – If none of the above is specifed, path can point to a directory with a LMDZ type k coeff table. In this case, see read_LMDZ for the keywords to specify.

If none of the parameters above is specified, just creates an empty object to be filled later.

Other Parameters
• p_unit (str, optional) – String identifying the pressure units to convert to (e.g. ‘bar’, ‘Pa’, ‘mbar’, or any pressure unit recognized by the astropy.units library). If =’unspecified’, no conversion is done.

• file_p_unit (str, optional) – String to specify the current pressure unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the pressure grid and the pressure unit do not correspond)

• kdata_unit (str, optional) – String to identify the unit to convert to. Accepts ‘cm^2’, ‘m^2’ or any surface unit recognized by the astropy.units library. If =’unspecified’, no conversion is done. In general, kdata should be kept in ‘per number’ or ‘per volume’ units (as opposed to ‘per mass’ units) as composition will always be assumed to be a number or volume mixing ratio. Opacities per unit mass are not supported yet. Note that you do not need to specify the ‘/molec’ or ‘/molecule’ in the unit.

• file_kdata_unit (str, optional) – String to specify the current kdata unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the kdata grid and the kdata unit do not correspond)

• remove_zeros (boolean, optional) – If True, the zeros in the kdata table are replaced by a value 10 orders of magnitude smaller than the smallest positive value

• mol (str, optional) – The name of the gas or molecule described by the Ktable

• search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path in Settings and only files in search_path are returned.

property shape(self)

Returns the shape of self.kdata

xtable_to_ktable(self, xtable=None, wnedges=None, weights=None, ggrid=None, quad='legendre', order=20, g_split=0.9, mid_dw=True, write=0, remove_zeros=False)[source]

Fills the Ktable object with a k-coeff table computed from a Xtable object (inplace).

The p and kcorr units are inherited from the Xtable object.

Parameters
• xtable (Xtable) – input Xtable object instance

• wnedges (Array) – edges of the wavenumber bins to be used to compute the corrk

Other Parameters
• weights (array, optional) – If weights are provided, they are used instead of the legendre quadrature.

• quad (string, optional) – Type of quadrature used. Default is ‘legendre’. Also available: ‘split-legendre’ which uses half quadrature points between 0. and g_split and half between g_split and 1.

• order (Integer, optional) – Order of the Gauss legendre quadrature used. Default is 20.

• g_split (float, optional) – Used only if quad=’split-legendre’. See above.

• mid_dw (boolean, optional) –

• If True, the Xsec values in the high resolution xtable data are assumed to cover a spectral interval that is centered around the corresponding wavenumber value. The first and last Xsec values are discarded.

• If False, each interval runs from the wavenumber value to the next one. The last Xsec value is dicarded.

hires_to_ktable(self, path=None, filename_grid=None, logpgrid=None, tgrid=None, wnedges=None, quad='legendre', order=20, g_split=0.9, weights=None, ggrid=None, mid_dw=True, write=0, mol=None, grid_p_unit='Pa', p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, **kwargs)[source]

Computes a k coeff table from Hires_spectrum objects (inplace).

Warning

By default, log pressures are specified in Pa in logpgrid!!! If you want to use another unit, do not forget to specify it with the grid_p_unit keyword.

Parameters
• path (String) – directory with the input files

• filename_grid (array of str with shape (logpgrid.size,tgrid.size)) – Names of the input high-res spectra. If None, the files are assumed to follow Kspectrum/LMDZ convention, i.e. be of the type ‘k001’, ‘k002’, etc. See create_fname_grid_Kspectrum_LMDZ() for possible additional keyword arguments.

• logpgrid (array) – Grid in log(pressure) of the input. Default unit is Pa, but can be changed with the grid_p_unit keyword.

• tgrid (array) – Grid in temperature of the input.

• wnedges (array) – Edges of the wavenumber bins to be used to compute the corr-k

Other Parameters
• weights (array, optional) – If weights are provided, they are used instead of the legendre quadrature.

• quad (string, optional) – Type of quadrature used. Default is ‘legendre’. Also available: ‘split-legendre’ which uses half quadrature points between 0. and g_split and half between g_split and 1.

• order (Integer, optional) – Order of the Gauss legendre quadrature used. Default is 20.

• g_split (float, optional) – Used only if quad=’split-legendre’. See above.

• mid_dw (boolean, optional) –

• If True, the Xsec values in the high resolution xsec data are assumed to cover a spectral interval that is centered around the corresponding wavenumber value. The first and last Xsec values are discarded.

• If False, each interval runs from the wavenumber value to the next one. The last Xsec value is dicarded.

• mol (string, optional) – Give a name to the molecule. Useful when used later in a Kdatabase to track molecules.

• p_unit (str, optional) – Pressure unit to convert to.

• grid_p_unit (str, optional) – Unit of the specified logpgrid.

• kdata_unit (str, optional) – Kdata unit to convert to.

• file_kdata_unit (str, optional) – Kdata unit in input files.

See create_fname_grid_Kspectrum_LMDZ() or Hires_spectrum for a list of additional arguments that can be provided to those funtion through **kwargs.

copy(self, cp_kdata=True, ktab5d=False)[source]

Creates a new instance of Ktable object and (deep) copies data into it.

Parameters
• cp_kdata (bool, optional) – If false, the kdata table is not copied and only the structure and metadata are.

• ktab5d (bool, optional) – If true, creates a Ktable5d object with the same structure. Data are not copied.

Returns

A new Ktable or Ktable5d instance with the same structure as self.

Return type
gindex(self, g)[source]

Finds the index corresponding to the given g

spectrum_to_plot(self, p=1e-05, t=200.0, x=1.0, g=None)[source]

provide the spectrum for a given point to be plotted

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• g (float) – Gauss point

• x (float) – Mixing ratio of the species

plot_distrib(self, ax, p=1e-05, t=200.0, wl=1.0, x=1.0, xscale=None, yscale='log', **kwarg)[source]

Plot the distribution for a given point

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• wl (float) – Wavelength (micron)

RandOverlap(self, other, x_self, x_other, write=0, use_rebin=False)[source]

Method to randomly mix the opacities of 2 species (self and other).

Parameters
• other (Ktable) – A Ktable object to be mixed with. Dimensions should be the same as self.

• x_self (float or array) – Volume mixing ratio of the first species

• x_other (float or array) – Volume mixing ratio of the species to be mixed with.

If one of these is None, the kcoeffs of the species in question are considered to be already normalized with respect to the mixing ratio.

Returns

array of k-coefficients for the mix.

Return type

array

bin_down(self, wnedges=None, weights=None, ggrid=None, remove_zeros=False, num=300, use_rebin=False, write=0)[source]

Method to bin down a kcoeff table to a new grid of wavenumbers (inplace).

Parameters
• wnedges (array) – Edges of the new bins of wavenumbers (cm-1) onto which the kcoeff should be binned down. if you want Nwnew bin in the end, wnedges.size must be Nwnew+1 wnedges[0] should be greater than self.wnedges[0] (JL20 not sure anymore) wnedges[-1] should be lower than self.wnedges[-1]

• weights (array, optional) – Desired weights for the resulting Ktable.

• ggrid (array, optional) – Desired g-points for the resulting Ktable. Must be consistent with provided weights. If not given, they are taken at the midpoints of the array given by the cumulative sum of the weights

remap_g(self, ggrid=None, weights=None)[source]

Method to resample a kcoeff table to a new g grid (inplace).

Parameters
• ggrid (array) – New grid of abcissas for quadrature

• weights (array) – New grid of weights

class Ktable5d(*filename_filters, filename=None, path=None, p_unit='unspecified', file_p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, search_path=None, mol=None, **kwargs)[source]

A class that handles tables of k-coefficients with a variable gas. Based on the Data_table class that handles basic operations common to Ktable and Xtable.

This class is specifically designed to deal with LMDZ type ktable where there is a variable gas.

Initializes k coeff table with variable gas and supporting data from various sources (see below by order of precedence)

Parameters
• filename (str (optional)) – Relative or absolute name of the file to be loaded.

• path (str) – If none of the above is specifed, path can point to a directory with a LMDZ type k coeff table. In this case, see read_LMDZ for the keywords to specify.

If there is no input, just creates an empty object to be filled later

See Ktable __init__ mehthod for documentation on p_unit, file_p_unit, kdata_unit, file_kdata_unit, remove_zeros, search_path, and mol arguments.

property shape(self)

Returns the shape of self.kdata

read_hdf5(self, filename=None, mol=None)[source]

Initializes k coeff table and supporting data from an Exomol hdf5 file

Parameters

filename (str) – Name of the input hdf5 file

write_hdf5(self, filename, compression='gzip', compression_level=9, kdata_unit=None, p_unit=None)[source]

Saves data in a hdf5 format

Parameters

filename (str) – Name of the file to be created and saved

read_LMDZ(self, path=None, res=None, band=None, mol=None)[source]

Initializes k coeff table and supporting data from a .dat file in a gcm friendly format.

Units are assumed to be cm^2 for kdata and mbar for pressure.

Parameters
• path (str) – Name of the directory with the various input files

• res (str) – “IRxVI” where IR and VI are the numbers of bands in the infrared and visible of the k table to load.

• band (str) – “IR” or “VI” to specify which band to load.

write_LMDZ(self, path, band='IR', fmt='%22.15e', write_only_metadata=False)[source]

Saves data in a LMDZ friendly format.

The gcm requires p in mbar and kdata in cm^2/molec. The conversion is done automatically.

Parameters
• path (str) – Name of the directory to be created and saved, the one that will contain all the necessary files

• band (str) – The band you are computing: ‘IR’ or ‘VI’

• fmt (str) – Fortran format for the corrk file.

• write_only_metadata (bool, optional) – If True, only supporting files are written (T.dat, p.dat, etc.)

hires_to_ktable(self, path=None, filename_grid=None, logpgrid=None, tgrid=None, xgrid=None, wnedges=None, quad='legendre', order=20, g_split=0.9, weights=None, ggrid=None, mid_dw=True, write=0, mol=None, grid_p_unit='Pa', p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, **kwargs)[source]

Computes a k coeff table from Hires_spectrum objects.

see exo_k.ktable.Ktable.hires_to_ktable() method for details on the arguments and options.

Other Parameters

xgrid (array) – Input grid in vmr of the variable gas. Needed for a Ktable5d.

Warning

By default, log pressures are specified in Pa in logpgrid!!! If you want to use another unit, do not forget to specify it with the grid_p_unit keyword.

setup_interpolation(self, log_interp=None)[source]

Creates interpolating functions to be called later on. and loads it as attribute (inplace).

set_kdata(self, new_kdata)[source]

Changes kdata (inplace). this is preferred to directly accessing kdata because one could forget to run setup_interpolation().

Parameters

new_kdata (array) – New array of kdata.

interpolate_kdata(self, logp_array=None, t_array=None, x_array=None, log_interp=None, wngrid_limit=None)[source]

interpolate_kdata interpolates the kdata at on a given temperature and log pressure profile.

Parameters
• logp_array (Array) – log 10 pressure array to interpolate to

• t_array (Array, same size a logp_array) – Temperature array to interpolate to

• x_array (Array, same size a logp_array) – vmr of variable gas array to interpolate to

• floats are given, they are interpreted as arrays of size 1. (If) –

• wngrid_limit (list or array, optional) – if an array is given, interpolates only within this array

• log_interp (bool, dummy) – Dummy variable to be consistent with interpolate_kdata in data_table. Whether the interpolation is linear in kdata or in log(kdata) is actually controlled by self._settings._log_interp but only when the ktable is loaded. If you change that after the loading, you should rerun setup_interpolation().

Returns

The interpolated kdata.

Return type

array of shape (logp_array.size, self.Nw , self.Ng)

remap_logPT(self, logp_array=None, t_array=None, x_array=None)[source]

remap_logPT re-interpolates the kdata on a new temprature and log pressure grid (inplace).

Parameters
• logp_array (Array) – log 10 pressure array to interpolate to

• t_array (Array) – temperature array to interpolate to

• x_array (Array) – vmr of variable gas array to interpolate to

Whether the interpolation is linear in kdata or in log(kdata) is controlled by self._settings._log_interp but only when the ktable is loaded. If you change that after the loading, you should rerun setup_interpolation().

copy(self, cp_kdata=True)[source]

Creates a new instance of Ktable5d object and (deep) copies data into it

Parameters

cp_kdata (bool, optional) – If false, the kdata table is not copied and only the structure and metadata are.

Returns

A new Ktable5d instance with the same structure as self.

Return type

Ktable

gindex(self, g)[source]

Finds the index corresponding to the given g

xindex(self, x)[source]

Finds the index corresponding to the given x

spectrum_to_plot(self, p=1e-05, t=200.0, x=1.0, g=None)[source]

provide the spectrum for a given point to be plotted

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• g (float) – Gauss point

• x (float) – Mixing ratio of the species

plot_distrib(self, ax, p=1e-05, t=200.0, wl=1.0, x=1.0, xscale=None, yscale='log', **kwarg)[source]

Plot the distribution for a given point

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• wl (float) – Wavelength (micron)

combine_with(self, other, x_self=None, x_other=None, **kwargs)[source]

Method to create a new Ktable5d where the kdata of ‘self’ are randomly mixed with ‘other’ (that must be a Ktable).

The main purpose is to add the opacity of a trace species to the background gas of the Ktable5d instance.

Warning

Because:

• the opacity from the background and variable gases cannot be isolated,

• The values of the array for the vmr of the variable gas (self.xgrid) are not modified (diluted),

the treatment here is valid only if x_other << 1.

For this reason, x_self should be either left to None, or 1-x_other depending exactly what you want to do. But if you put x_self<<1, you are on your own.

Parameters
• other (Ktable) – A Ktable object to be mixed with. Dimensions should be the same as self (except for xgrid).

• x_self (float only, optional) – Volume mixing ratio of self.

• x_other (float or array, optional) – Volume mixing ratio of the species to be mixed with (other).

If either x_self or x_other are set to None (default), the cross section of the species in question are considered to be already normalized with respect to the mixing ratio.

Returns

A new Ktable5d with the opacity of the new species added.

Return type

Ktable5d

bin_down(self, wnedges=None, weights=None, ggrid=None, remove_zeros=False, num=300, use_rebin=False, write=0)[source]

Method to bin down a kcoeff table to a new grid of wavenumbers (inplace).

Parameters
• wnedges (array) – Edges of the new bins of wavenumbers (cm-1) onto which the kcoeff should be binned down. if you want Nwnew bin in the end, wnedges.size must be Nwnew+1 wnedges[0] should be greater than self.wnedges[0] (JL20 not sure anymore) wnedges[-1] should be lower than self.wnedges[-1]

• weights (array, optional) – Desired weights for the resulting Ktable.

• ggrid (array, optional) – Desired g-points for the resulting Ktable. Must be consistent with provided weights. If not given, they are taken at the midpoints of the array given by the cumulative sum of the weights

clip_spectral_range(self, wn_range=None, wl_range=None)[source]

Limits the data to the provided spectral range (inplace):

• Wavenumber in cm^-1 if using wn_range argument

• Wavelength in micron if using wl_range

extend_spectral_range(self, **kwargs)[source]

Extends the spectral range of an existing table (inplace). The new bins are filled with zeros (except if remove_zeros=True).

See exo_k.data_table.Data_table.extend_spectral_range() method for details on the arguments and options.

remap_g(self, ggrid=None, weights=None)[source]

Method to resample a kcoeff table to a new g grid (inplace).

Parameters
• ggrid (array) – New grid of abcissas for quadrature

• weights (array) – New grid of weights

class Xtable(*filename_filters, filename=None, p_unit='unspecified', file_p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, search_path=None, mol=None)[source]

A class that handles tables of cross sections.

Initializes cross section table and supporting data from a file based on its extension.

Parameters
• filename (str) – Relative or absolute path to the input file.

• filename_filters (sequence of string) – As many strings as necessary to uniquely define a file in the global search path defined in Settings. This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain ‘*’.

If there is no filename or filename_filters provided, just creates an empty object to be filled later

See Ktable __init__ mehthod for documentation on p_unit, file_p_unit, kdata_unit, file_kdata_unit, remove_zeros, search_path, and mol keywords.

read_hdf5(self, filename=None, mol=None)[source]

Initializes k coeff table and supporting data from an Exomol hdf5 file

Parameters
• filename (str) – Name of the input hdf5 file

• mol (str, optional) – Overrides the name of the molecule to be put in the Xtable object.

write_hdf5(self, filename, compression='gzip', compression_level=9, kdata_unit=None, p_unit=None, exomol_units=False)[source]

Saves data in a hdf5 format

Parameters
• filename (str) – Name of the file to be created and saved

• exomol_units (bool (optional)) – If True, data are converted back to cm^2 and bar units before being written.

read_exo_transmit(self, filename, mol=None)[source]

Creates an xsec object from an exo_transmit like spectra. See https://github.com/elizakempton/Exo_Transmit or Kempton et al. (2016) for details. Pressures are expected to be in Pa and cross sections in m^2/molecule

Parameters
• filename (str) – Name of the input file.

• mol (str) – Overrides the name of the molecule to be put in the Xtable object.

hires_to_xtable(self, path=None, filename_grid=None, logpgrid=None, tgrid=None, write=0, mol=None, grid_p_unit='Pa', p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', **kwargs)[source]

Loads an Xtable from high-resolution spectra (inplace).

Warning

By default, log pressures are specified in Pa in logpgrid!!! If you want to use another unit, do not forget to specify it with the grid_p_unit keyword.

see exo_k.ktable.Ktable.hires_to_ktable() method for details on the arguments and options.

bin_down(self, wnedges=None, remove_zeros=False, write=0)[source]

Method to bin down a xsec table to a new grid of wavenumbers (inplace).

Parameters
• wnedges (array) – Edges of the new bins of wavenumbers (cm-1) onto which the xsec should be binned down. if you want Nwnew bin in the end, wngrid.size must be Nwnew+1 wnedges[0] should be greater than self.wnedges[0] wnedges[-1] should be lower than self.wnedges[-1]

• remove_zeros (bool, optional) – If True, remove zeros in kdata.

sample(self, wngrid, remove_zeros=False, log_interp=None)[source]

Method to re sample a xsec table to a new grid of wavenumbers (inplace).

Parameters

wngrid (array) – Location of the new wavenumbers points (cm-1)

sample_cp(self, wngrid, **kwargs)[source]

Creates a copy of the instance before resampling it.

Parameters

sample method for details. (See) –

Returns

the re-sampled Xtable

Return type

Xtable object

spectrum_to_plot(self, p=1e-05, t=200.0, x=1.0, g=None)[source]

provide the spectrum for a given point to be plotted

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• x (float) – Volume mixing ratio of the species

• g (is unused but here to be consistent with the method in data_table) –

copy(self, cp_kdata=True)[source]

Creates a new instance of Xtable object and (deep) copies data into it

Parameters

cp_kdata (bool, optional) – If false, the kdata table is not copied and only the structure and metadata are.

Returns

A new Xtable instance with the same structure as self.

Return type

Xtable

property shape(self)

Returns the shape of self.kdata

read_pickle(self, filename=None)[source]

Initializes xsec table and supporting data from an Exomol pickle file

Parameters
• filename (str) – Relative or absolute name of the input pickle file

• mol (str, optional) – Overrides the name of the molecule to be put in the Xtable object.

write_pickle(self, filename)[source]

Saves data in a pickle format

Parameters

filename (str) – Relative or absolute name of the file to be created and saved

class Hires_spectrum(filename, file_kdata_unit='unspecified', kdata_unit='unspecified', mult_factor=None, binary=False, **kwargs)[source]

A class defining a Hires_spectrum object.

Reads a high-resolution spectrum from a file (either hdf5 or ascii).

Parameters
• filename (str) – Full pathname to the file. Extension defines the format used.

• file_kdata_unit (str) – Specifies the unit for the opacity data in the file. This is needed for ascii formats as the units are not known. The type of quantity may differ whether we are handling cross sections (surface) or absorption coefficients (inverse length)

• kdata_unit (str) – Unit to convert to.

• mult_factor (float) – A multiplicative factor that can be applied to kdata (for example to correct for any dilution effect, or specific conversion).

see read_ascii() for additional arguments to use with ascii files

read_ascii(self, filename, data_type=None, skiprows=0, wn_column=None, kdata_column=None)[source]

Parameters
• filename (str) – Initial hires-spectrum filename.

• data_type ('xsec' or 'abs_coeff') – Whether the data read are cross-sections or absorption coefficients.

• skiprows (int, optional) – Number of header lines to skip. For the latest Kspectrum format, the header is skipped automatically.

• wn_column/kdata_column (int, optional) – Number of column to be read for wavenumber and kdata in python convention (0 is first, 1 is second, etc.)

write_hdf5(self, filename)[source]

Writes kspectrum file to hdf5

read_hdf5(self, filename)[source]

read_binary(self, filename, mass_amu=None)[source]

Assumed to be in cm^2/g with wavelength in cm.

Will be automatically converted to cm^2/molecule and wns in cm^-1 (unless conversion to mks is requested).

convert_kdata_unit(self, kdata_unit='unspecified', file_kdata_unit='unspecified')[source]

Converts kdata to a new unit (inplace)

Parameters
• kdata_unit (str) – String to identify the units to convert to. Accepts ‘cm^2’, ‘m^2’ or any surface unit recognized by the astropy.units library. If =’unspecified’, no conversion is done. In general, kdata should be kept in ‘per number’ or ‘per volume’ units (as opposed to ‘per mass’ units) as composition will always be assumed to be a number or volume mixing ratio. Opacities per unit mass are not supported yet. Note that you do not need to specify the ‘/molec’ or ‘/molecule’ in the unit.

• file_kdata_unit (str) – String to specify the current kdata unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the kdata grid and the kdata unit do not correspond)

plot_spectrum(self, ax, x_axis='wls', xscale=None, yscale=None, x=1.0, **kwarg)[source]

Plot the spectrum

Parameters
• ax (pyplot.Axes) – A pyplot axes instance where to put the plot.

• x_axis (str, optional) – If ‘wls’, x axis is wavelength. Wavenumber otherwise.

• x/yscale (str, optional) – If ‘log’ log axes are used.

convert_data_type(self, pressure, temperature, kdata_unit=None, convert_to=None)[source]

Converts from one data_type (cross sections or absorption coefficents) to the other (inplace).

Conversion to mks is done by default if a conversion takes place and no kdata_unit is specified.

Parameters
• pressure (float) – Pressure used for the conversion (in Pa)

• temperature (float) – Temperature used for the conversion (in K)

• kdata_unit (str (optional)) – Unit to use for the output

• convert_to (str ('xsec' or 'abs_coeff', optional)) – Data type to convert to. Nothing is done if convert_to is equal to self.data_type. If None, converts to the other type.

clip_spectral_range(self, wn_range=None, wl_range=None)[source]

Limits the data to the provided spectral range (inplace):

• Wavenumber in cm^-1 if using wn_range argument

• Wavelength in micron if using wl_range

PI = 3.14159265359
create_table(logpgrid=None, tgrid=None, xgrid=None, wngrid=None, wnedges=None, ggrid=None, weights=None, p_unit='Pa', kdata_unit='m^2/molecule', value=None, mol=None)[source]

Create a new table with the required dimensions padded with zeros.

The class of the object created will depend on the dimensions required.

Parameters
• logpgrid (array) – Grid in log p

• tgrid (array) – Grid in T

• xgrid (array) – Grid in volume mixing ratio

• wngrid (array) – Grid wavenumber

• ggrid (array) – Grid g-space

• weights (array) – Grid of quadrature weights

• p_unit (str (optional)) – Unit of pressure (default Pa)

• kdata_unit (str (optional)) – Unit of cross section (default is m^2/molecule)

Returns

new_table – A new table

Return type

Xtable, Ktable, or Ktable5d

hires_to_ktable(filename_grid=None, xgrid=None, **kwargs)[source]

Emulates exo_k.ktable.Ktable.hires_to_ktable() and exo_k.ktable5d.Ktable5d.hires_to_ktable() as functions and not methods so that the user can call them without creating a Ktable first.

See those methods for details on the available arguments and options.

hires_to_xtable(**kwargs)[source]

Emulates exo_k.xtable.Xtable.hires_to_xtable() as a function and not a method so that the user can call it without creating an Xtable first.

See hires_to_xtable() for details on the available arguments and options.

convert_kspectrum_to_hdf5(file_in, file_out=None, **kwargs)[source]

Converts kspectrum like spectra to hdf5 format for speed and space. Helper function. Real work done in Hires_spectrum __init__ funtion.

Go there to see all the available arguments and options.

Parameters
• file_in (str) – Initial kspectrum filename.

• file_out (str) – Name of the final hdf5 file to be created. If not provided, ‘file_in.h5’ will be used.

create_fname_grid(base_string, logpgrid=None, tgrid=None, xgrid=None, p_kw=None, t_kw=None, x_kw=None)[source]

Creates a grid of filenames from an array of pressures, temperatures ( and vmr if there is a variable gas).

Parameters
• base_string (str) – Generic name of the spectra files with specific keywords to be replaced by the relevant numerical values

• logpgrid (Array) – Grid in log(pressure/Pa) of the input

• tgrid (Array) – Grid in temperature of the input

• xgrid (Array) – Input grid in vmr of the variable gas

Warning

The result of this function is much more predictable if the values in the above arrays are given as integers or directly strings. If you want to use floats anyway, good luck.

Parameters
• p_kw (str) –

• t_kw (str) –

• x_kw (str) – The pattern string that will be recognized as keywords between {} in base_string (See examples).

Examples

>>> logpgrid=[1,2]
>>> tgrid=np.array([100.,150.,200.])
>>> file_grid=exo_k.create_fname_grid('spectrum_CO2_1e{logp}Pa_{t}K.hdf5',
logpgrid=logpgrid,tgrid=tgrid,p_kw='logp',t_kw='t')
array([['spectrum_CO2_1e1Pa_100K.hdf5', 'spectrum_CO2_1e1Pa_150K.hdf5',
'spectrum_CO2_1e1Pa_200K.hdf5'],
['spectrum_CO2_1e2Pa_100K.hdf5', 'spectrum_CO2_1e2Pa_150K.hdf5',
'spectrum_CO2_1e2Pa_200K.hdf5']], dtype='<U28')

finalize_LMDZ_dir(corrkname, IRsize, VIsize)[source]

Creates the right links for a LMDZ type directory to be read by the LMDZ generic GCM.

You will need to create a proper Q.dat before using with the LMDZ GCM.

Important

You must have run exo_k.ktable.Ktable.write_LMDZ() or exo_k.ktable5d.Ktable5d.write_LMDZ() for both of your IR and VI channels beforehand.

Parameters
• corrkname (str) – Path to the directory with the LMDZ ktable to finalize

• IRsize (int) – Number of IR spectral bins

• VIsize (int) – Number of VI spectral bins

mmr_to_number_density(mmr, gas_density, r_eff, condensate_density)[source]

Converts a mass mixing ratio (mmr or q) in a number density of particles (in number per unit volume)

Parameters
• mmr (float or array) – Mass mixing ratio (in kg per kg of air)

• gas_density (float or array) – Density of the gas (in kg/m^3)

• r_eff (float or array) – Effective radius of the particles

• condensate_density (float or array) – Density of the constituent of the condensed particles (in kg/m^3)

PI = 3.14159265359
PLANCK = 6.62606957e-34
C_LUM = 299792458
KBOLTZ = 1.380648813e-23
SIG_SB = 5.670367e-08
PLANCK_CST1MKS
PLANCK_CST1
PLANCK_CST2
PLANCK_CST1_lamb
Bnu(nu, T)[source]

Computes the Planck law in wavenumber domain.

Parameters
• nu (float) – The wavenumber in cm^-1.

• T (float) – Temperature (K).

Returns

Bnu in W/m^2/str/cm^-1 (not SI units).

Return type

float

sigma*T^4=Int(Bnu dnu) where nu is expressed in cm^-1

Bnu_integral(nu_edges, T)[source]

Computes the integral of the Planck function in wavenumber bins.

Parameters
• nu_edges (array) – Edges of the wavenumber bins in cm^-1.

• T (float) – Temperature (K).

Returns

Bnu_integral in W/m^2/str.

Return type

array

sigma*T^4/PI=sum of Bnu_integral

Bnu_integral_num(nu_edges, T, n=30)[source]

Computes the integral of the Planck function in wavenumber bins.

Parameters
• nu_edges (array) – Edges of the wavenumber bins in cm^-1.

• T (float) – Temperature (K).

• n (int) – number of terms to take into account in the black body calculation.

Returns

Bnu_integral_num: Integral of the source function at temperatures T_array inside the bins in W/m^2/str

Return type

Array of shape (T_array.size,nu_edges.size-1)

sigma*T^4=sum of Bnu_integral_num

Bnu_integral_array(nu_edges, T_array, Nw, Nt, n=30)[source]

Computes the integral of the Planck function in wavenumber bins.

Parameters
• nu_edges (array) – Edges of the wavenumber bins in cm^-1.

• T (array) – Array of temperature (K).

• Nw (int) – Number of spectral bins.

• Nt (int) – Number of temperatures.

• n (int, optional) – number of terms to take into account in the black body calculation.

Returns

Bnu_integral_num: Integral of the source function at temperatures T_array inside the bins in W/m^2/str

Return type

Array of shape (T_array.size,nu_edges.size-1)

sigma*T^4=sum of Bnu_integral_num

Bnu_integral_old(nu_edges, T)[source]

Deprecated.

Computes the integral of the Planck function in wavenumber bins. nu_edges is an array of the edges of the wavenumber bins in cm^-1.

sigma*T^4=sum of Bnu_integral

Bnu_integral is in W/m^2/str

Bmicron(lamb, T)[source]

Computes the Planck law in wavelength domain.

Parameters
• lamb (float) – The wavelength in microns.

• T (float) – Temperature (K).

Returns

float

Bmicron in W/m^2/str/micron (not SI units).

sigma*T^4=Int(Bmicron d lamb) where lamb is expressed in microns

BBnu_Stellar_Spectrum(nu, T, Flux)[source]

Computes the outgoing spectral flux of a black body at temperature T so that its bolometric flux is equal to the input ‘Flux’

Parameters
• nu (float) – The wavenumber in cm^-1.

• T (float) – Temperature (K).

• Flux (float) – bolometric flux for rescaling.

Returns

BBnu_Stellar_Spectrum is in W/m^2/cm^-1 (not SI units).

Return type

float

sigma*T^4=Int(Bnu dnu) where nu is expressed in cm^-1

BBmicron_Stellar_Spectrum(lamb, T, Flux)[source]

Computes the outgoing spectral flux of a black body at temperature T so that its bolometric flux is equal to the input ‘Flux’

Parameters
• lamb (float) – The wavelength in microns.

• T (float) – Temperature (K).

• Flux (float) – bolometric flux for rescaling.

Returns

BBmicron_Stellar_Spectrum is in W/m^2/micron (not SI units).

Return type

float

sigma*T^4=Int(Bmicron d lamb) where lamb is expressed in microns.

wavelength_grid_R(lambda_min, lambda_max, R)[source]

Creates a wavelength grid starting from lambda_min and ending at lambda_max with a resolution of R (roughly).

Parameters
• lambda_min/lambda_max (int or float) – Min/max wavelength (in micron).

• R (int or float) – Resolution.

Returns

Grid of wavelength.

Return type

array

wavenumber_grid_R(nu_min, nu_max, R)[source]

Creates a wavenumber grid starting from nu_min and ending at nu_max with a resolution of R (roughly).

Parameters
• nu_min/nu_max (int or float) – Min/max wavenumber (in cm^-1).

• R (int or float) – Resolution.

Returns

Grid of wavenumber.

Return type

array

rad_prop_corrk(dcol_density, opacity_prof, mu0)[source]

Computes the optical depth of each of the layers for the opacity given for every wavelength and g point.

Parameters
• dcol_density (array) – Column density per layer (molecules/m^2/layer).

• opacity_prof (array) – effective cross section per molecule (m^2/molecule).

• mu0 (cosine of the equivalent zenith angle for the rays.) – e.g. Cos(60deg)=0.5 is chosen (See, for example, chap 4 of Pierrehumbert 2010)

Returns

• tau (Array) – cumulative optical depth from the top (with zeros at the top of the first layer)

• dtau (Array) – optical depth of each layer for each wavenumber.

rad_prop_xsec(dcol_density, opacity_prof, mu0)[source]

Computes the optical depth of each of the layers for the opacity given for every wavelength.

Parameters
• dcol_density (array) – Column density per layer (molecules/m^2/layer).

• opacity_prof (array) – effective cross section per molecule (m^2/molecule).

• mu0 (cosine of the equivalent zenith angle for the rays.) – e.g. Cos(60deg)=0.5 is chosen (See, for example, chap 4 of Pierrehumbert 2010)

Returns

• tau (Array) – cumulative optical depth from the top (with zeros at the top of the first layer)

• dtau (Array) – optical depth of each layer for each wavenumber.

path_integral_corrk(Nlay, Nw, Ng, tangent_path, density_prof, opacity_prof, weights)[source]

Computes the transmittance for each layer of the atmosphere for k-coefficients.

Parameters
• Nlay (int) – Number of layers.

• Nw (int) – Number of wavenumber bins.

• Ng (int) – Number of gauss points.

• tangent_path (List of arrays) – Triangular array of tangent path for each layer.

• density_prof (array) – Array with the number density of molecules in the atmosphere.

• opacity_prof (array) – Effective cross section of the atmsophere for each (layer,wavenumber,g-point).

• weights (array) – Weights for the quadrature in g-space.

Returns

transmittance – Transmittance for each layer and wavenumber bin (Exp(-tau_sigma)).

Return type

array

path_integral_xsec(Nlay, Nw, tangent_path, density_prof, opacity_prof)[source]

Computes the transmittance for each layer of the atmosphere from cross sections.

Parameters
• Nlay (int) – Number of layers.

• Nw (int) – Number of wavenumber bins.

• tangent_path (List of arrays) – Triangular array of tangent path for each layer.

• density_prof (array) – Array with the number density of molecules in the atmosphere.

• opacity_prof (array) – Effective cross section of the atmsophere for each (layer,wavenumber).

Returns

transmittance – Transmittance for each layer and wavenumber bin (Exp(-tau_sigma)).

Return type

array

gauss_legendre(order)[source]

Computes the weights and abscissa for a Gauss Legendre quadrature of order order

Parameters

order (int) – Order of the quadrature wanted.

Returns

• weights (array(order)) – Weights to be used in the quadrature.

• ggrid (array(order)) – Abscissa to be used for the quadrature.

• gedges (array(order+1)) – Cumulative sum of the weights. Goes from 0 to 1.

split_gauss_legendre(order, g_split)[source]

Computes the weights and abscissa for a split Gauss Legendre quadrature of order order: Half the points will be put between 0 and g_split, and half between g_splitand 1.

(This si what is used in petitRADTRANS with g_split=0.9)

Parameters
• order (int) – Order of the quadrature wanted. Needs to be even.

• g_split (float between 0 and 1) – Splitting point.

Returns

• weights (array(order)) – Weights to be used in the quadrature.

• ggrid (array(order)) – Abscissa to be used for the quadrature.

• gedges (array(order+1)) – Cumulative sum of the weights. Goes from 0 to 1.

G = 6.67384e-11
RSOL = 695500000.0
RJUP = 71492000.0
RJUP_POL = 69911000.0
PI = 3.14159265359
MSOL = 1.98847542e+30
MJUP = 1.898e+27
AU = 149597871000.0
KBOLTZ = 1.380648813e-23
RGP = 8.31446
PLANCK = 6.62606957e-34
C_LUM = 299792458
SIG_SB = 5.670367e-08
N_A = 6.022140857e+23
tiny = 1e-13
OneMintiny
ktable_long_name_attributes
nemesis_hitran_id_numbers
class Spectrum(value=None, wns=None, wnedges=None, filename=None, from_taurex=False, dataset='native_spectrum')[source]

A class defining a Spectrum object to plot and manipulate.

Instanciate with a value, bin centers, and bin edges. Can also load a Taurex spectrum if filename is provided.

copy(self)[source]

Deep copy of the spectrum.

plot_spectrum(self, ax, per_wavenumber=True, x_axis='wls', xscale=None, yscale=None, **kwarg)[source]

Plot the spectrum

Parameters
• ax (pyplot.Axes) – A pyplot axes instance where to put the plot.

• per_wavenumber (bool, optional) – Defines the units of spectral flux density. False converts to per wavelength units.

• x_axis (str, optional) – If ‘wls’, x axis is wavelength. Wavenumber otherwise.

• x/yscale (str, optional) – If ‘log’ log axes are used.

bin_down(self, wnedges)[source]

Bins down the spectrum to a new grid of wnedges by conserving area.

Parameters

wnedges (array) – Wavenumbers of the bin edges to be used

bin_down_cp(self, wnedges)[source]

Returns a new binned down spectrum to a grid of wnedges by conserving area.

Parameters

wnedges (array) – Wavenumbers of the bin edges to be used

Returns

Binned down spectrum

Return type

Spectrum

std(self)[source]

Defines standard deviation

abs(self)[source]

Defines absolute value

log10(self)[source]

Defines Log 10

property total(self)

Defines the weighted sum over the spectrum

read_hdf5(self, filename=None)[source]

Reads data in a hdf5 file

Parameters

filename (str) – Name of the file to be created and saved

write_hdf5(self, filename)[source]

Saves data in a hdf5 format

Parameters

filename (str) – Name of the file to be created and saved

load_taurex(self, filename, dataset='native_spectrum')[source]

Parameters
• filename (str) – Full name (path) of the hdf5 file to load

• dataset (str) – Name of the hdf5 dataset to load

exception EndOfFile[source]

Bases: Exception

Error for an end of file

Initialize self. See help(type(self)) for accurate signature.

select_kwargs(kwargs, filter_keys_list=[])[source]

Function to select only some keyword arguments from a kwargs dict to pass to a function afterward.

Parameters
• kwargs (dict) – Dictionary of keyword arguments and values.

• filter_keys_list (list of str) – Names of the keys to select.

Returns

filtered_kwargs – A dictionary with only the selected keys (if they were present in kwargs).

Return type

dict

Examples

>>> def func(allo=None):
>>>     print(allo)
>>>
>>>     print(kwargs)
>>>     func(**kwargs)
>>>
>>> def good_global_func(**kwargs):
>>>     print(kwargs)
>>>     func(**select_kwargs(kwargs,['allo']))

>>> bad_global_func(allo=3.,yeah=None)
{'allo': 3.0, 'yeah': None}
TypeError: func() got an unexpected keyword argument 'yeah'

>>> good_global_func(allo=3.,yeah=None)
{'allo': 3.0, 'yeah': None}
3.0

create_fname_grid_Kspectrum_LMDZ(Np, Nt, Nx=None, suffix='', nb_digit=3)[source]

Creates a grid of filenames consistent with Kspectrum/LMDZ from the number of pressure, temperatures (, and vmr) points (respectively) in the grid.

Parameters
• Nt (Np,) – Number of Pressure and temperature points.

• Nx (int, optional) – Number of vmr points if there is a variable gas

• suffix (str, optional) – String to add behind the ‘k001’

• nb_digit (int, optional) – Total number of digit including the zeros (‘k001’ is 3)

Returns

List of the files in the right order and formating to be given to exo_k.ktable.Ktable.hires_to_ktable() or exo_k.xtable.Xtable.hires_to_xtable().

Return type

list of str

Examples

>>> exo_k.create_fname_grid_Kspectrum_LMDZ(2,3)
array([['k001', 'k002', 'k003'],
['k004', 'k005', 'k006']], dtype='<U4')

>>> exo_k.create_fname_grid_Kspectrum_LMDZ(2,3,suffix='.h5')
array([['k001.h5', 'k002.h5', 'k003.h5'],
['k004.h5', 'k005.h5', 'k006.h5']], dtype='<U7')

convert_exo_transmit_to_hdf5(file_in, file_out, mol='unspecified')[source]

Converts exo_transmit like spectra to hdf5 format for speed and space.

Parameters
• file_in (str) – Initial exo_transmit filename.

• file_out (str) – Name of the final hdf5 file to be created.

convert_old_kspectrum_to_hdf5(file_in, file_out, skiprows=0)[source]

Deprecated.

Converts kspectrum like spectra to hdf5 format for speed and space

Parameters
• file_in (str) – Initial kspectrum filename.

• file_out (str) – Name of the final hdf5 file to be created.

class Molar_mass[source]

A class to compute the molar mass (in kg/mol) of regular molecules with a name written in a regular way (e.g. CO2, H2O, etc.). This class can also store the molar mass of custom gases with arbitrary names (for example: My_gas, earth_background).

init(self, *args, **kwds)[source]

Initializes empty dictionary of custom molecular masses.

add_species(self, species_dict)[source]

Add one or several species weights to the database.

Parameters

species_dict (dict) – Keys are gases names (they do not have to be real molecules). Values are molecular weight in kg/mol.

fetch(self, molecule_name)[source]

Computes the molar mass of a molecule in kg/mol

Parameters

molecule_name – str Name of the molecule.

Returns

Molar mass in kg/mol.

Return type

float

class Ktable(*filename_filters, filename=None, xtable=None, path=None, p_unit='unspecified', file_p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, search_path=None, mol=None, **kwargs)[source]

A class that handles 4D tables of k-coefficients.

Based on the Data_table class that handles basic operations common to Xtable.

Based on the Ktable_io class that incorporates all io routines (read/write_xxx for all the xxx supported formats).

Initializes k coeff table and supporting data from various sources (see below by order of precedence)

Parameters
• filename (str, optional) – Relative or absolute name of the file to be loaded.

• filename_filters (sequence of string) – As many strings as necessary to uniquely define a file in the global search path defined in Settings. This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain ‘*’.

• xtable (Xtable object) – If no filename nor filename_filters are provided, this xtable object will be used to create a ktable. In this case, wavenumber bins must be given with the wnedges keyword.

• path (str) – If none of the above is specifed, path can point to a directory with a LMDZ type k coeff table. In this case, see read_LMDZ for the keywords to specify.

If none of the parameters above is specified, just creates an empty object to be filled later.

Other Parameters
• p_unit (str, optional) – String identifying the pressure units to convert to (e.g. ‘bar’, ‘Pa’, ‘mbar’, or any pressure unit recognized by the astropy.units library). If =’unspecified’, no conversion is done.

• file_p_unit (str, optional) – String to specify the current pressure unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the pressure grid and the pressure unit do not correspond)

• kdata_unit (str, optional) – String to identify the unit to convert to. Accepts ‘cm^2’, ‘m^2’ or any surface unit recognized by the astropy.units library. If =’unspecified’, no conversion is done. In general, kdata should be kept in ‘per number’ or ‘per volume’ units (as opposed to ‘per mass’ units) as composition will always be assumed to be a number or volume mixing ratio. Opacities per unit mass are not supported yet. Note that you do not need to specify the ‘/molec’ or ‘/molecule’ in the unit.

• file_kdata_unit (str, optional) – String to specify the current kdata unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the kdata grid and the kdata unit do not correspond)

• remove_zeros (boolean, optional) – If True, the zeros in the kdata table are replaced by a value 10 orders of magnitude smaller than the smallest positive value

• mol (str, optional) – The name of the gas or molecule described by the Ktable

• search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path in Settings and only files in search_path are returned.

property shape(self)

Returns the shape of self.kdata

xtable_to_ktable(self, xtable=None, wnedges=None, weights=None, ggrid=None, quad='legendre', order=20, g_split=0.9, mid_dw=True, write=0, remove_zeros=False)[source]

Fills the Ktable object with a k-coeff table computed from a Xtable object (inplace).

The p and kcorr units are inherited from the Xtable object.

Parameters
• xtable (Xtable) – input Xtable object instance

• wnedges (Array) – edges of the wavenumber bins to be used to compute the corrk

Other Parameters
• weights (array, optional) – If weights are provided, they are used instead of the legendre quadrature.

• quad (string, optional) – Type of quadrature used. Default is ‘legendre’. Also available: ‘split-legendre’ which uses half quadrature points between 0. and g_split and half between g_split and 1.

• order (Integer, optional) – Order of the Gauss legendre quadrature used. Default is 20.

• g_split (float, optional) – Used only if quad=’split-legendre’. See above.

• mid_dw (boolean, optional) –

• If True, the Xsec values in the high resolution xtable data are assumed to cover a spectral interval that is centered around the corresponding wavenumber value. The first and last Xsec values are discarded.

• If False, each interval runs from the wavenumber value to the next one. The last Xsec value is dicarded.

hires_to_ktable(self, path=None, filename_grid=None, logpgrid=None, tgrid=None, wnedges=None, quad='legendre', order=20, g_split=0.9, weights=None, ggrid=None, mid_dw=True, write=0, mol=None, grid_p_unit='Pa', p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, **kwargs)[source]

Computes a k coeff table from Hires_spectrum objects (inplace).

Warning

By default, log pressures are specified in Pa in logpgrid!!! If you want to use another unit, do not forget to specify it with the grid_p_unit keyword.

Parameters
• path (String) – directory with the input files

• filename_grid (array of str with shape (logpgrid.size,tgrid.size)) – Names of the input high-res spectra. If None, the files are assumed to follow Kspectrum/LMDZ convention, i.e. be of the type ‘k001’, ‘k002’, etc. See create_fname_grid_Kspectrum_LMDZ() for possible additional keyword arguments.

• logpgrid (array) – Grid in log(pressure) of the input. Default unit is Pa, but can be changed with the grid_p_unit keyword.

• tgrid (array) – Grid in temperature of the input.

• wnedges (array) – Edges of the wavenumber bins to be used to compute the corr-k

Other Parameters
• weights (array, optional) – If weights are provided, they are used instead of the legendre quadrature.

• quad (string, optional) – Type of quadrature used. Default is ‘legendre’. Also available: ‘split-legendre’ which uses half quadrature points between 0. and g_split and half between g_split and 1.

• order (Integer, optional) – Order of the Gauss legendre quadrature used. Default is 20.

• g_split (float, optional) – Used only if quad=’split-legendre’. See above.

• mid_dw (boolean, optional) –

• If True, the Xsec values in the high resolution xsec data are assumed to cover a spectral interval that is centered around the corresponding wavenumber value. The first and last Xsec values are discarded.

• If False, each interval runs from the wavenumber value to the next one. The last Xsec value is dicarded.

• mol (string, optional) – Give a name to the molecule. Useful when used later in a Kdatabase to track molecules.

• p_unit (str, optional) – Pressure unit to convert to.

• grid_p_unit (str, optional) – Unit of the specified logpgrid.

• kdata_unit (str, optional) – Kdata unit to convert to.

• file_kdata_unit (str, optional) – Kdata unit in input files.

See create_fname_grid_Kspectrum_LMDZ() or Hires_spectrum for a list of additional arguments that can be provided to those funtion through **kwargs.

copy(self, cp_kdata=True, ktab5d=False)[source]

Creates a new instance of Ktable object and (deep) copies data into it.

Parameters
• cp_kdata (bool, optional) – If false, the kdata table is not copied and only the structure and metadata are.

• ktab5d (bool, optional) – If true, creates a Ktable5d object with the same structure. Data are not copied.

Returns

A new Ktable or Ktable5d instance with the same structure as self.

Return type
gindex(self, g)[source]

Finds the index corresponding to the given g

spectrum_to_plot(self, p=1e-05, t=200.0, x=1.0, g=None)[source]

provide the spectrum for a given point to be plotted

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• g (float) – Gauss point

• x (float) – Mixing ratio of the species

plot_distrib(self, ax, p=1e-05, t=200.0, wl=1.0, x=1.0, xscale=None, yscale='log', **kwarg)[source]

Plot the distribution for a given point

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• wl (float) – Wavelength (micron)

RandOverlap(self, other, x_self, x_other, write=0, use_rebin=False)[source]

Method to randomly mix the opacities of 2 species (self and other).

Parameters
• other (Ktable) – A Ktable object to be mixed with. Dimensions should be the same as self.

• x_self (float or array) – Volume mixing ratio of the first species

• x_other (float or array) – Volume mixing ratio of the species to be mixed with.

If one of these is None, the kcoeffs of the species in question are considered to be already normalized with respect to the mixing ratio.

Returns

array of k-coefficients for the mix.

Return type

array

bin_down(self, wnedges=None, weights=None, ggrid=None, remove_zeros=False, num=300, use_rebin=False, write=0)[source]

Method to bin down a kcoeff table to a new grid of wavenumbers (inplace).

Parameters
• wnedges (array) – Edges of the new bins of wavenumbers (cm-1) onto which the kcoeff should be binned down. if you want Nwnew bin in the end, wnedges.size must be Nwnew+1 wnedges[0] should be greater than self.wnedges[0] (JL20 not sure anymore) wnedges[-1] should be lower than self.wnedges[-1]

• weights (array, optional) – Desired weights for the resulting Ktable.

• ggrid (array, optional) – Desired g-points for the resulting Ktable. Must be consistent with provided weights. If not given, they are taken at the midpoints of the array given by the cumulative sum of the weights

remap_g(self, ggrid=None, weights=None)[source]

Method to resample a kcoeff table to a new g grid (inplace).

Parameters
• ggrid (array) – New grid of abcissas for quadrature

• weights (array) – New grid of weights

class Ktable5d(*filename_filters, filename=None, path=None, p_unit='unspecified', file_p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, search_path=None, mol=None, **kwargs)[source]

A class that handles tables of k-coefficients with a variable gas. Based on the Data_table class that handles basic operations common to Ktable and Xtable.

This class is specifically designed to deal with LMDZ type ktable where there is a variable gas.

Initializes k coeff table with variable gas and supporting data from various sources (see below by order of precedence)

Parameters
• filename (str (optional)) – Relative or absolute name of the file to be loaded.

• path (str) – If none of the above is specifed, path can point to a directory with a LMDZ type k coeff table. In this case, see read_LMDZ for the keywords to specify.

If there is no input, just creates an empty object to be filled later

See Ktable __init__ mehthod for documentation on p_unit, file_p_unit, kdata_unit, file_kdata_unit, remove_zeros, search_path, and mol arguments.

property shape(self)

Returns the shape of self.kdata

read_hdf5(self, filename=None, mol=None)[source]

Initializes k coeff table and supporting data from an Exomol hdf5 file

Parameters

filename (str) – Name of the input hdf5 file

write_hdf5(self, filename, compression='gzip', compression_level=9, kdata_unit=None, p_unit=None)[source]

Saves data in a hdf5 format

Parameters

filename (str) – Name of the file to be created and saved

read_LMDZ(self, path=None, res=None, band=None, mol=None)[source]

Initializes k coeff table and supporting data from a .dat file in a gcm friendly format.

Units are assumed to be cm^2 for kdata and mbar for pressure.

Parameters
• path (str) – Name of the directory with the various input files

• res (str) – “IRxVI” where IR and VI are the numbers of bands in the infrared and visible of the k table to load.

• band (str) – “IR” or “VI” to specify which band to load.

write_LMDZ(self, path, band='IR', fmt='%22.15e', write_only_metadata=False)[source]

Saves data in a LMDZ friendly format.

The gcm requires p in mbar and kdata in cm^2/molec. The conversion is done automatically.

Parameters
• path (str) – Name of the directory to be created and saved, the one that will contain all the necessary files

• band (str) – The band you are computing: ‘IR’ or ‘VI’

• fmt (str) – Fortran format for the corrk file.

• write_only_metadata (bool, optional) – If True, only supporting files are written (T.dat, p.dat, etc.)

hires_to_ktable(self, path=None, filename_grid=None, logpgrid=None, tgrid=None, xgrid=None, wnedges=None, quad='legendre', order=20, g_split=0.9, weights=None, ggrid=None, mid_dw=True, write=0, mol=None, grid_p_unit='Pa', p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, **kwargs)[source]

Computes a k coeff table from Hires_spectrum objects.

see exo_k.ktable.Ktable.hires_to_ktable() method for details on the arguments and options.

Other Parameters

xgrid (array) – Input grid in vmr of the variable gas. Needed for a Ktable5d.

Warning

By default, log pressures are specified in Pa in logpgrid!!! If you want to use another unit, do not forget to specify it with the grid_p_unit keyword.

setup_interpolation(self, log_interp=None)[source]

Creates interpolating functions to be called later on. and loads it as attribute (inplace).

set_kdata(self, new_kdata)[source]

Changes kdata (inplace). this is preferred to directly accessing kdata because one could forget to run setup_interpolation().

Parameters

new_kdata (array) – New array of kdata.

interpolate_kdata(self, logp_array=None, t_array=None, x_array=None, log_interp=None, wngrid_limit=None)[source]

interpolate_kdata interpolates the kdata at on a given temperature and log pressure profile.

Parameters
• logp_array (Array) – log 10 pressure array to interpolate to

• t_array (Array, same size a logp_array) – Temperature array to interpolate to

• x_array (Array, same size a logp_array) – vmr of variable gas array to interpolate to

• floats are given, they are interpreted as arrays of size 1. (If) –

• wngrid_limit (list or array, optional) – if an array is given, interpolates only within this array

• log_interp (bool, dummy) – Dummy variable to be consistent with interpolate_kdata in data_table. Whether the interpolation is linear in kdata or in log(kdata) is actually controlled by self._settings._log_interp but only when the ktable is loaded. If you change that after the loading, you should rerun setup_interpolation().

Returns

The interpolated kdata.

Return type

array of shape (logp_array.size, self.Nw , self.Ng)

remap_logPT(self, logp_array=None, t_array=None, x_array=None)[source]

remap_logPT re-interpolates the kdata on a new temprature and log pressure grid (inplace).

Parameters
• logp_array (Array) – log 10 pressure array to interpolate to

• t_array (Array) – temperature array to interpolate to

• x_array (Array) – vmr of variable gas array to interpolate to

Whether the interpolation is linear in kdata or in log(kdata) is controlled by self._settings._log_interp but only when the ktable is loaded. If you change that after the loading, you should rerun setup_interpolation().

copy(self, cp_kdata=True)[source]

Creates a new instance of Ktable5d object and (deep) copies data into it

Parameters

cp_kdata (bool, optional) – If false, the kdata table is not copied and only the structure and metadata are.

Returns

A new Ktable5d instance with the same structure as self.

Return type

Ktable

gindex(self, g)[source]

Finds the index corresponding to the given g

xindex(self, x)[source]

Finds the index corresponding to the given x

spectrum_to_plot(self, p=1e-05, t=200.0, x=1.0, g=None)[source]

provide the spectrum for a given point to be plotted

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• g (float) – Gauss point

• x (float) – Mixing ratio of the species

plot_distrib(self, ax, p=1e-05, t=200.0, wl=1.0, x=1.0, xscale=None, yscale='log', **kwarg)[source]

Plot the distribution for a given point

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• wl (float) – Wavelength (micron)

combine_with(self, other, x_self=None, x_other=None, **kwargs)[source]

Method to create a new Ktable5d where the kdata of ‘self’ are randomly mixed with ‘other’ (that must be a Ktable).

The main purpose is to add the opacity of a trace species to the background gas of the Ktable5d instance.

Warning

Because:

• the opacity from the background and variable gases cannot be isolated,

• The values of the array for the vmr of the variable gas (self.xgrid) are not modified (diluted),

the treatment here is valid only if x_other << 1.

For this reason, x_self should be either left to None, or 1-x_other depending exactly what you want to do. But if you put x_self<<1, you are on your own.

Parameters
• other (Ktable) – A Ktable object to be mixed with. Dimensions should be the same as self (except for xgrid).

• x_self (float only, optional) – Volume mixing ratio of self.

• x_other (float or array, optional) – Volume mixing ratio of the species to be mixed with (other).

If either x_self or x_other are set to None (default), the cross section of the species in question are considered to be already normalized with respect to the mixing ratio.

Returns

A new Ktable5d with the opacity of the new species added.

Return type

Ktable5d

bin_down(self, wnedges=None, weights=None, ggrid=None, remove_zeros=False, num=300, use_rebin=False, write=0)[source]

Method to bin down a kcoeff table to a new grid of wavenumbers (inplace).

Parameters
• wnedges (array) – Edges of the new bins of wavenumbers (cm-1) onto which the kcoeff should be binned down. if you want Nwnew bin in the end, wnedges.size must be Nwnew+1 wnedges[0] should be greater than self.wnedges[0] (JL20 not sure anymore) wnedges[-1] should be lower than self.wnedges[-1]

• weights (array, optional) – Desired weights for the resulting Ktable.

• ggrid (array, optional) – Desired g-points for the resulting Ktable. Must be consistent with provided weights. If not given, they are taken at the midpoints of the array given by the cumulative sum of the weights

clip_spectral_range(self, wn_range=None, wl_range=None)[source]

Limits the data to the provided spectral range (inplace):

• Wavenumber in cm^-1 if using wn_range argument

• Wavelength in micron if using wl_range

extend_spectral_range(self, **kwargs)[source]

Extends the spectral range of an existing table (inplace). The new bins are filled with zeros (except if remove_zeros=True).

See exo_k.data_table.Data_table.extend_spectral_range() method for details on the arguments and options.

remap_g(self, ggrid=None, weights=None)[source]

Method to resample a kcoeff table to a new g grid (inplace).

Parameters
• ggrid (array) – New grid of abcissas for quadrature

• weights (array) – New grid of weights

class Kdatabase(molecules, *str_filters, search_path=None, remove_zeros=True, **kwargs)[source]

This object contains mainly a dictionary of individual Ktable or Xtable objects for each molecule.

In addition, the informations about the P, T, Wn, g grids are reloaded as atributes of the Kdatabase object.

Initializes k coeff tables and supporting data from a list of molecules

Parameters
• molecules (list or dict) –

• If a list of molecules is provided, the file starting with the molecule name and containing all the str_filters are searched in the global search path defined in Settings.

• If a dictionary is provided, the keys are the molecules to load, and the values are the path to the corresponding file. If a None value is given, the str_filters will be used as above.

• search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path settings and only files in search_path are returned.

See also the options of Ktable

>>> Kdatabase(None)


Loads an empty database to be filled later with add_ktables().

Important

By default, Ktables have zeros removed when loaded to avoid log interpolation issues. You can avoid that with the remove_zeros=False keyword.

add_ktables(self, *ktables)[source]

Adds as many Ktable or Xtable to the database as you want (inplace).

Parameters

ktables (Ktable or Xtable objects) – Tables to be added.

copy(self)[source]

Creates a new instance of Kdatabase object and (deep) copies data into it

remap_logPT(self, logp_array=None, t_array=None)[source]

Applies the remap_logPT method to all the tables in the database (inplace). This can be used to put all the tables onthe same PT grid.

See exo_k.data_table.Data_table.remap_logPT() for details.

bin_down(self, wnedges=None, **kwargs)[source]

Applies the bin_down method to all the tables in the database (inplace). This can be used to put all the tables on the same wavenumber grid.

bin_down_cp(self, wnedges=None, **kwargs)[source]

Creates a copy of the database and bins it down.

Parameters

bin_down for details on parameters (See) –

Returns

The binned down database

Return type

Kdatabase object

sample(self, wngrid, **kwargs)[source]

Applies the sample method to all the tables in the database (inplace). This can be used to put all the tables onthe same wavenumber grid.

See Ktable.bin_down() or Xtable.bin_down() for details.

sample_cp(self, wngrid, **kwargs)[source]

Creates a copy of the database and re-samples it.

Parameters

sample for details on parameters (See) –

Returns

The re-sampled database

Return type

Kdatabase object

clip_spectral_range(self, wn_range=None, wl_range=None)[source]

Limits the data to the provided spectral range (inplace):

• Wavenumber in cm^-1 if using wn_range argument

• Wavelength in micron if using wl_range

convert_p_unit(self, p_unit='unspecified')[source]

Converts pressure unit of all Data_tables (inplace). See Data_table.convert_p_unit() for details.

convert_kdata_unit(self, kdata_unit='unspecified')[source]

Converts kdata unit of all Data_tables (inplace). See Data_table.convert_kdata_unit() for details.

convert_to_mks(self)[source]

Converts units of all Data_tables to MKS (inplace)

create_mix_ktable(self, composition, inactive_species=[])[source]

Creates a Ktable for a mix of molecules.

The table is computed over the P,T grid of the Kdatabase instance.

Parameters
• composition (dict) – Keys are the molecule names (they must match the names in the database). Values are either numbers or arrays of volume mixing ratios with shape (pgrid.size,tgrid.size). This composition will instantiate a Gas_mix object. In particular, if a value is ‘background’, this gas will be used to fill up to sum(vmr)=1 (See Gas_mix for details). For each (P,T) point, the sum of all the mixing ratios should be lower or equal to 1. If it is lower, it is assumed that the rest of the gas is transparent.

• inactive_species (list, optional) – List the gases that are in composition but for which we do not want the opacity to be accounted for.

Returns

A new ktable for the mix.

Return type

Ktable object

create_mix_ktable5d(self, bg_comp={}, vgas_comp={}, x_array=None, bg_inac_species=[], vgas_inac_species=[], **kwargs)[source]

Creates a Ktable5d for a mix of molecules with a variable gas. In essence, the regular create_mix_ktable is called to create two mixes:

• The background mix specified by composition=bg_comp, inactive_species=bg_inac_species

• The variable gas specified by composition=vgas_comp, inactive_species=vgas_inac_species

See create_mix_ktable() for details.

These two gases are then mixed together for an array of vmr x_array where var_gas has a vmr of x_array and the background gas has a vmr of 1.-x_array

Returns

A new ktable for the mix with a dimension for the vmr of the variable gas.

Return type

Ktable5d object

class Xtable(*filename_filters, filename=None, p_unit='unspecified', file_p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', remove_zeros=False, search_path=None, mol=None)[source]

A class that handles tables of cross sections.

Initializes cross section table and supporting data from a file based on its extension.

Parameters
• filename (str) – Relative or absolute path to the input file.

• filename_filters (sequence of string) – As many strings as necessary to uniquely define a file in the global search path defined in Settings. This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain ‘*’.

If there is no filename or filename_filters provided, just creates an empty object to be filled later

See Ktable __init__ mehthod for documentation on p_unit, file_p_unit, kdata_unit, file_kdata_unit, remove_zeros, search_path, and mol keywords.

read_hdf5(self, filename=None, mol=None)[source]

Initializes k coeff table and supporting data from an Exomol hdf5 file

Parameters
• filename (str) – Name of the input hdf5 file

• mol (str, optional) – Overrides the name of the molecule to be put in the Xtable object.

write_hdf5(self, filename, compression='gzip', compression_level=9, kdata_unit=None, p_unit=None, exomol_units=False)[source]

Saves data in a hdf5 format

Parameters
• filename (str) – Name of the file to be created and saved

• exomol_units (bool (optional)) – If True, data are converted back to cm^2 and bar units before being written.

read_exo_transmit(self, filename, mol=None)[source]

Creates an xsec object from an exo_transmit like spectra. See https://github.com/elizakempton/Exo_Transmit or Kempton et al. (2016) for details. Pressures are expected to be in Pa and cross sections in m^2/molecule

Parameters
• filename (str) – Name of the input file.

• mol (str) – Overrides the name of the molecule to be put in the Xtable object.

hires_to_xtable(self, path=None, filename_grid=None, logpgrid=None, tgrid=None, write=0, mol=None, grid_p_unit='Pa', p_unit='unspecified', kdata_unit='unspecified', file_kdata_unit='unspecified', **kwargs)[source]

Loads an Xtable from high-resolution spectra (inplace).

Warning

By default, log pressures are specified in Pa in logpgrid!!! If you want to use another unit, do not forget to specify it with the grid_p_unit keyword.

see exo_k.ktable.Ktable.hires_to_ktable() method for details on the arguments and options.

bin_down(self, wnedges=None, remove_zeros=False, write=0)[source]

Method to bin down a xsec table to a new grid of wavenumbers (inplace).

Parameters
• wnedges (array) – Edges of the new bins of wavenumbers (cm-1) onto which the xsec should be binned down. if you want Nwnew bin in the end, wngrid.size must be Nwnew+1 wnedges[0] should be greater than self.wnedges[0] wnedges[-1] should be lower than self.wnedges[-1]

• remove_zeros (bool, optional) – If True, remove zeros in kdata.

sample(self, wngrid, remove_zeros=False, log_interp=None)[source]

Method to re sample a xsec table to a new grid of wavenumbers (inplace).

Parameters

wngrid (array) – Location of the new wavenumbers points (cm-1)

sample_cp(self, wngrid, **kwargs)[source]

Creates a copy of the instance before resampling it.

Parameters

sample method for details. (See) –

Returns

the re-sampled Xtable

Return type

Xtable object

spectrum_to_plot(self, p=1e-05, t=200.0, x=1.0, g=None)[source]

provide the spectrum for a given point to be plotted

Parameters
• p (float) – Pressure (Ktable pressure unit)

• t (float) – Temperature(K)

• x (float) – Volume mixing ratio of the species

• g (is unused but here to be consistent with the method in data_table) –

copy(self, cp_kdata=True)[source]

Creates a new instance of Xtable object and (deep) copies data into it

Parameters

cp_kdata (bool, optional) – If false, the kdata table is not copied and only the structure and metadata are.

Returns

A new Xtable instance with the same structure as self.

Return type

Xtable

property shape(self)

Returns the shape of self.kdata

read_pickle(self, filename=None)[source]

Initializes xsec table and supporting data from an Exomol pickle file

Parameters
• filename (str) – Relative or absolute name of the input pickle file

• mol (str, optional) – Overrides the name of the molecule to be put in the Xtable object.

write_pickle(self, filename)[source]

Saves data in a pickle format

Parameters

filename (str) – Relative or absolute name of the file to be created and saved

class Atable(*filename_filters, filename=None, aerosol_name=None, search_path=None, mks=False, remove_zeros=False)[source]

A class to handle aerosol optical properties in table form.

Initialization for Atables.

Parameters
• filename (str, optional) – Relative or absolute name of the file to be loaded.

• filename_filters (sequence of string) – As many strings as necessary to uniquely define a file in the global search path defined in Settings. This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain ‘*’.

Other Parameters

search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path in Settings and only files in search_path are returned.

read_LMDZ(self, filename, aerosol_name=None)[source]

Reads LMDZ like optical propertt files.

Parameters

filename (str) – Name of the file to be read.

read_hdf5(self, filename, aerosol_name=None)[source]

Reads hdf5 cia files and load temperature, wavenumber, and absorption coefficient grid.

Parameters

filename (str) – Name of the file to be read.

write_hdf5(self, filename)[source]

Writes hdf5 cia files.

Parameters

filename (str) – Name of the file to be written.

sample(self, wngrid, remove_zeros=False, use_grid_filter=False, sample_all_vars=False, **kwargs)[source]

Method to re sample a Atable to a new grid of wavenumbers (in place)

Parameters
• wngrid (array) – new wavenumber grid (cm-1)

• use_grid_filter (boolean, optional) – If true, the table is sampled only within the boundaries of its current wavenumber grid. The coefficients are set to zero elswere (except if remove_zeros is set to True). If false, the values at the boundaries are used when sampling outside the grid.

• sample_all_vars (boolean, optional) – Whether to sample the single_scattering albedo and asymmetry_factor as well.

sample_cp(self, wngrid, **kwargs)[source]

Creates a copy of the object before resampling it.

Parameters

sample method for details. (See) –

Returns

the re-sampled Atable

Return type

Atable object

interpolate_optical_properties(self, r_array=None, var_type=0, log_interp=None, wngrid_limit=None)[source]

interpolate_cia interpolates the kdata at on a given temperature profile.

Parameters
• r_array (float or array) – Effective radius array to interpolate to. If a float is given, it is interpreted as an array of size 1.

• data_id (int) –

type of data to interpolate:
• 0 is extinction coefficient

• 1 is single scattering albedo

• 2 is asymmetry factor

• wngrid_limit (array, optional) – If an array is given, interpolates only within this array.

• log_interp (bool, optional) – Whether the interpolation is linear in kdata or in log(kdata).

cross_section(self, r_array, wngrid_limit=None, log_interp=None)[source]

Computes the cross section due to the aerosol in area per particles.

Parameters

r_array (float or array) – Effective radius array to interpolate to. If a float is given, it is interpreted as an array of size 1.

Other Parameters
• wngrid_limit (array, optional) – If an array is given, interpolates only within this array.

• log_interp (bool, optional) – Whether the interpolation is linear in kdata or in log(kdata).

absorption_coefficient(self, r_array, n_density, wngrid_limit=None, log_interp=None)[source]

Computes the cross section due to the aerosol in area per particles.

Parameters
• r_array (float or 1d array) – Effective radius array to interpolate to. If a float is given, it is interpreted as an array of size 1.

• n_density (float or 1d array (same dim as r_array)) – Number density of aerosol

Other Parameters
• wngrid_limit (array, optional) – If an array is given, interpolates only within this array.

• log_interp (bool, optional) – Whether the interpolation is linear in kdata or in log(kdata).

plot_spectrum(self, ax, r=1e-06, x_axis='wls', xscale=None, yscale=None, var_type=0, **kwarg)[source]

Plot the spectrum for a given point

Parameters
• ax (pyplot.Axes) – A pyplot axes instance where to put the plot.

• r (float) – Effective radius (m)

• x_axis (str, optional) – If ‘wls’, x axis is wavelength. Wavenumber otherwise.

• x/yscale (str, optional) – If ‘log’ log axes are used.

convert_to_mks(self)[source]

Converts units to MKS

rindex(self, r)[source]

Finds the index corresponding to the given radius r (units must be the same as the ktable)

remove_zeros(self, deltalog_min_value=0.0)[source]

Finds zeros in the ext_coeff and set them to (10.^-deltalog_min_value) times the minimum positive value in the table. This is to be able to work in logspace.

copy(self)[source]

Creates a new instance of Atable object and (deep) copies data into it

combine_tables(aerosol_name, *atables)[source]

Combine several tables representing the same aerosol type for different wavelength range.

class Adatabase(*str_filters, filenames=None, remove_zeros=False, **kwargs)[source]

Class to group Atable objects and combine them in radiative transfer

Initializes aerosol tables and supporting data from a list of filenames.

Parameters

filenames (list) – List of names (not full path) of the input cia files. The files must be in the global search path.

A local search path can be specified with ‘search_path=’

See the options of Atable __init__ method.

add_atables(self, *atables)[source]

Adds new Atable objects to a Adatabase.

Parameters

atables (Atable) – As many Atables as you want.

property names(self)

Gives the names of the aerosols in the database

copy(self)[source]

Creates a new instance of CIAdatabase object and (deep) copies data into it

sample(self, wngrid, remove_zeros=True, use_grid_filter=True, sample_all_vars=False)[source]

Samples all the Atables in the database on the same wavenumber grid to be able to use them in radiative transfer modules.

Important

For this method, the default options are remove_zeros=True and use_grid_filter=True. This ensures that you do not count several contributinns twice when you use two different aerosol tables to represent the same aerosol type over two different spectral window (typically VI and IR)

Parameters

wngrid (array) – new wavenumber grid (cm-1)

See :func:exo_k.atable.Atable.sample for further details on options.

convert_to_mks(self)[source]

Converts units of all Cia_tables to MKS.

absorption_coefficient(self, aer_reffs_densities, wngrid_limit=None, log_interp=None)[source]

Computes the absorption coefficient in m^-1 for the whole mix specified (assumes data in MKS).

Parameters
• aer_reffs_densities (dict) – A dictionary with aerosol names as keys and lists containing 2 floats (or arrays) as values. The values are the particle effective radii and number densities.

• wngrid_limit (array, optional) – Smaller and bigger wavenumbers inside which to perform the calculation.

Returns

The effective cross section coefficient profile for the aerosols (in m^2).

Return type

array

class Cia_table(*filename_filters, filename=None, molecule_pair=None, search_path=None, mks=False, remove_zeros=False, old_cia_unit='cm^5')[source]

A class to handle CIA opacity data tables.

Initialization for Cia_tables.

Parameters
• filename (str, optional) – Relative or absolute name of the file to be loaded.

• filename_filters (sequence of string) – As many strings as necessary to uniquely define a file in the global search path defined with exo_k.settings.Settings.set_cia_search_path(). This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain ‘*’.

• molecule_pair (list of size 2, optional) – The molecule pair we want to consider, specified as an array with two strings (like [‘H2’,’H2’] or [‘N2’,’H2O’]). The order of the molecules in the pair is irrelevant.

Other Parameters
• old_cia_unit (str, optional) – String to specify the current cia unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the cia grid and the cia unit do not correspond). Available units are: ‘cm^5’, ‘cm^2’ that stand for cm^2/amagat, and ‘cm^-1’ that stand for cm^-1/amagat^2.

• remove_zeros (boolean, optional) –

If True, the zeros in the kdata table are replaced by

a value 10 orders of magnitude smaller than the smallest positive value

• search_path (str, optional) – If search_path is provided, it locally overrides the global search path defined with exo_k.settings.Settings.set_cia_search_path() and only files in search_path are returned.

read_hitran_cia(self, filename, old_cia_unit='cm^5')[source]

Reads hitran cia files and load temperature, wavenumber, and absorption coefficient grid.

Parameters
• filename (str) – Name of the file to be read.

• old_cia_unit (str, optional) – Units found in the file.

read_hdf5(self, filename)[source]

Reads hdf5 cia files and load temperature, wavenumber, and absorption coefficient grid.

Parameters

filename (str) – Name of the file to be read.

write_hdf5(self, filename)[source]

Writes hdf5 cia files.

Parameters

filename (str) – Name of the file to be written.

sample(self, wngrid, remove_zeros=False, use_grid_filter=False, **kwargs)[source]

Method to re sample a cia table to a new grid of wavenumbers (inplace).

Parameters
• wngrid (array) – new wavenumber grid (cm-1)

• use_grid_filter (boolean, optional) – If true, the table is sampled only within the boundaries of its current wavenumber grid. The coefficients are set to zero elswere (except if remove_zeros is set to True). If false, the values at the boundaries are used when sampling outside the grid.

sample_cp(self, wngrid, **kwargs)[source]

Creates a copy of the object before resampling it.

Parameters

sample method for details. (See) –

Returns

the re-sampled Cia_table

Return type

Cia_table object

interpolate_cia(self, t_array=None, log_interp=None, wngrid_limit=None)[source]

interpolate_cia interpolates the kdata at on a given temperature profile.

Parameters
• t_array (float or array) – Temperature array to interpolate to. If a float is given, it is interpreted as an array of size 1.

• wngrid_limit (array, optional) – If an array is given, interpolates only within this array.

• log_interp (bool, optional) – Whether the interpolation is linear in kdata or in log(kdata).

Returns

The interpolated kdata.

Return type

array of shape (logp_array.size, self.Nw)

equivalent_xsec(self, logP, T, x_mol2, wngrid_limit=None)[source]

Computes the cross section due to CIA in area per molecule of type 1.

effective_cross_section(self, logP, T, x_mol1, x_mol2, wngrid_limit=None)[source]

Computes the total cross section for a molecule pair (in m^2 per total number of molecules; assumes data in MKS).

Parameters
• logP (float or array) – Log10 of the pressure (Pa).

• T (float or array) – Temperature (K).

• x_mol1/2 (float or array) – Volume mixing ratio of the 1st and 2nd molecule of the pair.

• wngrid_limit (array, optional) – If an array is given, interpolates only within this array.

Returns

total cross section for the molecule pair in m^2 per total number of molecules.

Return type

float or array

plot_spectrum(self, ax, t=200.0, x_axis='wls', xscale=None, yscale=None, **kwarg)[source]

Plot the spectrum for a given point

Parameters
• ax (pyplot.Axes) – A pyplot axes instance where to put the plot.

• t (float) – temperature(K)

• x_axis (str, optional) – If ‘wls’, x axis is wavelength. Wavenumber otherwise.

• x/yscale (str, optional) – If ‘log’ log axes are used.

convert_abs_coeff_unit(self, abs_coeff_unit='unspecified', old_abs_coeff_unit='unspecified')[source]

Converts abs_coeff to a new unit (inplace).

Parameters
• abs_coeff_unit (str) – String to identify the units to convert to. Accepts ‘cm^5’, ‘m^5’. or any length^5 unit recognized by the astropy.units library. If =’unspecified’, no conversion is done.

• old_abs_coeff_unit (str, optional) – String to specify the current kdata unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the kdata grid and the kdata unit do not correspond)

convert_to_mks(self)[source]

Converts units to MKS

remove_zeros(self, deltalog_min_value=0.0)[source]

Finds zeros in the abs_coeff and set them to (10.^-deltalog_min_value) times the minimum positive value in the table (inplace). This is to be able to work in logspace.

copy(self)[source]

Creates a new instance of CIA_table object and (deep) copies data into it

read_CKD_cia(self, filename, old_cia_unit='cm^2')[source]

Reads hitran cia files and load temperature, wavenumber, and absorption coefficient grid.

Parameters

filename (str) – Name of the file to be read.

effective_cross_section2(self, logP, T, x_mol1, x_mol2, wngrid_limit=None)[source]

Obsolete.

Computes the total cross section for a molecule pair (in m^2 per total number of molecules; assumes data in MKS).

class CIAdatabase(*str_filters, filenames=None, molecule_pairs=None, molecules=None, remove_zeros=True, **kwargs)[source]

Class to group Cia_table objects and combine them in radiative transfer

Initializes cia tables and supporting data. The files to load can be specified either using (in order of precedence) a list of filenames, molecule pairs, or molecules. See below for details.

Any number of filters (strings) can be provided to refine the search to files whose names contain the filters.

Parameters
• filenames (list, optional) – List of names (not full path) of the input cia files. The files must be in the global search path.

• molecule_pairs (list of size 2 lists, optional) – List of the molecule pairs we want to consider, specified as an array with two strings (like [‘H2’,’H2’] or [‘N2’,’H2O’]). The order of the molecules in the pair is irrelevant.

• molecules (list of strings, optional) – A list of all the molecules we want to consider. Exo_k will look for all the possible pairs for which a cia file is found.

The default path searched is set with exo_k.settings.Settings.set_cia_search_path() or add_cia_search_path(). A local search path can be specified with the search_path keyword.

See the options of Cia_table __init__ method.

add_cia_tables(self, *cia_tables)[source]

Adds new Cia_table objects to a CIA database (inplace).

Parameters

cia_tables (Cia_table) – As many cia tables as you want.

copy(self)[source]

Creates a new instance of CIAdatabase object and (deep) copies data into it

sample(self, wngrid, remove_zeros=False, use_grid_filter=False)[source]

Samples all the cia_table in the database on the same wavenumber grid to be able to use them in radiative transfer modules (inplace).

Parameters

wngrid (array) – new wavenumber grid (cm-1)

See :func:exo_k.cia_table.Cia_table.sample for further details on options.

convert_to_mks(self)[source]

Converts units of all Cia_tables to MKS (inplace).

cia_cross_section(self, logP_array, T_array, gas_comp, wngrid_limit=None)[source]

Computes the absorption coefficient in m^-1 for the whole mix specified (assumes data in MKS).

Parameters
• logP_array (array) –

• T_array (array) – log10 Pressure (Pa) and temperature profiles

• gas_comp (Gas_mix object) – behaves like a dict with mol names as keys and vmr as values.

• wngrid_limit (array, optional) – Smaller and bigger wavenumbers inside which to perform the calculation.

Returns

The cia effective cross section coefficient profile for the whole gas (in m^2).

Return type

array

class Hires_spectrum(filename, file_kdata_unit='unspecified', kdata_unit='unspecified', mult_factor=None, binary=False, **kwargs)[source]

A class defining a Hires_spectrum object.

Reads a high-resolution spectrum from a file (either hdf5 or ascii).

Parameters
• filename (str) – Full pathname to the file. Extension defines the format used.

• file_kdata_unit (str) – Specifies the unit for the opacity data in the file. This is needed for ascii formats as the units are not known. The type of quantity may differ whether we are handling cross sections (surface) or absorption coefficients (inverse length)

• kdata_unit (str) – Unit to convert to.

• mult_factor (float) – A multiplicative factor that can be applied to kdata (for example to correct for any dilution effect, or specific conversion).

see read_ascii() for additional arguments to use with ascii files

read_ascii(self, filename, data_type=None, skiprows=0, wn_column=None, kdata_column=None)[source]

Parameters
• filename (str) – Initial hires-spectrum filename.

• data_type ('xsec' or 'abs_coeff') – Whether the data read are cross-sections or absorption coefficients.

• skiprows (int, optional) – Number of header lines to skip. For the latest Kspectrum format, the header is skipped automatically.

• wn_column/kdata_column (int, optional) – Number of column to be read for wavenumber and kdata in python convention (0 is first, 1 is second, etc.)

write_hdf5(self, filename)[source]

Writes kspectrum file to hdf5

read_hdf5(self, filename)[source]

read_binary(self, filename, mass_amu=None)[source]

Assumed to be in cm^2/g with wavelength in cm.

Will be automatically converted to cm^2/molecule and wns in cm^-1 (unless conversion to mks is requested).

convert_kdata_unit(self, kdata_unit='unspecified', file_kdata_unit='unspecified')[source]

Converts kdata to a new unit (inplace)

Parameters
• kdata_unit (str) – String to identify the units to convert to. Accepts ‘cm^2’, ‘m^2’ or any surface unit recognized by the astropy.units library. If =’unspecified’, no conversion is done. In general, kdata should be kept in ‘per number’ or ‘per volume’ units (as opposed to ‘per mass’ units) as composition will always be assumed to be a number or volume mixing ratio. Opacities per unit mass are not supported yet. Note that you do not need to specify the ‘/molec’ or ‘/molecule’ in the unit.

• file_kdata_unit (str) – String to specify the current kdata unit if it is unspecified or if you have reasons to believe it is wrong (e.g. you just read a file where you know that the kdata grid and the kdata unit do not correspond)

plot_spectrum(self, ax, x_axis='wls', xscale=None, yscale=None, x=1.0, **kwarg)[source]

Plot the spectrum

Parameters
• ax (pyplot.Axes) – A pyplot axes instance where to put the plot.

• x_axis (str, optional) – If ‘wls’, x axis is wavelength. Wavenumber otherwise.

• x/yscale (str, optional) – If ‘log’ log axes are used.

convert_data_type(self, pressure, temperature, kdata_unit=None, convert_to=None)[source]

Converts from one data_type (cross sections or absorption coefficents) to the other (inplace).

Conversion to mks is done by default if a conversion takes place and no kdata_unit is specified.

Parameters
• pressure (float) – Pressure used for the conversion (in Pa)

• temperature (float) – Temperature used for the conversion (in K)

• kdata_unit (str (optional)) – Unit to use for the output

• convert_to (str ('xsec' or 'abs_coeff', optional)) – Data type to convert to. Nothing is done if convert_to is equal to self.data_type. If None, converts to the other type.

clip_spectral_range(self, wn_range=None, wl_range=None)[source]

Limits the data to the provided spectral range (inplace):

• Wavenumber in cm^-1 if using wn_range argument

• Wavelength in micron if using wl_range

class Atm_profile(composition={}, psurf=None, ptop=None, logplev=None, tlev=None, Tsurf=None, Tstrat=None, grav=None, Rp=None, Mgas=None, rcp=0.28, Nlev=20)[source]

Bases: object

A class defining an atmospheric PT profile with some global data (gravity, etc.)

The derived class Atm handles radiative transfer calculations.

Initializes atmospheric profiles

Parameters
• composition (dict) – Keys are molecule names and values the vmr. Vmr can be arrays of size Nlev-1 (i.e. the number of layers).

• grav (float) – Planet surface gravity (gravity constant with altitude for now).

• Rp (float or Astropy.unit quantity) – Planet radius. If float, Jupiter radii are assumed.

• rcp (float) – Adiabatic lapse rate for the gas (R/cp)

• Mgas (float, optional) – Molar mass of the gas (kg/mol). If given, overrides the molar mass computed from composition.

There are two ways to define the profile. Either define:

• Nlev: int Number of level interfaces (Number of layers is Nlev-1)

• psurf, Tsurf: float Surface pressure (Pa) and temperature

• ptop: float Pressure at the top of the model (Pa)

• Tstrat: float Stratospheric temperature

or:

• logplev: array

• tlev: array (same size) These will become the pressures (Pa) and temperatures at the level interfaces. This will be used to define the surface and top pressures. Nlev becomes the size of the arrays.

Warning

Layers are counted from the top down (increasing pressure order). All methods follow the same convention.

set_logPT_profile(self, log_plev, tlev)[source]

Set the logP-T profile of the atmosphere with a new one

Parameters
• log_plev (numpy array) – Log pressure (in Pa) at the level surfaces

• tlev (numpy array (same size)) – temperature at the level surfaces.

set_adiab_profile(self, Tsurf=None, Tstrat=None, rcp=0.28)[source]

Initializes the logP-T atmospheric profile with an adiabat with index R/cp=rcp

Parameters
• Tsurf (float) – Surface temperature.

• Tstrat (float, optional) – Temperature of the stratosphere. If None is given, an isothermal atmosphere with T=Tsurf is returned.

• rcp (float) – R/c_p of the atmosphere

set_grav(self, grav=None)[source]

Sets the surface gravity of the planet

Parameters

grav (float) – surface gravity (m/s^2)

set_gas(self, composition_dict)[source]

Sets the composition of the atmosphere

Parameters
• composition_dict (dictionary) – Keys are molecule names, and values are volume mixing ratios. A ‘background’ value means that the gas will be used to fill up to vmr=1 If they do not add up to 1 and there is no background gas_mix, the rest of the gas_mix is considered transparent.

• compute_col_dens (boolean, optional) – If True, the column density per layer of the atmosphere is recomputed. This si mostly to save time when we know this will be done later on.

set_Mgas(self, Mgas=None)[source]

Sets the mean molar mass of the atmosphere.

Parameters

Mgas (float or array of size Nlay) – Mean molar mass (kg/mol). If None is give, the mmm is computed from the composition.

set_rcp(self, rcp)[source]

Sets the adiabatic index of the atmosphere

Parameters

rcp (float) – R/c_p

set_Rp(self, Rp)[source]

Sets the radius of the planet

Parameters

Rp (float) – radius of the planet (m)

set_Rstar(self, Rstar)[source]

Sets the radius of the star

Parameters

Rstar (float) – radius of the star (m)

compute_density(self)[source]

Computes the number density (m^-3) profile of the atmosphere

compute_layer_col_density(self)[source]

Computes the column number density (molecules/m^-2) per layer of the atmosphere

compute_altitudes(self)[source]

Compute altitudes of the level surfaces (zlev) and mid layers (zlay).

compute_area(self)[source]

Computes the area of the annulus covered by each layer in a transit setup.

compute_tangent_path(self)[source]

Computes a triangular array of the tangent path length (in m) spent in each layer. self.tangent_path[ilay][jlay] is the length that the ray that is tangent to the ilay layer spends in the jlay>=ilay layer (accounting for a factor of 2 due to symmetry)

class Atm(k_database=None, cia_database=None, wn_range=None, wl_range=None, **kwargs)[source]

Class based on Atm_profile that handles radiative trasnfer calculations.

Radiative data are accessed through the gas_mix.Gas_mix class.

Initialization method that calls Atm_Profile().__init__() and links to Kdatabase and other radiative data.

set_k_database(self, k_database=None)[source]

Change the radiative database used by the Gas_mix object handling opacities inside Atm.

See gas_mix.Gas_mix.set_k_database for details.

Parameters

k_database (Kdatabase object) – New Kdatabase to use.

set_cia_database(self, cia_database=None)[source]

Change the CIA database used by the Gas_mix object handling opacities inside Atm.

See gas_mix.Gas_mix.set_cia_database for details.

Parameters

cia_database (CIAdatabase object) – New CIAdatabase to use.

set_spectral_range(self, wn_range=None, wl_range=None)[source]

Sets the spectral range in which computations will be done by specifying either the wavenumber (in cm^-1) or the wavelength (in micron) range.

See gas_mix.Gas_mix.set_spectral_range for details.

opacity(self, **kwargs)[source]

Computes the opacity of each of the layers.

See gas_mix.Gas_mix.cross_section for details.

emission_spectrum(self, integral=True, mu0=0.5, mu_quad_order=None, **kwargs)[source]

Returns the emission flux at the top of the atmosphere (in W/m^2/cm^-1)

Parameters

integral (boolean, optional) –

• If true, the black body is integrated within each wavenumber bin.

• If not, only the central value is used. False is faster and should be ok for small bins, but True is the correct version.

Other Parameters
• mu0 (float) – Cosine of the quadrature angle use to compute output flux

• mu_quad_order (int) – If an integer is given, the emission intensity is computed for a number of angles and integrated following a gauss legendre quadrature rule of order mu_quad_order.

Returns

A spectrum with the Spectral flux at the top of the atmosphere (in W/m^2/cm^-1)

Return type

Spectrum object

emission_spectrum_quad(self, integral=True, mu_quad_order=3, **kwargs)[source]

Returns the emission flux at the top of the atmosphere (in W/m^2/cm^-1) using gauss legendre qudrature of order mu_quad_order

Parameters

integral (boolean, optional) –

• If true, the black body is integrated within each wavenumber bin.

• If not, only the central value is used. False is faster and should be ok for small bins, but True is the correct version.

Returns

A spectrum with the Spectral flux at the top of the atmosphere (in W/m^2/cm^-1)

Return type

Spectrum object

exp_minus_tau(self)[source]

Sums Exp(-tau) over gauss points

exp_minus_tau_g(self, g_index)[source]

Sums Exp(-tau) over gauss points

surf_bb(self, integral=True)[source]

Computes the surface black body flux (in W/m^2/cm^-1)

Parameters

integral (boolean, optional) –

• If true, the black body is integrated within each wavenumber bin.

• If not, only the central value is used. False is faster and should be ok for small bins, but True is the correct version.

Returns

Spectral flux at the surface (in W/m^2/cm^-1)

Return type

Spectrum object

top_bb(self, integral=True)[source]

Computes the top of atmosphere black body flux (in W/m^2/cm^-1)

Parameters

integral (boolean, optional) –

If true, the black body is integrated within each wavenumber bin. If not, only the central value is used.

False is faster and should be ok for small bins, but True is the correct version.

Returns

Spectral flux of a bb at the temperature at the top of atmosphere (in W/m^2/cm^-1)

Return type

Spectrum object

transmittance_profile(self, **kwargs)[source]

Computes the transmittance profile of an atmosphere, i.e. Exp(-tau) for each layer of the model. Real work done in the numbafied function path_integral_corrk/xsec depending on the type of data.

transmission_spectrum(self, normalized=False, Rstar=None, **kwargs)[source]

Computes the transmission spectrum of the atmosphere. In general (see options below), the code returns the transit depth:

delta_nu=(pi*Rp^2+alpha_nu)/(pi*Rstar^2).

where

alpha_nu=2*pi*Int_0^zmax (Rp+z)*(1-exp(-tau_nu(z))) dz

Parameters
• Rstar (float, optional) – Radius of the host star. Does not need to be given here if as already been specified as an attribute of the self.Atm object. If specified, the result is the transit depth: delta_nu=(pi*Rp^2+alpha_nu)/(pi*Rstar^2).

• normalized (boolean, optional) –

Used only if self.Rstar and Rstar are None. * If true, the result is normalized to the planetary radius:

delta_nu=1+alpha_nu/(pi*Rp^2).

• If False, delta_sigma=1+(h_sigma/R_planet)^2. delta_nu=pi*Rp^2+alpha_nu.

Returns

The transit spectrum (see above for normalization options).

Return type

array

heating_rate(self, Fin=1.0, Tstar=5570.0, szangle=60.0, **kwargs)[source]

Computes the heating rate in the atmosphere

Parameters
• Fin (float) – Bolometric stellar flux at the top of atmopshere (W/m^2).

• Tstar (float) – Stellar temperature

• szangle (float) – Solar zenith angle

Returns

Heating rate in each atmospheric layer (K/s).

Return type

array

emission_spectrum_exp_integral(self, integral=True, **kwargs)[source]

Computes the emission flux at the top of the atmosphere (in W/m^2/cm^-1)

Warning

This method uses a formulation with exponential integrals that is not yet perceived as accurate enough by the author. It is left for testing only.

Parameters

integral (boolean, optional) –

• If true, the black body is integrated within each wavenumber bin.

• If not, only the central value is used. False is faster and should be ok for small bins, but True is the correct version.

Returns

A spectrum with the Spectral flux at the top of the atmosphere (in W/m^2/cm^-1)

Return type

Spectrum object

class EquChemTable(filename=None, remove_zeros=False)[source]

Bases: object

Class to load and interpolate chemistry data.

Initializes chemical composition tables from various init files

Parameters

filename (str) – Name of the input file

read_composition_in(self, filename=None, remove_zeros=False, skiprows=7)[source]

Initializes chemical composition tables from composition.in files

Parameters
• filename (str) – Name of the input file

• skiprows (int, optional) – Number of lines to skip in the file

read_composition_dat(self, filename=None, remove_zeros=False, skiprows=1)[source]

Initializes chemical composition tables from composition.in files

Parameters
• filename (str) – Name of the input file

• skiprows (int, optional) – Number of lines to skip in the file

remove_zeros(self, deltalog_min_value=30.0)[source]

Finds zeros in the chem data and set them to (10.^-deltalog_min_value) times the minimum positive value in the table. This is to be able to work in logspace.

setup_interpolation(self)[source]

Creates interpolating functions to be called later on.

vmr(self, logP, T, mol)[source]

Interpolates a single molecule on a logP-T value

interpolate_vmr(self, logp_array=None, t_array=None, mols=None, grid=False)[source]

Interpolates all molecules in mols on a logP-T grid

class Gas_mix(composition={}, bg_gas=None, logp_array=None, t_array=None, k_database=None, cia_database=None)[source]

Dict-like class to handle gas composition (with background gas) and molar mass.

If logp_array, t_array, and radiative databases are provided, cross_section can be used to compute the opacity of the gas

__init_ Instantiates a Gas_mix object and computes the vmr of the ‘background’ gas.

set_composition(self, composition, bg_gas=None)[source]

Reset composition and computes the vmr of the ‘background’ gas.

Parameters
• composition (dict) – Keys are molecule names. Values are vmr or arrays of vmr.

• bg_gas (str) – Name of the background molecule. If None, it is inferred from the molecule for which vmr=’background’.

set_logPT(self, logp_array=None, t_array=None)[source]

Sets the pressure (in Pa) and temperature fields.

get_background_vmr(self)[source]

Computes the volume mixing ratio of the background gas in a mix Uses the fact that self.composition is a dictionary with the name of the molecules as keys and the vmr as values. vmr are either float or arrays.

At this stage, the background gas should be identified by self.bg_gas, and its Vol. Mix. Ratio will be updated in the composition dict.

molar_mass(self)[source]

Computes and returns the molar mass of a mix of gases

Returns

Molar mass of the active gases in kg/mol

Return type

float or array

get_vmr_array(self, sh=None)[source]

Returns a dictionary with an array of vol. mix. ratios for each species.

Parameters

sh (set or list) – shape of the array wanted if all the vmr are floats. If some are already arrays, check whether the shape is the correct one.

Returns

• res (dict) – A dictionary with the an array of vmr per species.

• cst_array (boolean) – Is True if all the values in the arrays are constant.

set_k_database(self, k_database=None)[source]

Change the radiative database attached to the current instance of Gas_mix

Parameters

k_database (Kdatabase object) – New Kdatabase to use.

set_cia_database(self, cia_database=None)[source]

Changes the CIA database attached to the current instance of Gas_mix

Parameters

cia_database (CIAdatabase object) – New CIAdatabase to use.

set_spectral_range(self, wn_range=None, wl_range=None)[source]

Sets the default spectral range in which computations will be done by specifying either the wavenumber or the wavelength range.

Parameters
• wn_range (list or array of size 2) – Minimum and maximum wavenumber (in cm^-1).

• wl_range (list or array of size 2) – Minimum and maximum wavelength (in micron)

cross_section(self, composition=None, logp_array=None, t_array=None, wl_range=None, wn_range=None, rayleigh=True, write=0, random_overlap=False, logp_interp=True, **kwargs)[source]

Computes the cross section (m^2/total number of molecule) for the mix at each of the logPT points as a function of wavenumber (and possibly g point).

Parameters
• wl_range (array or list of two values, optional) – Wavelength range to cover.

• wn_range (array or list of two values, optional) – Wavenumber range to cover.

• rayleigh (boolean, optional) – Whether to compute rayleigh scattering.

• random_overlap (boolean, optional) – Whether Ktable opacities are added linearly (False), or using random overlap method (True).

Returns

kdata_array – Cross section array of shape (layer number, Nw (, Ng if corrk)).

Return type

array

After every computation, the following variables are updated to account for any possible change in spectral range:

• self.Nw, Number of wavenumber bins

• self.wns, Wavenumber array

• self.wnedges, Wavenumber of the edges of the bins

items(self)[source]

Emulates dict.items() method

values(self)[source]

Emulates dict.values() method

keys(self)[source]

Emulates dict.keys() method

copy(self)[source]

Deep copy of the dict and arrays. The databases are not deep copied.

abstract mix_with(self, other_gas, vmr_other_gas)[source]

Mix with other Gas_mix.

class Settings[source]

A class based on a singleton to store global options only once for every instance.

So all the following methods can be called using the following syntax:

>>> exo_k.Settings().method_name(agrs)


In gerneal, they will change internal global attributes that change the global behavior of some routines in the library.

init(self, *args, **kwds)[source]
reset_search_path(self, path_type='all', no_path=False)[source]

Set default search path.

Parameters
• path_type (str) – What type of path to reset. Possibilities are ‘all’ (default), ‘kdata’, ‘cia’, and ‘aerosol’

• no_path (bool (optional)) – If False (default), the search path is reset to ‘.’. If True, empties the search path.

add_search_path(self, *search_paths, path_type='kdata')[source]

Add path(s) to the list of paths that will be searched for various files.

Parameters
• search_path (string or list of strings) – Search path(s) to look for opacities.

• path_type (str) –

What type of path to change. Possibilities are:
• ’kdata’ (default): global xsec and corr-k search path

• ’ktable’ : only corr-k files

• ’xtable’ : only cross section files

• ’cia’: search path for CIA files

• ’aerosol’: search path for Aerosol optical property files

Examples

>>> exo_k.Settings().add_search_path('data/xsec','data/corrk')
>>> exo_k.Settings().search_path()
['/your/path/to/exo_k',
'/your/path/to/exo_k/data/xsec',
'/your/path/to/exo_k/data/corrk']

add_cia_search_path(self, *search_paths)[source]

Add path(s) to the list of paths that will be searched for cia files.

Parameters

search_path (string or list of strings) – Search path(s) to look for opacities.

add_aerosol_search_path(self, *search_paths)[source]

Add path(s) to the list of paths that will be searched for aerosol files.

Parameters

search_path (string or list of strings) – Search path(s) to look for opacities.

set_search_path(self, *search_paths, path_type='kdata')[source]

Like :func:~exo_k.settings.Settings.add_search_path except for the fact that the path is reset first.

set_cia_search_path(self, *search_paths)[source]

Like :func:~exo_k.settings.Settings.add_cia_search_path except for the fact that the path is reset first.

set_aerosol_search_path(self, *search_paths)[source]

Like :func:~exo_k.settings.Settings.add_aerosol_search_path except for the fact that the path is reset first.

property search_path(self)

Returns the current value of the global search path (_search_path)

cia_search_path(self)[source]

Returns the current value of the cia search path (_cia_search_path)

aerosol_search_path(self)[source]

Returns the current value of the aerosol search path (_aerosol_search_path)

set_delimiter(self, newdelimiter)[source]

Sets the delimiter string used to separate molecule names in filenames.

Parameters

newdelimiter (string) – New delimiter to use. Default is ‘_’.

Example

If I have a file named ‘H2O.R10000_xsec.hdf5’ that I want to load in a Kdatabase, the default settings will result in an error:

>>> database=xk.Kdatabase(['H2O'],'R10000')
No file was found with these filters:
('H2O_', 'R1000') in the following directories:
['/home/falco/xsec/xsec_sampled_R10000_0.3-15']


Using

>>> xk.Settings().set_delimiter('.')
>>> database=xk.Kdatabase(['H2O'],'R10000')


finds the file.

set_delimiters(self, newdelimiters)[source]

Sets the delimiter string used to separate molecule names in filenames. If you want to include the ‘-‘ character, you must put a ‘’ before to avoid it being interpreted as a special character by the re module.

Parameters

newdelimiters (string) – New delimiters to use. Default is ‘_.-‘.

set_log_interp(self, log_interp)[source]

Sets the default interpolation mode for kdata. Default is Log.

Parameters

set_case_sensitive(self, case_sensitive)[source]

Set whether name matching is case sensitive. Default is False.

Parameters

case_sensitive (boolean) – If True, name matching is case sensitive.

set_mks(self, set_mks)[source]

Forces conversion to mks system.

Parameters

set_mks (boolean) – If True, all datasets are converted to mks upon loading.

list_files(self, *str_filters, molecule=None, only_one=False, search_path=None, path_type='kdata')[source]

A routine that provides a list of all filenames containing a set of string filters in one of the global _search_path or a local one.

Whether the search is case sensitive is specified through the Settings.set_case_sensitive() method.

Warning

The pattern matching with the str_filters is done using regular expressions. If you want to match special characters (like a dot in a filename), do not forget to put a backslash in front of it.

Parameters
• *str_filters (str) – A set of strings that need to be contained in the name of the file

• molecule (str) – The name of a molecule to be looked for in the filename. It must be followed by one of the characters in self._delimiters and either at the begining of the name or just after one of the characters in self._delimiters.

• only_one (boolean, optional) – If true, only one filename is returned (the first one). If false, a list is returned. Default is False.

• search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path settings and only files in search_path are returned.

Returns

List of filenames corresponding to all the str_filters

Return type

list of strings

list_cia_files(self, *str_filters, molecule_pair=None, only_one=False, search_path=None)[source]

A routine that provides a list of all filenames containing a set of string filters in the global _search_path or a local one.

Whether the search is case sensitive is specified through the Settings.set_case_sensitive() method.

Warning

The pattern matching with the str_filters is done using regular expressions. If you want to match special characters (like a dot in a filename), do not forget to put a backslash in front of it.

Parameters
• *str_filters (str) – A set of strings that need to be contained in the name of the file

• molecule_pair (list of 2 str) – The name of the 2 molecules in the cia pair.

• only_one (boolean, optional) – If true, only one filename is returned (the first one). If false, a list is returned. Default is False.

• search_path (str, optional) – If search_path is provided, it locally overrides the global _search_path settings and only files in search_path are returned.

Returns

List of filenames corresponding to all the str_filters

Return type

list of strings

class Rayleigh[source]

Class to compute Rayleigh opacities

init(self, *args, **kwds)[source]

Initializes various parameters for Rayleigh computations

sigma(self, wns, vmr)[source]

Computes the Rayleigh cross section for the gas. This one is faster than sigma_array, but can be used only when vmr values are floats.

Parameters
• wns (array) – array of wavenumbers

• vmr (dict of floats) – Keys are molecule names. Values are the volume mixing ratios

Returns

Rayleigh cross section for the whole gas in m^2/molecule

Return type

array of shape (wns.size)

sigma_array(self, wns, vmr)[source]

Computes the Rayleigh cross section for the gas.

Parameters
• wns (array) – array of wavenumbers

• vmr (dict of arrays) – Keys are molecule names. Values are arrays the volume mixing ratios

Returns

Rayleigh cross section for the whole gas in m^2/molecule

Return type

array of shape (vmr.values.size, wns.size)

sigma_mol(self, mol, wn2, wn4)[source]

Intermediary function to compute rayleigh for each molecule.

Parameters
• mol (str) – Molecule name.

• wn4 (wn2,) – Array of the wavenumber (in cm^-1) to the 2nd and 4th power. (To avoid recomputing it each time).

Returns

• to_add (bool) – Says whether the molecule has been found and the contribution needs to be added.

• tmp (array of size self.wns or None) – The cross section for the molecule as a function of wns. None if the molecule has not been found.