Time Series Resampling Methods
The adjustment of a segment of time-series data set to produce a segment of data which is scientifically equivalent but with data sample timing strictly simultaneous with that of another data set is called “resampling”. Paschmann and Daly [2], Chapter 2
Time Series Interpolation
Flexible time series interpolation through the tinterp
function.
This function supports interpolation for both vector-like and matrix-like time series. Other features include:
- Returns scalar value for single time point interpolation
- Returns DimArray for multiple time points interpolation, preserving metadata and dimensions.
- Customizable interpolation method through the
interp
keyword argument
SPEDAS.tinterp
— Functiontinterp(A, t; interp=LinearInterpolation)
Interpolate time series A
at time point(s) t
. Returns interpolated value for single time point or DimArray for multiple time points.
tinterp(A, B; interp=LinearInterpolation)
Interpolate A
to times in B
SPEDAS.tinterp_nans
— Functiontinterp_nans(da::AbstractDimArray; query=timeDimType, kwargs...)
Interpolate only the NaN values in da
along the specified dimensions query
. Non-NaN values are preserved exactly as they are.
See also interpolate_nans
SPEDAS.resample
— Functionresample(arr, n=DEFAULTS.resample; dim=1, verbose=false)
Resample an array along the dimension dim
to n
points. If the original length is less than or equal to n
, the original array is returned unchanged.
SPEDAS.tresample
— Functiontresample(da::DimArray, n=DEFAULTS.resample; dimtype=Ti)
Resample a DimArray specifically along its dimension of type dimtype
to n
points. Throws an error if no dimension of type dimtype
is found in the array.
Basic Usage
using SPEDAS
using Dates
using DataInterpolations
# Interpolate at a single time point
val = tinterp(time_series, DateTime("2023-01-01T12:00:00"))
# Interpolate at multiple time points
new_times = DateTime("2023-01-01"):Hour(1):DateTime("2023-01-02")
interpolated = tinterp(time_series, new_times; interp=CubicSpline)
Utilities
SPEDAS.dropna
— Functiondropna(da::DimArray, query)
Remove slices containing NaN values along dimensions other than query
.
SPEDAS.rectify_datetime
— FunctionRectify the time step of a DimArray
to be uniform.