A Python example using NumPy and SHTns that performs backward and forward Spherical Harmonic Transforms.
A Python example using NumPy and SHTns that performs backward and forward Spherical Harmonic Transforms.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
20
21import numpy
22import shtns
23
24
25lmax = 7
26mmax = 3
27
28sh = shtns.sht(lmax, mmax)
29
30
31nlat, nphi = sh.set_grid()
32print(sh.nlat, sh.nphi)
33
34cost = sh.cos_theta
35el = sh.l
36l2 = el*(el+1)
37
38
44
45ylm = sh.spec_array()
46vr = sh.spat_array()
47
48ylm[sh.idx(1, 0)] = 1.0
49
50print(ylm[sh.l == 1])
51print(ylm[sh.m == 1])
52
53ylm = ylm * l2
54
55y = sh.synth(ylm)
56
57print(y)
58
59i_theta = sh.nlat//2
60i_phi = 1
61print(y[i_theta, i_phi])
62
63
64zlm = sh.analys(y)
65print(zlm)
66
67
68dy_dt, dy_dp = sh.synth_grad(ylm)
69
70