[SciPy-user] Spherical Harmonics

Arne Keller arne.keller at ppm.u-psud.fr
Sat Jan 22 09:33:47 EST 2005


Hi,
I'm trying to use the sph_harm special function, but it has a very
strange behavior, sometimes it fails with a segmentation fault.

If someone can try to execute these lines of codes, to see if he obtains
the same result:

##########################################################
## file test.py
##########################################################
import scipy
from scipy.special import sph_harm,lpmn,gammaln
from scipy import *

#n=1 #uncommenting this line produce a segmentation fault!

#taken from special/basic.py:
def sph_harmonic(m,n,theta,phi):
    """inputs of (m,n,theta,phi) returns spherical harmonic of order
    m,n (|m|<=n) and argument theta and phi:  Y^m_n(theta,phi)
    """
    x = cos(phi)
    m,n = int(m), int(n)
    Pmn,Pmnd = lpmn(m,n,x)
    val = Pmn[m,n]
    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)
    return val

n=1
m=1
theta=pi/2.
phi=0.
print sph_harmonic(m,n,phi,theta)

################End test #################################
it produces (-0.345494149471+0j)


but When I uncomment the first line ('n=1'), then a segmentation fault
occurs (if the line is uncommented but with 'n=2' instead of 'n=1' then
the execution is normal).

Please may anybody help?

Many thanks






More information about the SciPy-User mailing list