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

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

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

First, we show a very simple example of usage with Euler angles, though it breaks my heart to do so:1

>>> import spherical as sf
>>> alpha, beta, gamma = 0.1, 0.2, 0.3
>>> ell,mp,m = 3,2,1
>>> sf.Wigner_D_element(alpha, beta, gamma, ell, mp, m)

Of course, it's always better to use unit quaternions to describe rotations:

>>> import numpy as np
>>> import quaternionic
>>> R = quaternionic.array(1,2,3,4).normalized
>>> ell,mp,m = 3,2,1
>>> sf.Wigner_D_element(R, ell, mp, m)

If you need to calculate values of the 𝔇(ℓ) matrix elements for many values of (ℓ, m', m), it is more efficient to do so all at once. The following calculates all modes for ℓ from 2 to 8 (inclusive):

>>> indices = np.array([[ell,mp,m] for ell in range(2,9)
... for mp in range(-ell, ell+1) for m in range(-ell, ell+1)])
>>> sf.Wigner_D_element(R, indices)

Finally, if you really need to put the pedal to the metal, and are willing to guarantee that the input arguments are correct, you can use a special hidden form of the function:

>>> sf._Wigner_D_element(R.a, R.b, indices, elements)

Here, R.a and R.b are the two complex parts of the quaternion defined on this page (though the user need not care about that). The indices variable is assumed to be a two-dimensional array of integers, where the second dimension has size three, representing the (ℓ, m', m) indices. This avoids certain somewhat slower pure-python operations involving argument checking, reshaping, etc. The elements variable must be a one-dimensional array of complex numbers (can be uninitialized), which will be replaced with the corresponding values on return. Again, however, there is no input dimension checking here, so if you give bad inputs, behavior could range from silently wrong to exceptions to segmentation faults. Caveat emptor.

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-0.1.2.tar.gz (391.4 kB view details)

Uploaded Source

Built Distribution

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

spherical-0.1.2-py3-none-any.whl (380.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spherical-0.1.2.tar.gz
  • Upload date:
  • Size: 391.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.0b4 CPython/3.8.5 Linux/5.4.0-1025-azure

File hashes

Hashes for spherical-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ed24fea57f0922d24506febc1702c5eae5d7dfabf8d5cd55353c63d4bebf4275
MD5 d266cbcc901b44a3091226581dfca338
BLAKE2b-256 b8d60abcca29647c4cd5ad6b6a9fe957d33b292d8e904abdb5635e75979da965

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spherical-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 380.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.0b4 CPython/3.8.5 Linux/5.4.0-1025-azure

File hashes

Hashes for spherical-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c153deb88f23a6ae5a6507964c0a6d630b543dfa8bc15585ea2facf7f8ee537
MD5 648c471aa187d6c465682e02e56f4f8b
BLAKE2b-256 415e5dc8ab59fde2345ac4a81305bbf1c73cae6e5eeb3d29e14034cd3ca65e1a

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