def sph_harm(m, n, az, el, type='complex'):
'''Compute sphercial harmonics
Parameters
----------
m : (int)
Order of the spherical harmonic. abs(m) <= n
n : (int)
Degree of the harmonic, sometimes called l. n >= 0
az: (float)
Azimuthal (longitudinal) coordinate [0, 2pi], also called Theta.
el : (float)
Elevation (colatitudinal) coordinate [0, pi], also called Phi.
Returns
-------
y_mn : (complex float)
Complex spherical harmonic of order m and degree n,
sampled at theta = az, phi = el
'''
if type == 'legacy':
return scy.sph_harm(m, n, az, el)
elif type == 'real':
Lnm = scy.lpmv(_np.abs(m), n, _np.cos(el))
factor_1 = (2 * n + 1) / (4 * _np.pi)
factor_2 = scy.factorial(n - _np.abs(m)) / scy.factorial(n + abs(m))
if m != 0:
factor_1 = 2 * factor_1
if m < 0:
return (-1) ** m * _np.sqrt(factor_1 * factor_2) * Lnm * _np.sin(m * az)
else:
return (-1) ** m * _np.sqrt(factor_1 * factor_2) * Lnm * _np.cos(m * az)
else:
# For the correct Condon–Shortley phase, all m>0 need to be increased by 1
return (-1) ** _np.float_(m - (m < 0) * (m % 2)) * scy.sph_harm(m, n, az, el)
评论列表
文章目录