[Scipy-svn] r6255 - trunk/scipy/special/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Mar 16 21:46:41 EDT 2010


Author: matthew.brett at gmail.com
Date: 2010-03-16 20:46:41 -0500 (Tue, 16 Mar 2010)
New Revision: 6255

Modified:
   trunk/scipy/special/tests/test_basic.py
Log:
TEST - selected tests of spherical harmonics from Wikipedia spherical harmonics table

Modified: trunk/scipy/special/tests/test_basic.py
===================================================================
--- trunk/scipy/special/tests/test_basic.py	2010-03-09 13:31:00 UTC (rev 6254)
+++ trunk/scipy/special/tests/test_basic.py	2010-03-17 01:46:41 UTC (rev 6255)
@@ -2017,11 +2017,42 @@
         # correctly written.
         rndrl = (10,10,10,11)
         assert_array_equal(rnd,rndrl)
+        
 
+def test_sph_harm():
+    # Tests derived from tables in
+    # http://en.wikipedia.org/wiki/Table_of_spherical_harmonics
+    sh = sph_harm
+    pi = np.pi
+    exp = np.exp
+    sqrt = np.sqrt
+    sin = np.sin
+    cos = np.cos
+    yield (assert_array_almost_equal, sh(0,0,0,0),
+           0.5/sqrt(pi))
+    yield (assert_array_almost_equal, sh(-2,2,0.,pi/4),
+           0.25*sqrt(15./(2.*pi))*
+           (sin(pi/4))**2.)
+    yield (assert_array_almost_equal, sh(-2,2,0.,pi/2),
+           0.25*sqrt(15./(2.*pi)))
+    yield (assert_array_almost_equal, sh(2,2,pi,pi/2),
+           0.25*sqrt(15/(2.*pi))*
+           exp(0+2.*pi*1j)*sin(pi/2.)**2.)
+    yield (assert_array_almost_equal, sh(2,4,pi/4.,pi/3.),
+           (3./8.)*sqrt(5./(2.*pi))*
+           exp(0+2.*pi/4.*1j)*
+           sin(pi/3.)**2.*
+           (7.*cos(pi/3.)**2.-1))
+    yield (assert_array_almost_equal, sh(4,4,pi/8.,pi/6.),
+           (3./16.)*sqrt(35./(2.*pi))*
+           exp(0+4.*pi/8.*1j)*sin(pi/6.)**4.)
+
+
 class TestSpherical(TestCase):
     def test_sph_harm(self):
+        # see test_sph_harm function
         pass
-
+    
     def test_sph_in(self):
         i1n = sph_in(1,.2)
         inp0 = (i1n[0][1])




More information about the Scipy-svn mailing list