The spectra module.¶
This module implements computation of 1D spectra from 2D fields. It is a new addition at 0.5.0.
The main functions are:
New at 0.5
First introduced.
Detailed Module Contents¶
The entire module is documented below.
This program evaluates MONC fields with 4 dimensions (vertical, x, y, time) to produce horizontal power spectra at each time and vertical level written to new netcdf files.
BY DEFAULT, each variable contained in the input file’s xarray.Dataset “Data variables” has its horizontal power spectra evaluated. These are all placed in the same output file.
They can alternatively be placed in a list in the user settings section.
Several options can influence the form of the final result.
Assumes the horizontal grid dimensions are the same for each variable being analysed. Assumes the horizontal dimensions are named ‘x’ and ‘y’. Assumes the vertical dimension is the only dimension with a ‘z’ in its name, but it can be either ‘z’ or ‘zn’. The time dimension name is identified by a user-supplied string, currently: ‘time’.
“Durran” calculation based on Durran et al. (2017): https://doi.org/10.1175/MWR-D-17-0056.1
User must supply:
dir: input directory (slash-agnostic)
file: input file
Suggest switching to argument input (see below)
outtag: output file tag (appended to input file name)
Creates 'spectra/' directory within the given dir
dx: x-direction grid spacing [m]
dy: y-direction grid spacing [m]
@author: Todd Jones @modified: Peter Clark
- subfilter.spectra.spectra_options(config_file=None)¶
- subfilter.spectra.spectra_variable_list(ds, derived_dataset, options, var_list=None)¶
Compute and store 1D forms of 2D power spectra.
- Parameters
ds (xarray dataset) – Input data
derived_dataset (dict) – Output data. ‘ds’:xarray dataset ‘file’: Path to output file.
options (dict) – options for spectral calculations
var_list (list[str], optional) – List of variable names in ds to derive spectra for. The default is None.
- Returns
dso (xarray dataset) – Output data.
outfile (str)
- subfilter.spectra.spectrum_ave_1D(ds, dso, vname, outfile, options, dx, dy)¶
Compute averaged 1D spectra in x and y directions separately. Use real fft of anomalies, Durran et al. (2017), Eq. 13, and average over y results over x direction (and vice versa), handling Nyquist (Kr_delta).
- Parameters
ds (xarray Dataset) – Input data.
dso (xarray Dataset) – Output data.
vname (str) – Variable name (in ds).
outfile (str) – Path to output file.
options (dict) – Options controlling spectrum calculations.
dx (float) – x grid spacing.
dy (float) – y grid spacing.
- Returns
- Return type
None.
- subfilter.spectra.GetPSD1D(psd2D, k)¶
Get PSD 1D (total radial power spectrum) For use with option spec_method: ndimage
- Parameters
psd2D – 2D numpy array containing 2D spectra values
- Returns
- 1D numpy array containing 1D spectra ordered from
wavenumber 0 to highest wavenumber of shortest dimension
- Return type
psd1D
@author: https://gist.github.com/TangibitStudios/47beaf24690329ac7fecddde70835ce9
- subfilter.spectra.prepare_map(fkx, fky, kp, dkh, Nmax)¶
- subfilter.spectra.rad_ave_with_comp(Ek, rlab, index, norm, comp)¶
- subfilter.spectra.rad_ave_without_comp(Ek, rlab, index, norm)¶
- subfilter.spectra.spectrum_ave_1D_radial(ds, dso, vname, outfile, options, dx, dy, kmap=None)¶
Compute averaged 2D spectra averaged to 1D. Use real fft of anomalies, Durran et al. (2017), Eq. 13, and average over y results over x direction (and vice versa), handling Nyquist (Kr_delta).
- Parameters
ds (xarray Dataset) – Input data.
dso (xarray Dataset) – Output data.
vname (str) – Variable name (in ds).
outfile (str) – Path to output file.
options (dict) – Options controlling spectrum calculations.
dx (float) – x grid spacing.
dy (float) – y grid spacing.
kmap (dict, optional) – Previously computed mapping from radial k to 2D grid. The default is None.
- Returns
kmap – Previously computed mapping from radial k to 2D grid.
- Return type
dict