Skip to main content

Evaluate and transform D matrices, 3-j symbols, and (scalar or spin-weighted) spherical harmonics

Project description

Test Status Test Coverage Documentation Status PyPI Version Conda Version DOI

Spherical Functions

Python/numba package for evaluating and transforming Wigner's 𝔇 matrices, Wigner's 3-j symbols, and spin-weighted (and scalar) spherical harmonics. These functions are evaluated directly in terms of quaternions, as well as in the more standard forms of spherical coordinates and Euler angles.1

These quantities are computed using recursion relations, which makes it possible to compute to very high ℓ values. Unlike direct evaluation of individual elements, which will generally cause overflow or underflow beyond ℓ≈30, these recursion relations should be accurate for ℓ values beyond 1000.

The conventions for this package are described in detail on this page.

Installation

Because this package is pure python code, installation is very simple. In particular, with a reasonably modern installation, you can just run a command like

conda install -c conda-forge spherical

or

python -m pip install spherical

Either of these will download and install the package.

Usage

Functions of angles or rotations

Currently, due to the nature of recursions, this module does not allow calculation of individual elements, but returns ranges of results. For example, when computing Wigner's 𝔇 matrix, all matrices up to a given ℓ will be returned; when evaluating a spin-weighted spherical harmonic, all harmonics up to a given ℓ will be returned. Fortunately, this is usually what is required in any case.

To calculate Wigner's d or 𝔇 matrix or spin-weighted spherical harmonics, first construct a Wigner object.

import quaternionic
import spherical
ell_max = 16  # Use the largest ℓ value you expect to need
wigner = spherical.Wigner(ell_max)

This module takes input as quaternions. The quaternionic module has various ways of constructing quaternions, including direct construction or conversion from rotation matrices, axis-angle representation, Euler angles,1 or spherical coordinates, among others:

R = quaternionic.array([1, 2, 3, 4]).normalized
R = quaternionic.array.from_axis_angle(vec)
R = quaternionic.array.from_euler_angles(alpha, beta, gamma)
R = quaternionic.array.from_spherical_coordinates(theta, phi)

Mode weights can be rotated as

wigner.rotate(modes, R)

or evaluated as

wigner.evaluate(modes, R)

We can compute the 𝔇 matrix as

D = wigner.D(R)

which can be indexed as

D[wigner.Dindex(ell, mp, m)]

or we can compute the spin-weighted spherical harmonics as

Y = wigner.sYlm(s, R)

which can be indexed as

Y[wigner.Yindex(ell, m)]

Note that, if relevant, it is probably more efficient to use the rotate and evaluate methods than to use D or Y.

Clebsch-Gordan and 3-j symbols

It is possible to compute individual values of the 3-j or Clebsch-Gordan symbols:

w3j = spherical.Wigner3j(j_1, j_2, j_3, m_1, m_2, m_3)
cg = spherical.clebsch_gordan(j_1, m_1, j_2, m_2, j_3, m_3)

However, when more than one element is needed (as is typically the case), it is much more efficient to compute a range of values:

calc3j = spherical.Wigner3jCalculator(j2_max, j3_max)
w3j = calc3j.calculate(j2, j3, m2, m3)

Acknowledgments

I very much appreciate Barry Wardell's help in sorting out the relationships between my conventions and those of other people and software packages (especially Mathematica's crazy conventions).

This code is, of course, hosted on github. Because it is an open-source project, the hosting is free, and all the wonderful features of github are available, including free wiki space and web page hosting, pull requests, a nice interface to the git logs, etc.

The work of creating this code was supported in part by the Sherman Fairchild Foundation and by NSF Grants No. PHY-1306125 and AST-1333129.



1 Euler angles are awful

Euler angles are pretty much the worst things ever and it makes me feel bad even supporting them. Quaternions are faster, more accurate, basically free of singularities, more intuitive, and generally easier to understand. You can work entirely without Euler angles (I certainly do). You absolutely never need them. But if you're so old fashioned that you really can't give them up, they are fully supported.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spherical-1.1.0.tar.gz (83.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spherical-1.1.0-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

Details for the file spherical-1.1.0.tar.gz.

File metadata

  • Download URL: spherical-1.1.0.tar.gz
  • Upload date:
  • Size: 83.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.13 HTTPX/0.28.1

File hashes

Hashes for spherical-1.1.0.tar.gz
Algorithm Hash digest
SHA256 17a069f788c3989e0c8b244ff9c765fabedb6cb279cf10d6d7bccfb820e401d9
MD5 a973eed9474da24ece35275f0cb39109
BLAKE2b-256 bdfc815c0485689cc93c3c3c934a6cb0ad15f9d8d61281c7637b703e3fae7beb

See more details on using hashes here.

File details

Details for the file spherical-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: spherical-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.13 HTTPX/0.28.1

File hashes

Hashes for spherical-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83d49a036749caaa2ab15a2ffecad76626137e08c050486a3095c786fd936e6f
MD5 f5ca81eea7f73b50928cdedc1b203ba2
BLAKE2b-256 87b64b7ff8811fd1fa3e66b691a4787a2d123899014d1a489ff96aac8968b6e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page