exo_k.util.interp
@author: jeremy leconte Library of useful functions for interpolation
Module Contents
- exo_k.util.interp.bilinear_interpolation(z00, z10, z01, z11, x, y)[source]
2D interpolation Applies linear interpolation across x and y between xmin,xmax and ymin,ymax
- Parameters:
- exo_k.util.interp.bilinear_interpolation_array(z00, z10, z01, z11, x, y)[source]
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.
- Parameters:
z00 (
array
,np.ndarray
) – Array corresponding to xmin,yminz10 (
array
,np.ndarray
) – Array corresponding to xmax,yminz01 (
array
,np.ndarray
) – Array corresponding to xmin,ymaxz11 (
array
,np.ndarray
) – Array corresponding to xmax,ymaxx (
array
,np.ndarray
) – weights on x coordy (
array
,np.ndarray
) – weights on y coord
- exo_k.util.interp.linear_interpolation(z00, z10, x)[source]
1D interpolation.
Applies linear interpolation in x between xmin, xmax.
- Parameters:
z00 (
array
,np.ndarray
) – Array corresponding to xminz10 (
array
,np.ndarray
) – Array corresponding to xmaxx (
float
) – weight on x coord
- exo_k.util.interp.interp_ind_weights(x_to_interp, x_grid)[source]
Finds the indices and weights to interpolate from a x_grid to a x_to_interp.
- exo_k.util.interp.rebin_ind_weights(old_bin_grid, new_bin_grid)[source]
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)]
- exo_k.util.interp.kdata_conv_loop(kdata1, kdata2, kdataconv, shape)[source]
Computes the convolution of two kdata tables.
- Parameters:
kdata1 (
array
,np.ndarrays
) – The two ktable.kdata tables to convolve.kdata2 (
array
,np.ndarrays
) – The two ktable.kdata tables to convolve.shape (
array
,np.ndarray
) – shape of the ktabke.kdata tables to convolve (last size is Ng).kdataconv (
array
,np.ndarray
) – Result table where the last dimension as a length equal to Ng^2.
- exo_k.util.interp.kdata_conv_loop_profile(kdata1, kdata2, kdataconv, Nlay, Nw, Ng)[source]
Computes the convolution of two atmospheric kdata profiles.
Nothing is returned. kdataconv is changed in place.
- Parameters:
kdata1 (
array
,np.ndarrays
) – The two ktable.kdata tables to convolve.kdata2 (
array
,np.ndarrays
) – The two ktable.kdata tables to convolve.kdataconv (
array
,np.ndarray
) – Result table where the last dimension as a length equal to Ng^2.Nlay (
int
) – Number of atmospheric layersNw (
int
) – Number of wavenumber pointsNg (
int
) – Number of g-points
- exo_k.util.interp.rebin(f_fine, fine_grid, coarse_grid)[source]
Computes the binned version of a function on a coarser grid. The two grids do not need to have the same boundaries.
- Parameters:
f_fine (
array
,np.ndarray
) – Function to be rebinned, given on the fine_grid.fine_grid (
array
,np.ndarray
) – The high resolution grid edges we start with.coarse_grid (
array
,np.ndarray
) – The coarser resolution grid edges inside which we want to bin the function f.
- exo_k.util.interp.g_sample_4d(new_ggrid, new_kdata, old_ggrid, old_kdata)[source]
Reinterpolte the g grid inplace.
- exo_k.util.interp.g_sample_5d(new_ggrid, new_kdata, old_ggrid, old_kdata)[source]
Reinterpolte the g grid inplace.
- exo_k.util.interp.RandOverlap_2_kdata_prof(Nlay, Nw, Ng, kdata1, kdata2, weights, ggrid)[source]
Function to randomely mix the opacities of 2 species in an atmospheric profile.
- Parameters:
Nlay (
int
) – Number of layers, spectral bins, and gauss points.Nw (
int
) – Number of layers, spectral bins, and gauss points.Ng (
int
) – Number of layers, spectral bins, and gauss points.kdata1 (
array
,np.ndarrays
ofsize (Nlay
,Nw
,Ng)
) – vmr weighted cross-sections for the two species.kdata2 (
array
,np.ndarrays
ofsize (Nlay
,Nw
,Ng)
) – vmr weighted cross-sections for the two species.weights (
array
,np.ndarray
) – gauss weights.ggrid (
array
,np.ndarray
) – g-points.
- Returns:
- array
k-coefficient array of the mix over the atmospheric column.
- exo_k.util.interp.unit_convert(quantity, unit_file='unspecified', unit_in='unspecified', unit_out='unspecified')[source]
Chooses the final unit to use and the conversion factor to apply.
- Parameters:
quantity (
str
) – The name of the pysical quantity handled for potential error messagesunit_file/unit_in/unit_out (
str
) –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.
- Returns:
- unit_to_write: str
Resulting unit.
- conversion_factor: float
A multiplicating factor for the data to proceed to the conversion.
- exo_k.util.interp.rm_molec(unit_name)[source]
Removes “/molecule” or “/molec” from a unit string.
- Parameters:
unit_name (
str
) – String to be changed.- Returns:
- str
The unit name without the ending “/molecule” or “/molec”
- exo_k.util.interp.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, 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.
- exo_k.util.interp.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_split`and 1.
(This is what is used in petitRADTRANS with g_split=0.9)
- Parameters:
- 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.
- exo_k.util.interp.spectrum_to_kdist(k_hr, wn_hr, dwn_hr, wnedges, ggrid)[source]
Creates the k-distribution from a single high resolution spectrum
- Parameters:
k_hr (
array
,np.ndarray
) – Spectrumwn_hr (
array
,np.ndarray
) – Wavenumber griddwn_hr (
array
,np.ndarray
) – Width of the high resolution wavenumber bins.wnedges (
array
,np.ndarray
) – Lower resolution wavenumber bin edges inside which the k-dist will be computed.ggrid (
array
,np.ndarray
) – Grid of g-point abscissas
- Returns:
- kdataarray, np.ndarray
k coefficients for each (Wn, g) bin.
- exo_k.util.interp.bin_down_corrk_numba(newshape, kdata, old_ggrid, new_ggrid, gedges, indicestosum, wngrid_filter, wn_weigths, num, use_rebin)[source]
bins down a kcoefficient table (see
bin_down()
for details)- Parameters:
newshape (
array
,np.ndarray
) – Shape of kdata.kdata (
array
,np.ndarray
) – table to bin down.old_ggrid (
array
,np.ndarray
) – Grid of old g-point abscissas for kdata.new_ggrid (
array
,np.ndarray
) – New g-points for the binned-down k-coefficients.gedges (
array
,np.ndarray
) – Cumulative sum of the weights. Goes from 0 to 1. Used only if use_rebin=Trueindicestosum (
list
oflists
) – Indices of wavenumber bins to be used for the averagingwngrid_filter (
array
,np.ndarray
) – Indices of the new table where there will actually be data (zero elsewhere)wn_weigths (
list
oflists
) – Weights to be used for the averaging (same size as indicestosum)num (
int
) – Number of points to fine sample the g function in log-k spaceuse_rebin (
boolean
) – Whether to use rebin or interp method.
- exo_k.util.interp.kdata_conv(kdata1, kdata2, kdataconv, Ng)[source]
Deprecated.
Performs the convolution of the kdata over g-space.