Skip to content

Spectral

polars_ts.imaging.spectral

Spectrogram and wavelet scalogram imaging for time series.

Converts time series to time-frequency 2D representations via Short-Time Fourier Transform (STFT) and Continuous Wavelet Transform (CWT).

_spectrogram(x, nperseg, noverlap, window, log_scale)

Compute STFT spectrogram for a single 1D series.

_morlet(M, s=1.0, w=5.0)

Complex Morlet wavelet.

_ricker(M, a=1.0)

Mexican hat (Ricker) wavelet.

_cwt(x, wavelet_func, scales)

Continuous Wavelet Transform using convolution.

_scalogram(x, wavelet, scales)

Compute CWT scalogram for a single 1D series.

to_spectrogram(df, nperseg=64, noverlap=None, window='hann', log_scale=True, id_col='unique_id', target_col='y')

Convert time series to STFT spectrogram images.

Computes the Short-Time Fourier Transform magnitude for each series.

Parameters

df DataFrame with columns id_col and target_col. nperseg Length of each STFT segment. noverlap Number of overlapping points between segments. Defaults to nperseg // 2. window Window function name (e.g. "hann", "hamming"). log_scale Apply log1p to the magnitude for better dynamic range. id_col Column identifying each time series. target_col Column with the time series values.

Returns

dict[str, np.ndarray] Mapping from series ID to a 2D array (frequency x time bins).

to_scalogram(df, wavelet='morlet', scales=None, n_scales=32, id_col='unique_id', target_col='y')

Convert time series to CWT scalogram images.

Computes the Continuous Wavelet Transform magnitude for each series.

Parameters

df DataFrame with columns id_col and target_col. wavelet Wavelet name: "morlet" / "morl" or "ricker" / "mexh". scales Array of scales to use. If None, generates n_scales logarithmically spaced scales from 1 to series_length / 4. n_scales Number of scales when scales is None. id_col Column identifying each time series. target_col Column with the time series values.

Returns

dict[str, np.ndarray] Mapping from series ID to a 2D array (scale x time).