Spherical harmonics operators (fluiddyn.calcul.sphericalharmo)

This module requires the C library shtns. To install it, run something like:

./configure --enable-openmp --enable-python
make && make install
class fluiddyn.calcul.sphericalharmo.EasySHT(lmax=15, mmax=None, mres=1, norm=None, nlat=None, nlon=None, flags=None, polar_opt=1e-08, nl_order=2, radius=6367470.0)[source]

Bases: object

Simple possibilities of shtns.

Less possibilities but very simple to use… It has been written specially for atmospheric applications.

Creation of a default instance:

esh = EasySHT(lmax=15)
lmaxnumber {15}

Truncation degree.

mmax{None, int}

If is None, triangular truncation.


Azimutal symmetry coefficient (see shtns documentation).


For SH with quadratic mean equal to unity.

nlat{None, int}

If None, computed by shtns to avoid aliasing.

nlon{None, int}

If None, computed by shtns to avoid aliasing.

flags{sht_quick_init|SHT_PHI_CONTIGUOUS|SHT_SOUTH_POLE_FIRST, int}

Option flag for shtns.

polar_opt{1.0e-8, float}

Polar optimization threshold.

nl_order{2, int}

Nonlinear order of the equations (used to compute nlat and nlon).

radius{radius_earth, number}

Radius of the sphere (in meters)


In contrast as with shtns, with easypysht the meridional unit vector points towards the North if shtns.SHT_SOUTH_POLE_FIRST is used (this is the default) and it points towards the South if shtns.SHT_SOUTH_POLE_FIRST is not given in flags (thus there is a change of sign in the meridional velocity).

easypysht has been written for atmospheric applications thus some usual notations are used.

Here are some definitions useful to understand the code:

  • l denotes the degree of the spherical harmonic functions

  • m denotes the order of the spherical harmonic functions

  • SH denotes spherical harmonic (spectral array)

  • spat denotes spatial array

  • lat denotes latitude

  • lon denotes longitude

  • kh denotes horizontal wavenumber

  • u denotes longitudinal velocity

  • v denotes meridional velocity (the sign depends on the used base)

  • hdiv denotes horizontal divergence

  • hrot denotes vertical vorticity (curl on the sphere)

  • grad denotes the horizontal gradient

Variables and functions about spectral space array: lmax, mmax, mres, nlm, idx_lm(), l_idx, m_idx, l2_idx

Variables about grid and real space array: nlat, nlon, lats, lons, sin_lats, LATS, LONS

Variables for spectra: l2_l, kh_l

self.sh is the instance of the class sht defined in shtns.py. All functions and variables of this class can be used directly from this instance, for example:

esh.sh.sh_to_point(f_lm, cost, phi)

where t is the colatitude and phi is the longitude.


Produce a string describing the operator.

idx_lm(self, l, m)[source]
create_array_sh(value=None, dtype=<class 'complex'>)[source]

Create an array representing a field in spectral space.


Create an array representing a field in spatial space.

sh_from_spat(field, field_lm=None)[source]

Spherical harmonic transform.

examples: f_lm = sh_from_spat(f)

or if f_lm already exists: sh_from_spat(f, f_lm)

spat_from_sh(field_lm, field=None)[source]

Inverse spherical harmonic transform.


Microbenchmark forward and inverse SHT, and vorticity, divergence <-> u, v transformations.

uv_from_hdivrotsh(hdiv_lm, hrot_lm, uu=None, vv=None)[source]

u, v from div, rot (u and v are overwritten)

hdivrotsh_from_uv(uu, vv, hdiv_lm=None, hrot_lm=None)[source]

Compute hdivrotsh from uuvv.

(div_lm and rot_lm are overwritten)

uv_from_uDuRsh(uD_lm, uR_lm, uu=None, vv=None)[source]

Compute velocities uu, vv from uD, uR (uu and vv are overwritten).

uDuRsh_from_uv(uu, vv, uD_lm=None, uR_lm=None)[source]

Compute helmholtz decomposition of the velocities from uu, vv. (uD_lm and uR_lm are overwritten).

hdivrotsh_from_uDuRsh(uD_lm, uR_lm, hdiv_lm=None, hrot_lm=None)[source]

Compute horizontal divergence and vertical vorticity spherical harmonics from velocity vector spherical harmonics (hdiv_lm and hrot_lm are overwritten).

uDuRsh_from_hdivrotsh(hdiv_lm, hrot_lm, uD_lm=None, uR_lm=None)[source]

Compute velocity vector spherical harmonics from horizontal divergence and vertical vorticity spherical harmonics (uD_lm and uR_lm are overwritten).

gradf_from_fsh(f_lm, gradf_lon=None, gradf_lat=None)[source]

gradf from fsh.

Compute the gradient of a function f from its spherical harmonic coeff f_lm (gradf_lon and gradf_lat are overwritten)


Convenient function to look more like a pseudo-spectral Operators


Compute spectrum(l) from array_desh(ilm)

_array_desh_from_sh(field_lm, key_field)[source]

Compute the array_desh (density of energy) from an field_lm

spectrum_from_sh(field_lm, key_field)[source]

compute spectrum from field_lm

cospectrum_from_2fieldssh(f_lm, g_lm)[source]

compute cospectrum(l) from f_lm(ilm) and g_lm(ilm)

cospectrum_from_2vectorssh(f_lon_lm, f_lat_lm, g_lon_lm, g_lat_lm)[source]

compute cospectrum(l)…

cospectrum_from_2fieldssh2(f_lm, g_lm)[source]

compute cospectrum(l)…

cospectrum_from_2divrotsh(hdiva_lm, hrota_lm, hdivb_lm, hrotb_lm)[source]

compute cospectrum(l)…


Convenient function for fluidsim


bin_int(n, width)

compute_lmax(nlat[, nl_order])

compute_nlatnlon(lmax[, nl_order])


EasySHT([lmax, mmax, mres, norm, nlat, ...])

Simple possibilities of shtns.