[Scipy-svn] r6876 - trunk/scipy/signal

scipy-svn at scipy.org scipy-svn at scipy.org
Sat Nov 13 15:36:14 EST 2010


Author: warren.weckesser
Date: 2010-11-13 14:36:14 -0600 (Sat, 13 Nov 2010)
New Revision: 6876

Modified:
   trunk/scipy/signal/filter_design.py
   trunk/scipy/signal/ltisys.py
   trunk/scipy/signal/signaltools.py
Log:
ENH: signal: update 'raise' statements.

Modified: trunk/scipy/signal/filter_design.py
===================================================================
--- trunk/scipy/signal/filter_design.py	2010-11-13 20:20:24 UTC (rev 6875)
+++ trunk/scipy/signal/filter_design.py	2010-11-13 20:36:14 UTC (rev 6876)
@@ -238,9 +238,9 @@
     """
     b,a = map(atleast_1d,(b,a))
     if len(a.shape) != 1:
-        raise ValueError, "Denominator polynomial must be rank-1 array."
+        raise ValueError("Denominator polynomial must be rank-1 array.")
     if len(b.shape) > 2:
-        raise ValueError, "Numerator polynomial must be rank-1 or rank-2 array."
+        raise ValueError("Numerator polynomial must be rank-1 or rank-2 array.")
     if len(b.shape) == 1:
         b = asarray([b],b.dtype.char)
     while a[0] == 0.0 and len(a) > 1:
@@ -451,9 +451,9 @@
     try:
         ordfunc = filter_dict[ftype][1]
     except KeyError:
-        raise ValueError, "Invalid IIR filter type."
+        raise ValueError("Invalid IIR filter type: %s" % ftype)
     except IndexError:
-        raise ValueError, "%s does not have order selection use iirfilter function." % ftype
+        raise ValueError("%s does not have order selection use iirfilter function." % ftype)
 
     wp = atleast_1d(wp)
     ws = atleast_1d(ws)
@@ -515,15 +515,15 @@
     try:
         btype = band_dict[btype]
     except KeyError:
-        raise ValueError, "%s is an invalid bandtype for filter." % btype
+        raise ValueError("%s is an invalid bandtype for filter." % btype)
 
     try:
         typefunc = filter_dict[ftype][0]
     except KeyError:
-        raise ValueError, "%s is not a valid basic iir filter." % ftype
+        raise ValueError("%s is not a valid basic iir filter." % ftype)
 
     if output not in ['ba', 'zpk']:
-        raise ValueError, "%s is not a valid output form." % output
+        raise ValueError("%s is not a valid output form." % output)
 
     #pre-warp frequencies for digital filter design
     if not analog:
@@ -544,15 +544,15 @@
         z, p, k = typefunc(N)
     elif typefunc == cheb1ap:
         if rp is None:
-            raise ValueError, "passband ripple (rp) must be provided to design a Chebyshev I filter."
+            raise ValueError("passband ripple (rp) must be provided to design a Chebyshev I filter.")
         z, p, k = typefunc(N, rp)
     elif typefunc == cheb2ap:
         if rs is None:
-            raise ValueError, "stopband atteunatuion (rs) must be provided to design an Chebyshev II filter."
+            raise ValueError("stopband atteunatuion (rs) must be provided to design an Chebyshev II filter.")
         z, p, k = typefunc(N, rs)
     else:  # Elliptic filters
         if rs is None or rp is None:
-            raise ValueError, "Both rp and rs must be provided to design an elliptic filter."
+            raise ValueError("Both rp and rs must be provided to design an elliptic filter.")
         z, p, k = typefunc(N, rp, rs)
 
     b, a = zpk2tf(z,p,k)
@@ -694,7 +694,7 @@
         d1 = special.ellipk([arg1**2, 1-arg1**2])
         n = (d0[0]*d1[1] / (d0[1]*d1[0]))
     else:
-        raise ValueError, "Incorrect type: ", type
+        raise ValueError("Incorrect type: %s" % type)
     return n
 
 def buttord(wp, ws, gpass, gstop, analog=0):
@@ -800,7 +800,7 @@
                                               passb[0]*passb[1])
         WN = numpy.sort(abs(WN))
     else:
-        raise ValueError, "Bad type."
+        raise ValueError("Bad type: %s" % filter_type)
 
     if not analog:
         wn = (2.0/pi)*arctan(WN)
@@ -1179,7 +1179,7 @@
     ck1 = eps / numpy.sqrt(10**(0.1*rs)-1)
     ck1p = numpy.sqrt(1-ck1*ck1)
     if ck1p == 1:
-        raise ValueError, "Cannot design a filter with given rp and rs specifications."
+        raise ValueError("Cannot design a filter with given rp and rs specifications.")
 
     wp = 1
     val = special.ellipk([ck1*ck1,ck1p*ck1p])
@@ -1585,7 +1585,7 @@
              -.2373280669322028974199184-1.211476658382565356579418*1j,
              -.2373280669322028974199184+1.211476658382565356579418*1j]
     else:
-        raise ValueError, "Bessel Filter not supported for order %d" % N
+        raise ValueError("Bessel Filter not supported for order %d" % N)
 
     return z, p, k
 

Modified: trunk/scipy/signal/ltisys.py
===================================================================
--- trunk/scipy/signal/ltisys.py	2010-11-13 20:20:24 UTC (rev 6875)
+++ trunk/scipy/signal/ltisys.py	2010-11-13 20:36:14 UTC (rev 6876)
@@ -50,7 +50,7 @@
     M = num.shape[1]
     K = len(den)
     if (M > K):
-        raise ValueError, "Improper transfer function."
+        raise ValueError("Improper transfer function.")
     if (M == 0 or K == 0):  # Null system
         return array([],float), array([], float), array([], float), \
                array([], float)
@@ -87,7 +87,7 @@
 
     if ((len(A.shape) > 2) or (len(B.shape) > 2) or \
         (len(C.shape) > 2) or (len(D.shape) > 2)):
-        raise ValueError, "A, B, C, D arrays can be no larger than rank-2."
+        raise ValueError("A, B, C, D arrays can be no larger than rank-2.")
 
     MA, NA = A.shape
     MB, NB = B.shape
@@ -108,15 +108,15 @@
         A = zeros(MA, NA)
 
     if MA != NA:
-        raise ValueError, "A must be square."
+        raise ValueError("A must be square.")
     if MA != MB:
-        raise ValueError, "A and B must have the same number of rows."
+        raise ValueError("A and B must have the same number of rows.")
     if NA != NC:
-        raise ValueError, "A and C must have the same number of columns."
+        raise ValueError("A and C must have the same number of columns.")
     if MD != MC:
-        raise ValueError, "C and D must have the same number of rows."
+        raise ValueError("C and D must have the same number of rows.")
     if ND != NB:
-        raise ValueError, "B and D must have the same number of columns."
+        raise ValueError("B and D must have the same number of columns.")
 
     return A, B, C, D
 
@@ -145,7 +145,7 @@
 
     nout, nin = D.shape
     if input >= nin:
-        raise ValueError, "System does not have the input specified."
+        raise ValueError("System does not have the input specified.")
 
     # make MOSI from possibly MOMI system.
     if B.shape[-1] != 0:
@@ -256,7 +256,7 @@
             self.inputs = self.B.shape[-1]
             self.outputs = self.C.shape[0]
         else:
-            raise ValueError, "Needs 2, 3, or 4 arguments."
+            raise ValueError("Needs 2, 3, or 4 arguments.")
 
     def __setattr__(self, attr, val):
         if attr in ['num','den']:
@@ -368,7 +368,7 @@
 
     T = atleast_1d(T)
     if len(T.shape) != 1:
-        raise ValueError, "T must be a rank-1 array."
+        raise ValueError("T must be a rank-1 array.")
 
     if U is not None:
         U = atleast_1d(U)
@@ -459,12 +459,12 @@
         U = U.reshape((U.shape[0],1))
     sU = U.shape
     if len(T.shape) != 1:
-        raise ValueError, "T must be a rank-1 array."
+        raise ValueError("T must be a rank-1 array.")
     if sU[0] != len(T):
         raise ValueError("U must have the same number of rows "
                          "as elements in T.")
     if sU[1] != sys.inputs:
-        raise ValueError, "System does not define that many inputs."
+        raise ValueError("System does not define that many inputs.")
 
     if X0 is None:
         X0 = zeros(sys.B.shape[0], sys.A.dtype)
@@ -634,7 +634,7 @@
         sys = lti(*system)
     B = sys.B
     if B.shape[-1] != 1:
-        raise ValueError, "impulse2() requires a single-input system."
+        raise ValueError("impulse2() requires a single-input system.")
     B = B.squeeze()
     if X0 is None:
         X0 = zeros_like(B)

Modified: trunk/scipy/signal/signaltools.py
===================================================================
--- trunk/scipy/signal/signaltools.py	2010-11-13 20:20:24 UTC (rev 6875)
+++ trunk/scipy/signal/signaltools.py	2010-11-13 20:36:14 UTC (rev 6876)
@@ -39,8 +39,8 @@
         val = _modedict[mode]
     except KeyError:
         if mode not in [0,1,2]:
-            raise ValueError, "Acceptable mode flags are 'valid' (0)," \
-                  "'same' (1), or 'full' (2)."
+            raise ValueError("Acceptable mode flags are 'valid' (0),"
+                    " 'same' (1), or 'full' (2).")
         val = mode
     return val
 
@@ -49,8 +49,8 @@
         val = _boundarydict[boundary] << 2
     except KeyError:
         if val not in [0,1,2] :
-            raise ValueError, "Acceptable boundary flags are 'fill', 'wrap'" \
-                  " (or 'circular'), \n  and 'symm' (or 'symmetric')."
+            raise ValueError("Acceptable boundary flags are 'fill', 'wrap'"
+                    " (or 'circular'), \n  and 'symm' (or 'symmetric').")
         val = boundary << 2
     return val
 
@@ -297,8 +297,8 @@
     size = domain.shape
     for k in range(len(size)):
         if (size[k] % 2) != 1:
-            raise ValueError, "Each dimension of domain argument " \
-                  "should have an odd number of elements."
+            raise ValueError("Each dimension of domain argument "
+                    " should have an odd number of elements.")
     return sigtools._order_filterND(a, domain, rank)
 
 
@@ -336,7 +336,7 @@
 
     for k in range(len(volume.shape)):
         if (kernel_size[k] % 2) != 1:
-            raise ValueError, "Each element of kernel_size should be odd."
+            raise ValueError("Each element of kernel_size should be odd.")
 
     domain = ones(kernel_size)
 
@@ -536,7 +536,7 @@
 
     for size in kernel_size:
         if (size % 2) != 1:
-            raise ValueError, "Each element of kernel_size should be odd."
+            raise ValueError("Each element of kernel_size should be odd.")
 
     return sigtools._medfilt2d(image, kernel_size)
 
@@ -724,7 +724,7 @@
     if N is None:
         N = x.shape[axis]
     if N <=0:
-        raise ValueError, "N must be positive."
+        raise ValueError("N must be positive.")
     if iscomplexobj(x):
         print "Warning: imaginary part of x ignored."
         x = real(x)
@@ -773,7 +773,7 @@
         N = x.shape
     if len(N) < 2:
         if N <=0:
-            raise ValueError, "N must be positive."
+            raise ValueError("N must be positive.")
         N = (N,N)
     if iscomplexobj(x):
         print "Warning: imaginary part of x ignored."
@@ -1257,7 +1257,7 @@
 
     """
     if type not in ['linear','l','constant','c']:
