SHTns 3.7
Using SHTns with Python

SHTns provides a Python interface that uses NumPy arrays to perform Spherical Harmonic Transforms. The Python interface has been generated using SWIG (but you don't need it to compile the the Python package).

  • You can install the python module from the pypi repository:
    pip install shtns
    It is also possible to install from the source tree with:
    pip install .
    or
    python setup.py install --user
    In case you don't want OpenMP support, you can disable it by adding SHTNS_OPENMP=0 in front of the above commands.
  • Use within a python script or shell
    import shtns

To start using SHTns you must then create an sht object, from which you can call the transform functions and more. The arrays should be created using NumPy.

The Python interface also supports cuda GPU transparently, if the CUDA_PATH environment variable was pointing to the cuda toolkit installed on your system when you installed the shtns module (see above). To enable transforms on GPU, grids must be set with SHT_ALLOW_GPU and SHT_THETA_CONTIGUOUS.

See also
See the Python example and Python GPU example to get started.

There is also and the full working example shallow_water.py that solves the non-linear shallow water equations.

In case of segfaults, you may have alignment problems (should not occur on 64 bit systems). Please file a bugreport or contact the author.