Spin-weighted spherical harmonics

[1]:
import numpy as np

import few

# tune few configuration
cfg_set = few.get_config_setter(reset=True)
cfg_set.enable_backends("cpu")  # This tutorial only uses CPU
cfg_set.set_log_level("info")
cfg_set.finalize()
[2]:
from few.utils.ylm import GetYlms

ylm_gen = GetYlms(assume_positive_m=False)

ls = np.array([2, 3, 4, 5])
ms = np.array([2, 2, 3, 3])

# viewing angles
theta = np.pi / 3
phi = np.pi / 4

print(ylm_gen(ls, ms, theta, phi))
[ 2.17261840e-17+3.54815511e-01j -1.28533838e-17-2.09911687e-01j
  1.24292687e-16-1.24292687e-16j -2.46692086e-01+2.46692086e-01j]

If we assume positive m, it will return -m entries for all +m. The last 5 below are for -m. The final shape will be twice the initial length and will duplicate m=0 so be careful.

[3]:
ylm_gen = GetYlms(assume_positive_m=True)

ls = np.array([2, 3, 4, 5, 2])
ms = np.array([2, 2, 3, 3, 0])

# viewing angles
theta = np.pi / 3
phi = np.pi / 4

ylms = ylm_gen(ls, ms, theta, phi)

for l, m, ylm in zip(ls, ms, ylms[:5]):
    print("({},{}):".format(l, m), ylm)

for l, m, ylm in zip(ls, ms, ylms[5:]):
    print("({},-{}):".format(l, m), ylm)
(2,2): (2.1726183986132197e-17+0.3548155109090852j)
(3,2): (-1.285338378442592e-17-0.20991168708193983j)
(4,3): (1.242926870060164e-16-1.2429268700601641e-16j)
(5,3): (-0.24669208642519014+0.2466920864251902j)
(2,0): (0.2897056515173922+0j)
(2,-2): (2.4140204429035754e-18-0.039423945656564985j)
(3,-2): (-9.997076276775717e-18+0.16326464550817543j)
(4,-3): (-0.12119256904280647-0.12119256904280648j)
(5,-3): (0.235727993695182+0.23572799369518202j)
(2,-0): (0.2897056515173922+0j)