cospectrum
Functions
Compute power spectrum or co-spectrum of atmospheric time series. |
- cospectrum.cospectrum(ini, x, y, f, mean_wind_speed, plot=False, filename='', spectrum_type='')[source]
Compute power spectrum or co-spectrum of atmospheric time series.
This function calculates either the power spectrum (when x=y) or the co-spectrum (when x≠y) of atmospheric time series data. It implements standard eddy covariance spectral analysis techniques, including normalization and scaling according to Kaimal et al. (1972) conventions.
- Parameters:
ini (
dict
) –Initialization dictionary containing:
- param.WINDOW_LENGTHfloat
Length of the averaging window in seconds
- param.SAMPLING_RATE_FINALfloat
Final sampling rate in Hz
- param.NUM_FREQ_BINSint
Number of frequency bins for log-averaging
- param.SENSOR_HEIGHTfloat
Height of the sensor above ground [m]
x (
numpy.ndarray
) – Fluctuations of the first time series. For power spectrum, this is the only relevant time series. Units: Variable-specific (e.g., m s⁻¹ for wind, ppb for concentrations)y (
numpy.ndarray
) – Fluctuations of the second time series. For power spectrum, should be identical to x. Units: Variable-specificf (
numpy.ndarray
) – Frequency axis of spectra [Hz]mean_wind_speed (
float
) – Mean wind speed used for normalization [m s⁻¹]plot (
bool
, optional) – If True, creates diagnostic plots of the (co)spectrafilename (
str
, optional) – Name of the file being processed, used in plot titlesspectrum_type (
{'spec', 'cospec'}
, optional) – Type of analysis being performed: - ‘spec’: power spectrum - ‘cospec’: co-spectrum
- Returns:
cospec_xy (
numpy.ndarray
) – Log-bin averaged (co)spectrum Co(x’,y’,f) Units: Product of input variable units per Hzcospec_xy_scaled (
numpy.ndarray
) – Normalized and frequency-scaled (co)spectrum f·Co(x’,y’,f)/xy Units: Dimensionlesscospec_xy_integral (
float
) – Integral of the (co)spectrum, equals covariance for co-spectrum or variance for power spectrum Units: Product of input variable units
Notes
The function follows standard procedures for spectral analysis in micrometeorology:
Computes two-sided spectrum using FFT
Extracts and scales the one-sided spectrum
Log-bins the results for clearer visualization
Normalizes by integral and scales by frequency
For co-spectra, the results can be compared to the Kaimal formulations for unstable conditions when properly normalized.
See also
logBinSpectrum
Log-binning of spectral data
theor_cosp_Kaimal
Theoretical Kaimal co-spectrum
References
Examples
>>> # Calculate power spectrum of vertical wind speed >>> w = np.random.randn(18000) # 30 minutes at 10 Hz >>> f = np.fft.fftfreq(18000, d=0.1)[:9000] # Positive frequencies only >>> ini = {'param': { ... 'WINDOW_LENGTH': 1800, ... 'SAMPLING_RATE_FINAL': 10, ... 'NUM_FREQ_BINS': 50, ... 'SENSOR_HEIGHT': 23.5 ... }} >>> spec, spec_scaled, variance = cospectrum( ... ini, w, w, f, 2.5, plot=True, ... spectrum_type='spec' ... )