-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
Add a sliding window mechanism to speasy.signal that applies a function over a moving time window on a SpeasyVariable. This enables common time-series analysis operations like moving averages, sliding FFTs (spectrograms), running integrals, and arbitrary user-defined windowed computations.
Use cases
- Moving average — smooth noisy time series over a configurable window
- Sliding FFT / spectrogram — compute power spectral density in a moving window, producing a time-frequency representation
- Running integration — fluence, accumulated flux over a sliding interval
- Custom operations — any user-provided function applied per window (e.g. variance, percentiles)
Sketch of possible API
from speasy.signal.windowing import sliding_window
# Moving average
smoothed = sliding_window(var, window_size=np.timedelta64(30, 's'), func=np.mean)
# Sliding FFT (returns a different shape — time x frequency)
spectrogram = sliding_window(var, window_size=np.timedelta64(10, 's'), func='fft', step=np.timedelta64(5, 's'))
# Custom callable
result = sliding_window(var, window_size=np.timedelta64(1, 'm'), func=my_function)Design considerations
window_sizeasnp.timedelta64orfloat(seconds)- Optional
stepparameter for non-overlapping or partially overlapping windows (defaults to one sample = fully overlapping) - Built-in fast paths for
mean(cumsum trick, O(n)) andfft(stride tricks + vectorized FFT) - Arbitrary callable fallback for custom functions
- Output shape depends on the function: same shape for mean/integrate, time x frequency for FFT
- Should handle lists of variables like the rest of
speasy.signal
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request