Interpolation
- pyspedas.tinterpol(names, interp_to, method=None, newname=None, suffix=None)[source]
Interpolate data to times in interp_to.
- Parameters:
names (
array_like
orstr
) – List of tplot variables to interpolate. Allowed wildcards are ? for a single character, * from multiple characters.interp_to (
array_like
orstr
) – String containing the tplot variable with the time stamps to interpolate to.method (
str
, optional) – Interpolation method. Default is ‘linear’. Specifies the kind of interpolation as a string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, ‘next’) where ‘zero’, ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of zeroth, first, second or third order; ‘previous’ and ‘next’ simply return the previous or next value of the point) or as an integer specifying the order of the spline interpolator to use.newname (
str
orlist
ofstr
, optional) – List of new names for pytplot variables. If ‘’, then pytplot variables are replaced. If not given, then a suffix is applied.suffix (
str
, optional) – A suffix to apply. Default is ‘-itrp’.
- Returns:
This function works in-place or creates new pytplot variables depending on the ‘newname’ parameter.
- Return type:
Notes
Uses xarray interp method to interpolate data to the times in interp_to. See: https://docs.xarray.dev/en/latest/generated/xarray.DataArray.interp.html Similar to tinterpol.pro in IDL SPEDAS.
Examples
import numpy as np import pytplot import pyspedas
# Create some time series data times = np.array([‘2002-02-03T04:05:00’, ‘2002-02-03T04:05:05’, ‘2002-02-03T04:05:10’], dtype=’datetime64’) data = np.array([0.0, 5.0, 10.0])
# Store the data in pytplot pytplot.store_data(‘variable1’, data={‘x’: times, ‘y’: data})
# Create some new times to interpolate to new_times = np.array([‘2002-02-03T04:05:07’, ‘2002-02-03T04:05:08’, ‘2002-02-03T04:05:09’], dtype=’datetime64’) new_data = np.array([11.0, 12.0, 13.0])
# Store the new times in pytplot, the new_data will be ignored pytplot.store_data(‘variable2’, data={‘x’: new_times, ‘y’: new_data})
# Interpolate ‘variable1’ to the new times using the default linear method pyspedas.tinterpol(names=’variable1’, interp_to=’variable2’)
# The interpolated data is now stored in ‘variable1-itrp’ interpolated_data = pytplot.get_data(‘variable1-itrp’) print(interpolated_data)