-        raise ValueError, "Trend type must be linear or constant"
+        raise ValueError("Trend type must be 'linear' or 'constant'.")
     data = asarray(data)
     dtype = data.dtype.char
     if dtype not in 'dfDF':
@@ -1270,8 +1270,8 @@
         N = dshape[axis]
         bp = sort(unique(r_[0,bp,N]))
         if any(bp > N):
-            raise ValueError, "Breakpoints must be less than length " \
-                  "of data along given axis."
+            raise ValueError("Breakpoints must be less than length "
+                    "of data along given axis.")
         Nreg = len(bp) - 1
         # Restructure data so that axis is along first dimension and
         #  all other dimensions are collapsed into second dimension
@@ -1331,12 +1331,12 @@
     edge=ntaps*3
 
     if x.ndim != 1:
-        raise ValueError, "filtfilt only accepts 1-d arrays."
+        raise ValueError("filtfilt only accepts 1-d arrays.")
 
     #x must be bigger than edge
     if x.size < edge:
-        raise ValueError, "Input vector needs to be bigger than " \
-              "3 * max(len(a),len(b)."
+        raise ValueError("Input vector needs to be bigger than "
+              "3 * max(len(a),len(b).")
 
     if len(a) < ntaps:
         a=r_[a,zeros(len(b)-len(a))]
@@ -1392,7 +1392,7 @@
     """
 
     if not isinstance(q, int):
-        raise TypeError, "q must be an integer"
+        raise TypeError("q must be an integer")
 
     if n is None:
         if ftype == 'fir':




More information about the Scipy-svn mailing list