spacepy.toolbox.interpol¶
- spacepy.toolbox.interpol(newx, x, y, wrap=None, **kwargs)[source]¶
1-D linear interpolation with interpolation of hours/longitude
- Parameters:
- newxarray_like
x values where we want the interpolated values
- xarray_like
x values of the original data (must be monotonically increasing or wrapping)
- yarray_like
y values of the original data
- wrapstring, optional
for continuous x data that wraps in y at ‘hours’ (24), ‘longitude’ (360), or arbitrary value (int, float)
- kwargsdict
additional keywords, currently accepts baddata that sets baddata for masked arrays
- Returns:
- outnumpy.masked_array
interpolated data values for new abscissa values
Examples
For a simple interpolation
>>> import spacepy.toolbox as tb >>> import numpy >>> x = numpy.arange(10) >>> y = numpy.arange(10) >>> tb.interpol(numpy.arange(5)+0.5, x, y) array([ 0.5, 1.5, 2.5, 3.5, 4.5])
To use the wrap functionality, without the wrap keyword you get the wrong answer
>>> y = range(24)*2 >>> x = range(len(y)) >>> tb.interpol([1.5, 10.5, 23.5], x, y, wrap='hour').compressed() # compress removed the masked array array([ 1.5, 10.5, 23.5]) >>> tb.interpol([1.5, 10.5, 23.5], x, y) array([ 1.5, 10.5, 11.5])