:py:mod:`exo_k.util.interp` =========================== .. py:module:: exo_k.util.interp .. autoapi-nested-parse:: @author: jeremy leconte Library of useful functions for interpolation Module Contents --------------- .. py:function:: bilinear_interpolation(z00, z10, z01, z11, x, y) 2D interpolation Applies linear interpolation across x and y between xmin,xmax and ymin,ymax :param z00: Array corresponding to xmin,ymin :type z00: :class:`array`, :class:`np.ndarray` :param z10: Array corresponding to xmax,ymin :type z10: :class:`array`, :class:`np.ndarray` :param z01: Array corresponding to xmin,ymax :type z01: :class:`array`, :class:`np.ndarray` :param z11: Array corresponding to xmax,ymax :type z11: :class:`array`, :class:`np.ndarray` :param x: weight on x coord :type x: :class:`float` :param y: weight on y coord :type y: :class:`float` .. py:function:: bilinear_interpolation_array(z00, z10, z01, z11, x, y) 2D interpolation Applies linear interpolation across x and y between xmin,xmax and ymin,ymax. For this variant of bilinear_interpolation (mainly for chemistry), x, y and z must be 1D-arrays of the same length. :param z00: Array corresponding to xmin,ymin :type z00: :class:`array`, :class:`np.ndarray` :param z10: Array corresponding to xmax,ymin :type z10: :class:`array`, :class:`np.ndarray` :param z01: Array corresponding to xmin,ymax :type z01: :class:`array`, :class:`np.ndarray` :param z11: Array corresponding to xmax,ymax :type z11: :class:`array`, :class:`np.ndarray` :param x: weights on x coord :type x: :class:`array`, :class:`np.ndarray` :param y: weights on y coord :type y: :class:`array`, :class:`np.ndarray` .. py:function:: linear_interpolation(z00, z10, x) 1D interpolation. Applies linear interpolation in x between xmin, xmax. :param z00: Array corresponding to xmin :type z00: :class:`array`, :class:`np.ndarray` :param z10: Array corresponding to xmax :type z10: :class:`array`, :class:`np.ndarray` :param x: weight on x coord :type x: :class:`float` .. py:function:: interp_ind_weights(x_to_interp, x_grid) Finds the indices and weights to interpolate from a x_grid to a x_to_interp. .. py:function:: rebin_ind_weights(old_bin_grid, new_bin_grid) Computes the indices and weights to be used when rebinning an array of values f of size N in the bins delimited by old_bin_grid (of size N+1) onto new bins delimited by new_bin_grid (of size Nnew+1) Returns indices, weights to be used as follows to proceed with the rebinning >>> f_rebinned=[np.dot(f[indicestosum[ii]-1:indicestosum[ii+1]],final_weights[ii]) for ii in range(Nnew)] .. py:function:: kdata_conv_loop(kdata1, kdata2, kdataconv, shape) Computes the convolution of two kdata tables. :param kdata1: The two ktable.kdata tables to convolve. :type kdata1: :class:`array`, :class:`np.ndarrays` :param kdata2: The two ktable.kdata tables to convolve. :type kdata2: :class:`array`, :class:`np.ndarrays` :param shape: shape of the ktabke.kdata tables to convolve (last size is Ng). :type shape: :class:`array`, :class:`np.ndarray` :param kdataconv: Result table where the last dimension as a length equal to Ng^2. :type kdataconv: :class:`array`, :class:`np.ndarray` .. py:function:: kdata_conv_loop_profile(kdata1, kdata2, kdataconv, Nlay, Nw, Ng) Computes the convolution of two atmospheric kdata profiles. Nothing is returned. kdataconv is changed in place. :param kdata1: The two ktable.kdata tables to convolve. :type kdata1: :class:`array`, :class:`np.ndarrays` :param kdata2: The two ktable.kdata tables to convolve. :type kdata2: :class:`array`, :class:`np.ndarrays` :param kdataconv: Result table where the last dimension as a length equal to Ng^2. :type kdataconv: :class:`array`, :class:`np.ndarray` :param Nlay: Number of atmospheric layers :type Nlay: :class:`int` :param Nw: Number of wavenumber points :type Nw: :class:`int` :param Ng: Number of g-points :type Ng: :class:`int` .. py:function:: rebin(f_fine, fine_grid, coarse_grid) Computes the binned version of a function on a coarser grid. The two grids do not need to have the same boundaries. :param f_fine: Function to be rebinned, given on the fine_grid. :type f_fine: :class:`array`, :class:`np.ndarray` :param fine_grid: The high resolution grid edges we start with. :type fine_grid: :class:`array`, :class:`np.ndarray` :param coarse_grid: The coarser resolution grid edges inside which we want to bin the function f. :type coarse_grid: :class:`array`, :class:`np.ndarray` .. py:function:: g_sample_4d(new_ggrid, new_kdata, old_ggrid, old_kdata) Reinterpolte the g grid inplace. .. py:function:: g_sample_5d(new_ggrid, new_kdata, old_ggrid, old_kdata) Reinterpolte the g grid inplace. .. py:function:: RandOverlap_2_kdata_prof(Nlay, Nw, Ng, kdata1, kdata2, weights, ggrid) Function to randomely mix the opacities of 2 species in an atmospheric profile. :param Nlay: Number of layers, spectral bins, and gauss points. :type Nlay: :class:`int` :param Nw: Number of layers, spectral bins, and gauss points. :type Nw: :class:`int` :param Ng: Number of layers, spectral bins, and gauss points. :type Ng: :class:`int` :param kdata1: vmr weighted cross-sections for the two species. :type kdata1: :class:`array`, :class:`np.ndarrays` of :class:`size (Nlay`, :class:`Nw`, :class:`Ng)` :param kdata2: vmr weighted cross-sections for the two species. :type kdata2: :class:`array`, :class:`np.ndarrays` of :class:`size (Nlay`, :class:`Nw`, :class:`Ng)` :param weights: gauss weights. :type weights: :class:`array`, :class:`np.ndarray` :param ggrid: g-points. :type ggrid: :class:`array`, :class:`np.ndarray` :returns: array k-coefficient array of the mix over the atmospheric column. .. py:function:: unit_convert(quantity, unit_file='unspecified', unit_in='unspecified', unit_out='unspecified') Chooses the final unit to use and the conversion factor to apply. :param quantity: The name of the pysical quantity handled for potential error messages :type quantity: :class:`str` :param unit_file/unit_in/unit_out: Respectively: * String with the unit found in (or assumed from the format of) the initial data, * The unit we think the initial data are in if unit_file is 'unspecified' or (we believe) wrong, * The unit we want to convert to. If unspecified, we do not convert. :type unit_file/unit_in/unit_out: :class:`str` :returns: unit_to_write: str Resulting unit. conversion_factor: float A multiplicating factor for the data to proceed to the conversion. .. py:function:: rm_molec(unit_name) Removes "/molecule" or "/molec" from a unit string. :param unit_name: String to be changed. :type unit_name: :class:`str` :returns: str The unit name without the ending "/molecule" or "/molec" .. py:function:: is_sorted(a) Finds out if an array is sorted. Returns True if it is. .. py:function:: gauss_legendre(order) Computes the weights and abscissa for a Gauss Legendre quadrature of order `order` :param order: Order of the quadrature wanted. :type order: :class:`int` :returns: weights: array, np.ndarray(order) Weights to be used in the quadrature. ggrid: array, np.ndarray(order) Abscissa to be used for the quadrature. gedges: array, np.ndarray(order+1) Cumulative sum of the weights. Goes from 0 to 1. .. py:function:: split_gauss_legendre(order, g_split) 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_split`and 1. (This is what is used in petitRADTRANS with g_split=0.9) :param order: Order of the quadrature wanted. Needs to be even. :param g_split: Splitting point, it needs to be between 0 and 1. :returns: weights: array, np.ndarray(order) Weights to be used in the quadrature. ggrid: array, np.ndarray(order) Abscissa to be used for the quadrature. gedges: array, np.ndarray(order+1) Cumulative sum of the weights. Goes from 0 to 1. .. py:function:: spectrum_to_kdist(k_hr, wn_hr, dwn_hr, wnedges, ggrid) Creates the k-distribution from a single high resolution spectrum :param k_hr: Spectrum :type k_hr: :class:`array`, :class:`np.ndarray` :param wn_hr: Wavenumber grid :type wn_hr: :class:`array`, :class:`np.ndarray` :param dwn_hr: Width of the high resolution wavenumber bins. :type dwn_hr: :class:`array`, :class:`np.ndarray` :param wnedges: Lower resolution wavenumber bin edges inside which the k-dist will be computed. :type wnedges: :class:`array`, :class:`np.ndarray` :param ggrid: Grid of g-point abscissas :type ggrid: :class:`array`, :class:`np.ndarray` :returns: kdata : array, np.ndarray k coefficients for each (Wn, g) bin. .. py:function:: bin_down_corrk_numba(newshape, kdata, old_ggrid, new_ggrid, gedges, indicestosum, wngrid_filter, wn_weigths, num, use_rebin) bins down a kcoefficient table (see :func:`~exo_k.ktable.Ktable.bin_down` for details) :param newshape: Shape of kdata. :type newshape: :class:`array`, :class:`np.ndarray` :param kdata: table to bin down. :type kdata: :class:`array`, :class:`np.ndarray` :param old_ggrid: Grid of old g-point abscissas for kdata. :type old_ggrid: :class:`array`, :class:`np.ndarray` :param new_ggrid: New g-points for the binned-down k-coefficients. :type new_ggrid: :class:`array`, :class:`np.ndarray` :param gedges: Cumulative sum of the weights. Goes from 0 to 1. Used only if use_rebin=True :type gedges: :class:`array`, :class:`np.ndarray` :param indicestosum: Indices of wavenumber bins to be used for the averaging :type indicestosum: :class:`list` of :class:`lists` :param wngrid_filter: Indices of the new table where there will actually be data (zero elsewhere) :type wngrid_filter: :class:`array`, :class:`np.ndarray` :param wn_weigths: Weights to be used for the averaging (same size as indicestosum) :type wn_weigths: :class:`list` of :class:`lists` :param num: Number of points to fine sample the g function in log-k space :type num: :class:`int` :param use_rebin: Whether to use rebin or interp method. :type use_rebin: :class:`boolean` .. py:function:: kdata_conv(kdata1, kdata2, kdataconv, Ng) Deprecated. Performs the convolution of the kdata over g-space. .. py:function:: kdata_conv_loop_bad(kdata1, kdata2, kdataconv, shape) Deprecated. Performs the convolution of the kdata over g-space. But the loop is in bad order. Keep for test. .. py:function:: g_interp(logk, Nw, Ng, Num, ggrid, wl_weights, indices) Interpolates logk on a new g-grid.