:py:mod:`exo_k.ktable` ====================== .. py:module:: exo_k.ktable .. autoapi-nested-parse:: @author: jeremy leconte Module Contents --------------- .. py: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) Bases: :py:obj:`exo_k.ktable_io.Ktable_io` A class that handles 4D tables of k-coefficients. Based on the :class:`~exo_k.data_table.Data_table` class that handles basic operations common to Xtable. Based on the :class:`~exo_k.ktable_io.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) :param filename: Relative or absolute name of the file to be loaded. :type filename: :class:`str`, *optional* :param filename_filters: As many strings as necessary to uniquely define a file in the global search path defined in :class:`~exo_k.settings.Settings`. This path will be searched for a file with all the filename_filters in the name. The filename_filters can contain '*'. :type filename_filters: :class:`sequence` of :class:`string` :param xtable: 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. :type xtable: :class:`Xtable object` :param path: 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. :type path: :class:`str` If none of the parameters above is specified, just creates an empty object to be filled later. :param p_unit: 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. :type p_unit: :class:`str`, *optional* :param file_p_unit: 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) :type file_p_unit: :class:`str`, *optional* :param kdata_unit: 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. :type kdata_unit: :class:`str`, *optional* :param file_kdata_unit: 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) :type file_kdata_unit: :class:`str`, *optional* :param remove_zeros: If True, the zeros in the kdata table are replaced by a value 10 orders of magnitude smaller than the smallest positive value :type remove_zeros: :class:`boolean`, *optional* :param mol: The name of the gas or molecule described by the :class:`Ktable` :type mol: :class:`str`, *optional* :param search_path: If search_path is provided, it locally overrides the global _search_path in :class:`~exo_k.settings.Settings` and only files in search_path are returned. :type search_path: :class:`str`, *optional* .. py:method:: xtable_to_ktable(xtable=None, wnedges=None, weights=None, ggrid=None, quad='legendre', order=20, g_split=0.9, mid_dw=True, write=0, remove_zeros=False) Fills the :class:`~exo_k.ktable.Ktable` object with a k-coeff table computed from a :class:`~exo_k.xtable.Xtable` object (inplace). The p and kcorr units are inherited from the :class:`~exo_k.xtable.Xtable` object. :param xtable: input Xtable object instance :type xtable: :class:`~exo_k.xtable.Xtable` :param wnedges: edges of the wavenumber bins to be used to compute the corrk :type wnedges: :class:`Array` :param weights: If weights are provided, they are used instead of the legendre quadrature. :type weights: :class:`array`, :class:`np.ndarray`, *optional* :param quad: 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. :type quad: :class:`string`, *optional* :param order: Order of the Gauss legendre quadrature used. Default is 20. :type order: :class:`Integer`, *optional* :param g_split: Used only if quad='split-legendre'. See above. :type g_split: :class:`float`, *optional* :param mid_dw: * 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. :type mid_dw: :class:`boolean`, *optional* .. py:method:: hires_to_ktable(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) Computes a k coeff table from :class:`~exo_k.util.hires_spectrum.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. :param path: directory with the input files :type path: :class:`String` :param filename_grid: 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 :func:`~exo_k.util.filenames.create_fname_grid_Kspectrum_LMDZ` for possible additional keyword arguments. :type filename_grid: :class:`array`, :class:`np.ndarray` of :class:`str with shape (logpgrid.size,tgrid.size)` :param logpgrid: Grid in log(pressure) of the input. Default unit is Pa, but can be changed with the `grid_p_unit` keyword. :type logpgrid: :class:`array`, :class:`np.ndarray` :param tgrid: Grid in temperature of the input. :type tgrid: :class:`array`, :class:`np.ndarray` :param wnedges: Edges of the wavenumber bins to be used to compute the corr-k :type wnedges: :class:`array`, :class:`np.ndarray` :param weights: If weights are provided, they are used instead of the legendre quadrature. :type weights: :class:`array`, :class:`np.ndarray`, *optional* :param quad: 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. :type quad: :class:`string`, *optional* :param order: Order of the Gauss legendre quadrature used. Default is 20. :type order: :class:`Integer`, *optional* :param g_split: Used only if quad='split-legendre'. See above. :type g_split: :class:`float`, *optional* :param mid_dw: * 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. :type mid_dw: :class:`boolean`, *optional* :param mol: Give a name to the molecule. Useful when used later in a Kdatabase to track molecules. :type mol: :class:`string`, *optional* :param p_unit: Pressure unit to convert to. :type p_unit: :class:`str`, *optional* :param grid_p_unit: Unit of the specified `logpgrid`. :type grid_p_unit: :class:`str`, *optional* :param kdata_unit: Kdata unit to convert to. :type kdata_unit: :class:`str`, *optional* :param file_kdata_unit: Kdata unit in input files. :type file_kdata_unit: :class:`str`, *optional* See :func:`~exo_k.util.filenames.create_fname_grid_Kspectrum_LMDZ` or :class:`~exo_k.util.hires_spectrum.Hires_spectrum` for a list of additional arguments that can be provided to those funtion through `**kwargs`. .. py:method:: copy(cp_kdata=True, ktab5d=False) Creates a new instance of :class:`Ktable` object and (deep) copies data into it. :param cp_kdata: If false, the kdata table is not copied and only the structure and metadata are. :type cp_kdata: :class:`bool`, *optional* :param ktab5d: If true, creates a Ktable5d object with the same structure. Data are not copied. :type ktab5d: :class:`bool`, *optional* :returns: :class:`Ktable` or :class:`Ktable5d` A new :class:`Ktable` or :class:`Ktable5d` instance with the same structure as self. .. py:method:: gindex(g) Finds the index corresponding to the given g .. py:method:: spectrum_to_plot(p=1e-05, t=200.0, x=1.0, g=None) provide the spectrum for a given point to be plotted :param p: Pressure (Ktable pressure unit) :type p: :class:`float` :param t: Temperature(K) :type t: :class:`float` :param g: Gauss point :type g: :class:`float` :param x: Mixing ratio of the species :type x: :class:`float` .. py:method:: plot_distrib(ax, p=1e-05, t=200.0, wl=1.0, x=1.0, xscale=None, yscale='log', **kwarg) Plot the distribution for a given point :param p: Pressure (Ktable pressure unit) :type p: :class:`float` :param t: Temperature(K) :type t: :class:`float` :param wl: Wavelength (micron) :type wl: :class:`float` .. py:method:: RandOverlap(other, x_self, x_other, write=0, use_rebin=False) Method to randomly mix the opacities of 2 species (self and other). :param other: A :class:`Ktable` object to be mixed with. Dimensions should be the same as self. :type other: :class:`Ktable` :param x_self: Volume mixing ratio of the first species :type x_self: :class:`float` or :class:`array` :param x_other: Volume mixing ratio of the species to be mixed with. :type x_other: :class:`float` or :class:`array` 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 array of k-coefficients for the mix. .. py:method:: bin_down(wnedges=None, weights=None, ggrid=None, remove_zeros=False, num=300, use_rebin=False, write=0) Method to bin down a kcoeff table to a new grid of wavenumbers (inplace). :param wnedges: 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] :type wnedges: :class:`array`, :class:`np.ndarray` :param weights: Desired weights for the resulting Ktable. :type weights: :class:`array`, :class:`np.ndarray`, *optional* :param ggrid: 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 :type ggrid: :class:`array`, :class:`np.ndarray`, *optional* .. py:method:: remap_g(ggrid=None, weights=None) Method to resample a kcoeff table to a new g grid (inplace). :param ggrid: New grid of abcissas for quadrature :type ggrid: :class:`array`, :class:`np.ndarray` :param weights: New grid of weights :type weights: :class:`array`, :class:`np.ndarray`