| |
- interp(y, x, xinterp, missing=1e+20)
- Simple linear interpolation for ordinate with missing values.
Vectors x and y are the data describing a piecewise linear function.
Function returns the interpolated values of the ordinate function
at abscissa values in xinterp. Values of xinterp outside the range
of x are returned as missing. Any elements in the output that uses
missing values in y for the interpolation are set to missing.
Positional Input Arguments:
* y: Ordinate values of data. Rank 1 Numeric vector. Required.
Can have missing values. Floating or integer type.
* x: Abscissa values of data. Rank 1 Numeric vector. Required.
Can have no missing values. Must be monotonically ascending.
Floating or integer type.
* xinterp: Abscissa values to calculate interpolated ordinate
values at. Rank 1 Numeric vector or Numeric scalar. Required.
Can have no missing values. Can be in any order. Floating or
integer type.
Keyword Input Arguments:
* missing: If input has missing values, this is the missing value
value. Scalar. Floating or integer type. Default is 1e+20.
Output Result:
* Interpolated ordinate values at xinterp. Rank 1 Numeric vector
of same length as xinterp (if xinterp is a Numeric scalar,
output is also a Numeric scalar). Missing values are set to the
value of argument missing. Type is Float, even if argument
missing and inputs are all integer.
References:
* Lin, J. W.-B.: "Simple Interpolation."
Python/CDAT for Earth Scientists: Tips and Examples.
http://www.johnny-lin.com/cdat_tips/tips_math/interp.html
Example with no missing values (gives same output as function
arrayfns.interp):
>>> from interp import interp
>>> import Numeric as N
>>> x = N.array([1., 2., 3., 4., 5.])
>>> y = N.array([3., 6., 2.,-5.,-3.])
>>> xint = N.array([3.4, 2.3])
>>> yint = interp(y, x, xint, missing=1e+20)
>>> ['%.7g' % yint[i] for i in range(len(yint))]
['-0.8', '4.8']
Example with missing values:
>>> x = N.array([1., 2., 3., 4., 5.])
>>> y = N.array([3., 1e+20, 2., -5., -3.])
>>> xint = N.array([3.4, 2.3])
>>> yint = interp(y, x, xint, missing=1e+20)
>>> ['%.7g' % yint[i] for i in range(len(yint))]
['-0.8', '1e+20']
Example with values out of range of the data:
>>> x = N.array([1., 2.1, 3., 4., 5.1])
>>> y = N.array([3., 1e+20, 2., -5., -3.])
>>> xint = N.array([3.4, -2.3, 6.])
>>> yint = interp(y, x, xint, missing=1e+20)
>>> ['%.7g' % yint[i] for i in range(len(yint))]
['-0.8', '1e+20', '1e+20']
|