environmentaltools.spectral.analysis.fast_fourier_transform

environmentaltools.spectral.analysis.fast_fourier_transform(data, variable, fname=None, freq='H', alpha=0.05)[source]

Compute the Fast Fourier Transform for regularly sampled time series.

This function performs spectral analysis using FFT, suitable for time series with regular sampling intervals. It identifies significant frequencies using a chi-squared test at the specified significance level.

Parameters:
  • data (pd.DataFrame) – Time series data with datetime index and regular sampling.

  • variable (str) – Name of the column containing the variable to analyze.

  • fname (str, optional) – Filename to save the power spectral density and frequencies. If None, results are not saved to file.

  • freq ({'H', 'D'}, default='H') – Frequency of the data: ‘H’ for hourly, ‘D’ for daily.

  • alpha (float, default=0.05) – Significance level for the chi-squared test to identify significant frequencies.

Returns:

DataFrame with frequencies as index and columns:

  • ’psd’ : Power spectral density values

  • ’significant’ : Boolean indicating statistically significant frequencies

Return type:

pd.DataFrame

Notes

The spectral resolution (fmin) depends on the total duration of the time series. Longer time series provide finer frequency resolution. Only the positive frequency half of the spectrum is returned.

The significance test uses a chi-squared distribution with degrees of freedom calculated based on the number of data points and the spectral resolution.