[Scipy-svn] r6308 - in trunk/scipy/signal: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Apr 6 00:03:16 EDT 2010


Author: warren.weckesser
Date: 2010-04-05 23:03:16 -0500 (Mon, 05 Apr 2010)
New Revision: 6308

Added:
   trunk/scipy/signal/tests/test_windows.py
Modified:
   trunk/scipy/signal/tests/test_signaltools.py
   trunk/scipy/signal/windows.py
Log:
ENH: signal: Added 'chebwin' to the windows understood by get_window();
see ticket #831.  Also moved tests of windows to their own file, and
fixed one test in test_signaltools.py that was missing the actual
comparison to complete the test.


Modified: trunk/scipy/signal/tests/test_signaltools.py
===================================================================
--- trunk/scipy/signal/tests/test_signaltools.py	2010-04-06 02:52:03 UTC (rev 6307)
+++ trunk/scipy/signal/tests/test_signaltools.py	2010-04-06 04:03:16 UTC (rev 6308)
@@ -139,7 +139,9 @@
         d = array([[34,30,44, 62, 66],\
                    [52,48,62, 80, 84],\
                    [82,78,92,110,114]])
+        assert_array_equal(c,d)
 
+
 class OldTestConvolve2d(_TestConvolve2d):
     old_behavior = True
     @dec.deprecated()
@@ -309,49 +311,7 @@
         assert_array_equal(signal.order_filter([1,2,3],[1,0,1],1),
                            [2,3,2])
 
-class TestChebWin:
-    def test_cheb_odd(self):
-        cheb_odd_true = array([0.200938, 0.107729, 0.134941, 0.165348,
-                               0.198891, 0.235450, 0.274846, 0.316836,
-                               0.361119, 0.407338, 0.455079, 0.503883,
-                               0.553248, 0.602637, 0.651489, 0.699227,
-                               0.745266, 0.789028, 0.829947, 0.867485,
-                               0.901138, 0.930448, 0.955010, 0.974482,
-                               0.988591, 0.997138, 1.000000, 0.997138,
-                               0.988591, 0.974482, 0.955010, 0.930448,
-                               0.901138, 0.867485, 0.829947, 0.789028,
-                               0.745266, 0.699227, 0.651489, 0.602637,
-                               0.553248, 0.503883, 0.455079, 0.407338,
-                               0.361119, 0.316836, 0.274846, 0.235450,
-                               0.198891, 0.165348, 0.134941, 0.107729,
-                               0.200938])
 
-        cheb_odd = signal.chebwin(53, at=-40)
-        assert_array_almost_equal(cheb_odd, cheb_odd_true, decimal=4)
-
-    def test_cheb_even(self):
-        cheb_even_true = array([0.203894, 0.107279, 0.133904,
-                                0.163608, 0.196338, 0.231986,
-                                0.270385, 0.311313, 0.354493,
-                                0.399594, 0.446233, 0.493983,
-                                0.542378, 0.590916, 0.639071,
-                                0.686302, 0.732055, 0.775783,
-                                0.816944, 0.855021, 0.889525,
-                                0.920006, 0.946060, 0.967339,
-                                0.983557, 0.994494, 1.000000,
-                                1.000000, 0.994494, 0.983557,
-                                0.967339, 0.946060, 0.920006,
-                                0.889525, 0.855021, 0.816944,
-                                0.775783, 0.732055, 0.686302,
-                                0.639071, 0.590916, 0.542378,
-                                0.493983, 0.446233, 0.399594,
-                                0.354493, 0.311313, 0.270385,
-                                0.231986, 0.196338, 0.163608,
-                                0.133904, 0.107279, 0.203894])
-
-        cheb_even = signal.chebwin(54, at=-40)
-        assert_array_almost_equal(cheb_even, cheb_even_true, decimal=4)
-
 class _TestLinearFilter(TestCase):
     dt = None
     def test_rank1(self):

