pyshqg.core.spectral_transformations module
Submodule dedicated to the Poisson solver.
- class pyshqg.core.spectral_transformations.SpectralTransformations(backend, T, T_grid, planet_radius=1, planet_omega=1)
Bases:
objectClass for the spectral transformations.
The goal of this class is to define the transformations $x mapsto hat{x} mapsto x$ where $x$ is a variable in grid space and $hat{x}$ is the spectral transform of $x$.
The spectral space has shape $(2, T+1, T+1)$ where $T$ is the spectral truncature. The first index corresponds to the real/imaginary part, the second index corresponds to the spectral index $l$ and the second index corresponds to the spectral index $mleq l$. With this latter constraint, the number of non-zero coefficients is $(T+1)(T+2)$.
The grid space has shape $(T_{mathsf{g}}+1, 2T_{mathsf{g}}+2)$ where $T_{mathsf{g}}$ is the grid truncature. The first index corresponds to the latitude and the second to the longitude.
The transformations implemented in this class only work when $T_{mathsf{g}}geq T$. Note that the number of degrees of freedom in spectral space is $(T+1)(T+2)$ while in grid space it is $2(T_{mathsf{g}+1)^2$. This means that even in the case where $T_{mathsf{g}}=T$, there are more (approximately double) degrees of freedom in grid space. Consequently, the transformation from grid space to spectral space is the inverse of the transformation from spectral space to grid space only on the image of the transformation from spectral to grid space.
- backend
The backend.
- Type:
pyshqg.backend.Backend object
- T
The internal spectral truncature (i.e. the data truncature in spectral space).
- Type:
int
- T_grid
The grid spectral truncature (i.e. the data truncature in grid space), which detrmines the size of the grid: Nlat = T_grid+1 and Nlon=2*Nlat.
- Type:
int
- planet_radius
Planet radius.
- Type:
float
- planet_omega
Planet rotation speed.
- Type:
float
- lats
Latitude nodes.
- Type:
np.ndarray, shape (Nlat,)
- lons
Longitude nodes.
- Type:
np.ndarray, shape (Nlon,)
- legendre
Pre-computed Legendre coefficients for the spectral transformations.
- Type:
dict of str to backend array, shape (Nlat, T+1, T+1)
- laplacian_spectrum
Pre-computed eigen spectrum of the Laplacian operator.
- Type:
backend array, shape (T+1,)
- qp
Pre-computed planet vorticity in grid space.
- Type:
backend array, shape (Nlat, Nlon)
- __init__(backend, T, T_grid, planet_radius=1, planet_omega=1)
Constructor for the spectral transformations.
- Parameters:
backend (pyshqg.backend.Backend object) – The backend.
T (int) – The internal spectral truncature.
T_grid (int) – The grid spectral truncature.
planet_radius (float) – Planet radius.
planet_omega (float) – Planet rotation speed.
- precompute_grid_nodes()
Pre-computes the grid nodes.
- Returns:
lats, lons – Latitude and longitude nodes in degrees.
- Return type:
np.ndarray, shape (Nlat,) and (Nlon,)
- precompute_legendre_coefficients()
Pre-computes the Legendre coefficients.
Several variants are computed:
‘PLM’: for the standard transformation from spectral space to grid space;
‘PPLM’: for the transformation from spectral space to grid space with derivative with respect to longitude;
‘ALM’: for the transformation from spectral space to grid space with derivative with respect to latitude;
‘PW’: for the transformation from grid space to spectral space.
Note that all these coefficients are pre-computed using pyshtools.
- Returns:
legendre – Pre-computed Legendre coefficients for the spectral transformations.
- Return type:
dict of str to backend array, shape (Nlat, T+1, T+1)
- precompute_laplacian_spectrum()
Pre-computes the Laplacian eigen spectrum.
- Returns:
laplacian_spectrum – Pre-computed eigen spectrum of the Laplacian operator.
- Return type:
backend array, shape (T+1,)
- precompute_planet_vorticity()
Pre-computes the planet vorticity $q^{mathsf{p}}$.
Using the $beta$-plane approximation, the planet vorticity $q^{mathsf{p}}$ is defined as…
This method is used by the Poisson solver to define the transformation
- Returns:
qp – Planet vorticity $q^{mathsf{p}}$ in grid space.
- Return type:
backend array, shape (Nlat, Nlon)
- spec_to_grid_generic(spec_x, plm)
Applies the generic transformation from spectral space to grid space.
Use plm=PLM for a regular spectral to grid transformation, plm=PPLM for a transformation with gradients with respect to longitude, and plm=ALM for a transformation with gradients with respect to latitude.
- Parameters:
spec_x (backend array, shape (..., 2, T+1, T+1)) – Variable $hat{x}$ in spectral space.
plm (backend array, shape (Nlat, T+1, T+1)) – One of PLM, PPLM, ALM.
- Returns:
x – Variable $x$ in grid space.
- Return type:
backend array, shape (…, Nlat, Nlon)
- spec_to_grid(spec_x)
Applies the regular transformation from spectral space to grid space.
The spec_to_grid_generic method is used with plm=PLM to implement this transformation.
- Parameters:
spec_x (backend array, shape (..., 2, T+1, T+1)) – Variable $hat{x}$ in spectral space.
- Returns:
x – Variable $x$ in grid space.
- Return type:
backend array, shape (…, Nlat, Nlon)
- spec_to_grid_grad_theta(spec_x)
Applies the transformation from spectral space to grid space with gradients with respect to latitude ($theta$).
The spec_to_grid_generic method is used with plm=ALM to implement this transformation.
- Parameters:
spec_x (backend array, shape (..., 2, T+1, T+1)) – Variable $hat{x}$ in spectral space.
- Returns:
x – Gradient of variable $x$ with respect to latitude in grid space.
- Return type:
backend array, shape (…, Nlat, Nlon)
- spec_to_grid_grad_phi(spec_x)
Applies the transformation from spectral space to grid space with gradients with respect to longitude ($phi$).
The spec_to_grid_generic method is used with plm=PPLM to implement this transformation.
- Parameters:
spec_x (backend array, shape (..., 2, T+1, T+1)) – Variable $hat{x}$ in spectral space.
- Returns:
x – Gradient of variable $x$ with respect to longitude in grid space.
- Return type:
backend array, shape (…, Nlat, Nlon)
- grid_to_spec(x)
Applies the transformation from grid space to spectral space.
- Parameters:
x (backend array, shape (..., Nlat, Nlon)) – Variable $x$ in grid space.
- Returns:
spec_x – Variable $hat{x}$ in spectral space.
- Return type:
backend array, shape (…, 2, T+1, T+1)