speasy.signal.resampling package

speasy.signal.resampling.generate_time_vector(start: str | datetime | float64 | float | datetime64, stop: str | datetime | float64 | float | datetime64, dt: float | timedelta64) ndarray[source]

Generate a time vector given a start, stop and time step. The time vector will be generated in UTC time zone. The time step is in seconds.

Parameters:
start: float or datetime or np.datetime64

The start time

stop: float or datetime or np.datetime64

The stop time

dt: float or np.timedelta64

The time step in seconds or as a numpy timedelta64

Returns:
np.ndarray

The time vector as a numpy array of datetime64[ns]

speasy.signal.resampling.interpolate(ref: ndarray | SpeasyVariable, var: SpeasyVariable | Collection[SpeasyVariable], interpolate_callback: Callable | None = None, *args, **kwargs) SpeasyVariable | Collection[SpeasyVariable][source]

Interpolate a variable(s) to a new time vector. The time vector will be taken from the reference variable. Uses numpy.interp() to do the resampling by default.

Parameters:
ref: np.ndarray or SpeasyVariable

The reference time vector

var: SpeasyVariable or Collection[SpeasyVariable]

The variable(s) to interpolate

interpolate_callback: Callable or None

The interpolation function to use, defaults to numpy.interp() (Optional)

Returns:
SpeasyVariable or Collection[SpeasyVariable]

The interpolated variable(s) with all metadata preserved except for the new time axis

Notes

It only supports 1D variables.

speasy.signal.resampling.resample(var: SpeasyVariable | Collection[SpeasyVariable], new_dt: float | timedelta64, interpolate_callback: Callable | None = None, *args, **kwargs) SpeasyVariable | Collection[SpeasyVariable][source]

Resample a variable(s) to a new time step. The time vector will be generated from the start and stop times of the input variable. Uses numpy.interp() to do the resampling by default.

Parameters:
var: SpeasyVariable or Collection[SpeasyVariable]

The variable(s) to resample

new_dt: float or np.timedelta64

The new time step in seconds or as a numpy timedelta64

interpolate_callback: Callable or None

The interpolation function to use, defaults to numpy.interp()

Returns:
SpeasyVariable or Collection[SpeasyVariable]

The resampled variable(s) with all metadata preserved except for the new time axis

Notes

It only supports 1D variables.