[SciPy-user] displaying spherical harmonics with different resolution...
robert.kern at gmail.com
Thu Jan 25 18:49:54 CST 2007
> Robert Kern a écrit :
>> I don't think so. Plotting the real and imaginary parts as images gives the same
>> image (modulo resolution) for me on OS X. The problem is possibly in the code
>> that was used to generate the meshes.
> I don't think so too, but who knows ;-)
> Ok, let's see a short example.
> Here, it looks very bad.
> Note that if I replace 2 by 3 in dphi_deg & dtheta_deg,
> it looks very good.
> Where could the bug be hidden ???
> a = scipy.special.sph_harm(m,l,phi,theta)
You have phi and theta backwards assuming we're not using different naming
conventions. I'll fix the docstring to be explicit about which is which. Here,
phi is the polar angle [0, pi] and theta is the azimuthal angle [0, 2*pi].
Here is the implementation (note: *not* Cephes):
"""Spherical harmonic of order m,n (|m|<=n) and argument theta and phi:
x = cos(phi)
m,n = int(m), int(n)
Pmn,Pmnd = lpmn(m,n,x)
val = Pmn[-1, -1]
val *= sqrt((2*n+1)/4.0/pi)
val *= exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1)))
val *= exp(1j*m*theta)
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-user