Spherical harmonics
In pyshqg, the QG model is expressed in spherical harmonics.
In this page, we give a brief technical overview of spherical harmonics.
Spherical harmonics functions
Let \(P_{l}, l\in\mathbb{N}\) be Legendre polynomials, defined by
The associate Legendre functions \(\bar{P}_{l,m}, l\in\mathbb{N}, m\in\{0, \ldots, l\}\) are defined by
and the spherical harmonics functions \(Y_{l,m}, l\in\mathbb{N}, m\in\{-l, \ldots, l\}\), defined on the sphere, are given by
where \(\theta\) and \(\phi\) are the co-latitude and longitude, respectively.
The spherical harmonics functions form an orthonormal basis of the real, square-integrable functions on the sphere, so that any such function \(f\) can be expressed as the series
where the spherical harmonics coefficients \(f_{l,m}\) are given by
Spectral truncation
In the QG model, we use a so-called triangular spectral trunctation, in which all the spectral modes are kept up to a selected spectral degree \(T\). Consequently, the series expansion of \(f\) becomes
Using this truncature, the number of degrees of freedom is \((T+1)^{2}\).
In practice, the spectral coefficients \(f_{l,m}\) are usually stored in an array with shape \((2, T+1, T+1)\), where the second dimension represents the spectral degree \(l\), the third dimension represents the absolute value of the spectral mode \(m\), and the first dimension represents the sign of the spectral mode \(m\). This representation is suboptimal in terms of memory (because of the constraint \(|m|\leq l\), half of the array is unused) but turns out to be well suited for spectral transformations.
Quadrature
In order to numerically evaluate the spectral coefficients \(f_{l,m}\), the most convenient approach is to use a predefined quadrature, where the integrand is evaluated at a given number of points on the sphere.
In the QG model, we choose to use the Gauss–Legendre quadrature, in which integrands are evaluated on a rectangular grid with \(N_{\mathsf{lat}}\) co-latitudes \(\theta_{i}, i\in\{1, \ldots, N_{\mathsf{lat}}\}\) and \(N_{\mathsf{lon}}\) longitudes \(\phi_{j}, j\in\{1, \ldots, N_{\mathsf{lon}}\}\). The co-latitudes \(\theta_{i}\) are chosen as the zeros of the Legendre Polynomial \(P_{N_{\mathsf{lat}}}\), while the longitudes are evenly sampled over \([0, 2\pi]\). Using a rectangular quadrature means that polar areas are over-sampled, which is compensated by weighting the grid nodes with a factor \(w_{i}\) that depends only on latitude, called Gauss–Legendre weight.
As long as the number of co-latitudes \(N_{\mathsf{lat}}\) is larger than \(T+1\) and the number of longitudes \(N_{\mathsf{lon}}\) is larger than \(2T+1\), the Gauss–Legendre quadrature is exact. In particular, the spectral coefficients \(f_{l,m}\) are then given by
For simplicity, in the QG model we always choose to use \(N_{\mathsf{lon}}=2N_{\mathsf{lat}}\), but this constraint is not mandatory. In practice, the values of the function \(f\) are stored in an array with shape \((N_{\mathsf{lat}}, N_{\mathsf{lon}})\). Note that, even in the case where \(N_{\mathsf{lat}}=T+1\) and \(N_{\mathsf{lon}}=2T+1\), which is the smallest possible grid for a given truncature \(T\), the number of degrees of freedom in this grid space is \((T+1)(2T+1)\), which is almost double the number of degrees of freedom in spectral space, \((T+1)^{2}\). The grid is hence widely oversampled.
Spectral transformation
The direct spectral transformation is the operation that maps the gridded values of \(f\) – array with shape \((N_{\mathsf{lat}}, N_{\mathsf{lon}})\) – into the spectral coefficients \(f_{l, m}\) – array with shape \((2, T+1, T+1)\). According to the formulae of \(f_{l, m}\), there are two sums to compute.
The first sum, over \(i\), is usually referred to as Legendre transformation,
and is typically computed using functions such as numpy.einsum. Note that
in that operation, the \(\bar{P}_{l, m}(\mathrm{cos}\theta_{i})w_{i}\) factors
do not depend on \(f\) and hence can be precomputed once the grid is fixed
and then used for multiple spectral transformations.
The second sum, over \(j\), is usually referred to as Fourier transformation, and can be computed using specific implementations of the discrete Fourier transform since it has been assumed that the longitudes are evenly distributed.
The inverse spectral transformation is simply the inverse of the direct spectral transformation.
Longitudinal derivative
From the expressions of the spherical harmonics functions \(Y_{l,m}\), we see that
Therefore, the spectral coefficients \(g_{l,m}\) of the longitudinal derivative of \(f\) are related to the spectral coefficients \(f_{l,m}\) of \(f\) by
Latitudinal derivative
Let us define the \(A_{l,m}\) functions by
in such a way that
Consequently, it is possible to compute the values of the latitudinal derivative of \(f\) in the grid from the spectral coefficients \(f_{l,m}\) of \(f\) by applying an inverse spectral transformation where the precomputed values of the \(\bar{P}_{l, m}(\mathrm{cos}\theta_{i})w_{i}\) factors are replaced by precomputed values of \(A_{l, m}(\theta_{i})w_{i}\) factors.