geocat.comp.linint1#
- geocat.comp.linint1(fi, xo, xi=None, icycx=0, msg_py=None)#
Interpolates from one series to another using piecewise linear interpolation across the rightmost dimension. The series may be cyclic in the X direction.
If missing values are present, then linint1 will perform the piecewise linear interpolation at all points possible, but will return missing values at coordinates which could not be used.
If any of the output coordinates
xoare outside those of the input coordinatesxi, thefovalues at those coordinates will be set to missing (i.e. no extrapolation is performed).- Parameters:
fi (
xarray.DataArray,numpy.ndarray) – An array of one or more dimensions. Ifxiis passed in as an argument, then the size of the rightmost dimension offimust match the rightmost dimension ofxi.If missing values are present, then
linint1will perform the piecewise linear interpolation at all points possible, but will return missing values at coordinates which could not be used.Note: This variable must be supplied as a
xarray.DataArrayin order to copy the dimension names to the output. Otherwise, default names will be used.xo (
xarray.DataArray,numpy.ndarray) – A one-dimensional array that specifies the X coordinates of the return array. It must be strictly monotonically increasing or decreasing, but may be unequally spaced.If the output coordinates
xoare outside those of the input coordinatesxi, then the fo values at those coordinates will be set to missing (i.e. no extrapolation is performed).xi (
xarray.DataArray,numpy.ndarray) – An array that specifies the X coordinates of thefiarray. Most frequently, this array is one-dimensional. It must be strictly monotonically increasing or decreasing, but can be unequally spaced. Ifxiis multi-dimensional, then itsimensions must be the same asfi’s dimensions. If it is one-dimensional, its length must be the same as the rightmost (fastest varying) dimension offi.Note: If
fiis of typexarray.DataArrayandxiis left unspecified, then the rightmost coordinate dimension offiwill be used. Iffiis not of typexarray.DataArray, thenxibecomes a mandatory parameter. This parameter must be specified as a keyword argument.icycx (
bool) – An option to indicate whether the rightmost dimension offiis cyclic. This should be set to True only if you have global data, but your longitude values don’t quite wrap all the way around the globe. For example, if your longitude values go from, say, -179.75 to 179.75, or 0.5 to 359.5, then you would set this to True.msg_py (
numpy.number) – A numpy scalar value that represent a missing value infi. This argument allows a user to use a missing value scheme other than NaN or masked arrays, similar to what NCL allows.
- Returns:
fo (
xarray.DataArray,numpy.ndarray) – The interpolated series. The returned value will have the same dimensions asfi, except for the rightmost dimension which will have the same dimension size as the length of xo. The return type will be double iffiis double, and float otherwise.
Examples
Example 1: Using
linint1withxarray.DataArrayinputimport numpy as np import xarray as xr import geocat.comp fi_np = np.random.rand(80) # random 80-element array # xi does not have to be equally spaced, but it is # in this example xi = np.arange(80) # create target coordinate array, in this case use the same # min/max values as xi, but with different spacing xo = np.linspace(xi.min(), xi.max(), 100) # create :class:`xarray.DataArray` and chunk it using the # full shape of the original array. # note that xi is attached as a coordinate array fi = xr.DataArray(fi_np, dims=['x'], coords={'x': xi} ).chunk(fi_np.shape) fo = geocat.comp.linint1(fi, xo, icycx=0)