[SciPy-user] spherical harmonic
fred
fredantispam at free.fr
Mon Aug 7 07:49:41 EDT 2006
Hi,
I'm playing with spherical harmonic (special.sph_harm()) and I
don't understand what I get.
>From Wolfram (http://mathworld.wolfram.com/SphericalHarmonic.html),
Re_Y11.png, Im_Y11.png & mod_Y11.png seems to be correct
http://fredantispam.free.fr/Re_Y11.png
http://fredantispam.free.fr/Im_Y11.png
http://fredantispam.free.fr/mod_Y11.png
when I use
r =
(sqrt((2*n+1)/4.0/pi)*exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1)))*sin(phi)*exp(1j*m*theta))**2
But when I use special.sph_harm(m,n,theta,phi), I get this
http://fredantispam.free.fr/Re_Y11_2.png
http://fredantispam.free.fr/Im_Y11_2.png
http://fredantispam.free.fr/mod_Y11_2.png
Real & imaginary parts don't seem to be correct.
What I'm doing wrong ?
Cheers,
Here the small code I have used.
from sys import argv
from scipy import pi, cos, sin, exp, sqrt, mgrid, real, imag
from scipy.special import sph_harm, gammaln
from enthought.tvtk.tools import mlab, ivtk
def main():
m = int(argv[1])
n = int(argv[2])
gui = mlab.GUI()
window = ivtk.IVTKWithCrustAndBrowser(size=(1175,773))
window.open()
fig = mlab.Figure(window.scene)
o = mlab.Outline()
fig.add(o)
dphi, dtheta = pi/180, pi/180
[phi, theta] = mgrid[0:pi+dphi:dphi, 0:2*pi+dtheta:dtheta]
### cf. Wolfram : theta <--> phi
r = real(sph_harm(m,n,theta,phi))**2
# r =
real(sqrt((2*n+1)/4.0/pi)*exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1)))*sin(phi)*exp(1j*m*theta))**2
x = r*cos(theta)*sin(phi)
y = r*sin(theta)*sin(phi)
z = r*cos(phi)
s = mlab.Surf(x, y, z, z)
fig.add(s)
window.scene.x_plus_view()
window.scene.camera.parallel_projection = True
window.scene.camera.azimuth(-62)
window.scene.camera.elevation(19.5)
gui.start_event_loop()
if __name__ == '__main__':
main()
--
Fred.
More information about the SciPy-User
mailing list