Added: trunk/scipy/signal/tests/test_windows.py
===================================================================
--- trunk/scipy/signal/tests/test_windows.py	                        (rev 0)
+++ trunk/scipy/signal/tests/test_windows.py	2010-04-06 04:03:16 UTC (rev 6308)
@@ -0,0 +1,65 @@
+
+from numpy import array, ones_like
+from numpy.testing import assert_array_almost_equal, assert_array_equal
+from scipy import signal
+
+
+cheb_odd_true = array([0.200938, 0.107729, 0.134941, 0.165348,
+                       0.198891, 0.235450, 0.274846, 0.316836,
+                       0.361119, 0.407338, 0.455079, 0.503883,
+                       0.553248, 0.602637, 0.651489, 0.699227,
+                       0.745266, 0.789028, 0.829947, 0.867485,
+                       0.901138, 0.930448, 0.955010, 0.974482,
+                       0.988591, 0.997138, 1.000000, 0.997138,
+                       0.988591, 0.974482, 0.955010, 0.930448,
+                       0.901138, 0.867485, 0.829947, 0.789028,
+                       0.745266, 0.699227, 0.651489, 0.602637,
+                       0.553248, 0.503883, 0.455079, 0.407338,
+                       0.361119, 0.316836, 0.274846, 0.235450,
+                       0.198891, 0.165348, 0.134941, 0.107729,
+                       0.200938])
+
+cheb_even_true = array([0.203894, 0.107279, 0.133904,
+                        0.163608, 0.196338, 0.231986,
+                        0.270385, 0.311313, 0.354493,
+                        0.399594, 0.446233, 0.493983,
+                        0.542378, 0.590916, 0.639071,
+                        0.686302, 0.732055, 0.775783,
+                        0.816944, 0.855021, 0.889525,
+                        0.920006, 0.946060, 0.967339,
+                        0.983557, 0.994494, 1.000000,
+                        1.000000, 0.994494, 0.983557,
+                        0.967339, 0.946060, 0.920006,
+                        0.889525, 0.855021, 0.816944,
+                        0.775783, 0.732055, 0.686302,
+                        0.639071, 0.590916, 0.542378,
+                        0.493983, 0.446233, 0.399594,
+                        0.354493, 0.311313, 0.270385,
+                        0.231986, 0.196338, 0.163608,
+                        0.133904, 0.107279, 0.203894])
+
+
+class TestChebWin(object):
+
+    def test_cheb_odd(self):
+        cheb_odd = signal.chebwin(53, at=-40)
+        assert_array_almost_equal(cheb_odd, cheb_odd_true, decimal=4)
+
+    def test_cheb_even(self):
+        cheb_even = signal.chebwin(54, at=-40)
+        assert_array_almost_equal(cheb_even, cheb_even_true, decimal=4)
+
+
+class TestGetWindow(object):
+
+    def test_boxcar(self):
+        w = signal.get_window('boxcar', 12)
+        assert_array_equal(w, ones_like(w))
+
+    def test_cheb_odd(self):
+        w = signal.get_window(('chebwin', -40), 53, fftbins=False)
+        assert_array_almost_equal(w, cheb_odd_true, decimal=4)
+
+    def test_cheb_even(self):
+        w = signal.get_window(('chebwin', -40), 54, fftbins=False)
+        assert_array_almost_equal(w, cheb_even_true, decimal=4)

Modified: trunk/scipy/signal/windows.py
===================================================================
--- trunk/scipy/signal/windows.py	2010-04-06 02:52:03 UTC (rev 6307)
+++ trunk/scipy/signal/windows.py	2010-04-06 04:03:16 UTC (rev 6308)
@@ -377,7 +377,7 @@
                    parzen, bohman, blackmanharris, nuttall, barthann,
                    kaiser (needs beta), gaussian (needs std),
                    general_gaussian (needs power, width),
-                   slepian (needs width)
+                   slepian (needs width), chebwin (needs attenuation)
 
     If the window requires no parameters, then it can be a string.
     If the window requires parameters, the window argument should be a tuple
@@ -400,8 +400,10 @@
             if window in ['kaiser', 'ksr', 'gaussian', 'gauss', 'gss',
                         'general gaussian', 'general_gaussian',
                         'general gauss', 'general_gauss', 'ggs',
-                        'slepian', 'optimal', 'slep', 'dss']:
-                raise ValueError, "That window needs a parameter -- pass a tuple"
+                        'slepian', 'optimal', 'slep', 'dss',
+                        'chebwin', 'cheb']:
+                raise ValueError("The '" + window + "' window needs one or "
+                                    "more parameters  -- pass a tuple.")
             else:
                 winstr = window
 
@@ -438,12 +440,14 @@
             winfunc = boxcar
         elif winstr in ['slepian', 'slep', 'optimal', 'dss']:
             winfunc = slepian
+        elif winstr in ['chebwin', 'cheb']:
+            winfunc = chebwin
         else:
             raise ValueError, "Unknown window type."
 
-        params = (Nx,)+args + (sym,)
+        params = (Nx,) + args + (sym,)
     else:
         winfunc = kaiser
-        params = (Nx,beta,sym)
+        params = (Nx, beta, sym)
 
     return winfunc(*params)




More information about the Scipy-svn mailing list