[Scipy-svn] r4705 - in trunk/scipy/stsci: convolve/lib image/lib
scipy-svn@scip...
scipy-svn@scip...
Tue Sep 9 08:47:36 CDT 2008
Author: alan.mcintyre
Date: 2008-09-09 08:46:55 -0500 (Tue, 09 Sep 2008)
New Revision: 4705
Modified:
trunk/scipy/stsci/convolve/lib/Convolve.py
trunk/scipy/stsci/convolve/lib/iraf_frame.py
trunk/scipy/stsci/convolve/lib/lineshape.py
trunk/scipy/stsci/image/lib/_image.py
trunk/scipy/stsci/image/lib/combine.py
Log:
Standardize NumPy import as "import numpy as np".
Removed unused numpy import.
Clean up alignment of multiline statements.
Modified: trunk/scipy/stsci/convolve/lib/Convolve.py
===================================================================
--- trunk/scipy/stsci/convolve/lib/Convolve.py 2008-09-08 18:57:39 UTC (rev 4704)
+++ trunk/scipy/stsci/convolve/lib/Convolve.py 2008-09-09 13:46:55 UTC (rev 4705)
@@ -1,4 +1,4 @@
-import numpy as num
+import numpy as np
import _correlate
import numpy.fft as dft
import iraf_frame
@@ -16,12 +16,12 @@
}
def _condition_inputs(data, kernel):
- data, kernel = num.asarray(data), num.asarray(kernel)
- if num.rank(data) == 0:
+ data, kernel = np.asarray(data), np.asarray(kernel)
+ if np.rank(data) == 0:
data.shape = (1,)
- if num.rank(kernel) == 0:
+ if np.rank(kernel) == 0:
kernel.shape = (1,)
- if num.rank(data) > 1 or num.rank(kernel) > 1:
+ if np.rank(data) > 1 or np.rank(kernel) > 1:
raise ValueError("arrays must be 1D")
if len(data) < len(kernel):
data, kernel = kernel, data
@@ -30,25 +30,25 @@
def correlate(data, kernel, mode=FULL):
"""correlate(data, kernel, mode=FULL)
- >>> correlate(num.arange(8), [1, 2], mode=VALID)
+ >>> correlate(np.arange(8), [1, 2], mode=VALID)
array([ 2, 5, 8, 11, 14, 17, 20])
- >>> correlate(num.arange(8), [1, 2], mode=SAME)
+ >>> correlate(np.arange(8), [1, 2], mode=SAME)
array([ 0, 2, 5, 8, 11, 14, 17, 20])
- >>> correlate(num.arange(8), [1, 2], mode=FULL)
+ >>> correlate(np.arange(8), [1, 2], mode=FULL)
array([ 0, 2, 5, 8, 11, 14, 17, 20, 7])
- >>> correlate(num.arange(8), [1, 2, 3], mode=VALID)
+ >>> correlate(np.arange(8), [1, 2, 3], mode=VALID)
array([ 8, 14, 20, 26, 32, 38])
- >>> correlate(num.arange(8), [1, 2, 3], mode=SAME)
+ >>> correlate(np.arange(8), [1, 2, 3], mode=SAME)
array([ 3, 8, 14, 20, 26, 32, 38, 20])
- >>> correlate(num.arange(8), [1, 2, 3], mode=FULL)
+ >>> correlate(np.arange(8), [1, 2, 3], mode=FULL)
array([ 0, 3, 8, 14, 20, 26, 32, 38, 20, 7])
- >>> correlate(num.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
+ >>> correlate(np.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
array([ 70, 91, 112])
- >>> correlate(num.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
+ >>> correlate(np.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
array([ 17, 32, 50, 70, 91, 112, 85, 60])
- >>> correlate(num.arange(8), [1, 2, 3, 4, 5, 6], mode=FULL)
+ >>> correlate(np.arange(8), [1, 2, 3, 4, 5, 6], mode=FULL)
array([ 0, 6, 17, 32, 50, 70, 91, 112, 85, 60, 38, 20, 7])
- >>> correlate(num.arange(8), 1+1j)
+ >>> correlate(np.arange(8), 1+1j)
Traceback (most recent call last):
...
TypeError: array cannot be safely cast to required type
@@ -66,17 +66,17 @@
result_type = max(kernel.dtype.name, data.dtype.name)
if mode == VALID:
- wdata = num.concatenate((kdata, data, kdata))
+ wdata = np.concatenate((kdata, data, kdata))
result = wdata.astype(result_type)
_correlate.Correlate1d(kernel, wdata, result)
return result[lenk+halfk:-lenk-halfk+even]
elif mode == SAME:
- wdata = num.concatenate((kdata, data, kdata))
+ wdata = np.concatenate((kdata, data, kdata))
result = wdata.astype(result_type)
_correlate.Correlate1d(kernel, wdata, result)
return result[lenk:-lenk]
elif mode == FULL:
- wdata = num.concatenate((kdata, data, kdata))
+ wdata = np.concatenate((kdata, data, kdata))
result = wdata.astype(result_type)
_correlate.Correlate1d(kernel, wdata, result)
return result[halfk+1:-halfk-1+even]
@@ -102,25 +102,25 @@
sequences a and v; mode can be 0 (VALID), 1 (SAME), or 2 (FULL)
to specify size of the resulting sequence.
- >>> convolve(num.arange(8), [1, 2], mode=VALID)
+ >>> convolve(np.arange(8), [1, 2], mode=VALID)
array([ 1, 4, 7, 10, 13, 16, 19])
- >>> convolve(num.arange(8), [1, 2], mode=SAME)
+ >>> convolve(np.arange(8), [1, 2], mode=SAME)
array([ 0, 1, 4, 7, 10, 13, 16, 19])
- >>> convolve(num.arange(8), [1, 2], mode=FULL)
+ >>> convolve(np.arange(8), [1, 2], mode=FULL)
array([ 0, 1, 4, 7, 10, 13, 16, 19, 14])
- >>> convolve(num.arange(8), [1, 2, 3], mode=VALID)
+ >>> convolve(np.arange(8), [1, 2, 3], mode=VALID)
array([ 4, 10, 16, 22, 28, 34])
- >>> convolve(num.arange(8), [1, 2, 3], mode=SAME)
+ >>> convolve(np.arange(8), [1, 2, 3], mode=SAME)
array([ 1, 4, 10, 16, 22, 28, 34, 32])
- >>> convolve(num.arange(8), [1, 2, 3], mode=FULL)
+ >>> convolve(np.arange(8), [1, 2, 3], mode=FULL)
array([ 0, 1, 4, 10, 16, 22, 28, 34, 32, 21])
- >>> convolve(num.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
+ >>> convolve(np.arange(8), [1, 2, 3, 4, 5, 6], mode=VALID)
array([35, 56, 77])
- >>> convolve(num.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
+ >>> convolve(np.arange(8), [1, 2, 3, 4, 5, 6], mode=SAME)
array([ 4, 10, 20, 35, 56, 77, 90, 94])
- >>> convolve(num.arange(8), [1, 2, 3, 4, 5, 6], mode=FULL)
+ >>> convolve(np.arange(8), [1, 2, 3, 4, 5, 6], mode=FULL)
array([ 0, 1, 4, 10, 20, 35, 56, 77, 90, 94, 88, 71, 42])
- >>> convolve([1.,2.], num.arange(10.))
+ >>> convolve([1.,2.], np.arange(10.))
array([ 0., 1., 4., 7., 10., 13., 16., 19., 22., 25., 18.])
"""
data, kernel = _condition_inputs(data, kernel)
@@ -131,15 +131,15 @@
def _gaussian(sigma, mew, npoints, sigmas):
- ox = num.arange(mew-sigmas*sigma,
- mew+sigmas*sigma,
- 2*sigmas*sigma/npoints, type=num.float64)
+ ox = np.arange(mew-sigmas*sigma,
+ mew+sigmas*sigma,
+ 2*sigmas*sigma/npoints, type=np.float64)
x = ox-mew
x /= sigma
x = x * x
x *= -1/2
- x = num.exp(x)
- return ox, 1/(sigma * num.sqrt(2*num.pi)) * x
+ x = np.exp(x)
+ return ox, 1/(sigma * np.sqrt(2*np.pi)) * x
def _correlate2d_fft(data0, kernel0, output=None, mode="nearest", cval=0.0):
"""_correlate2d_fft does 2d correlation of 'data' with 'kernel', storing
@@ -153,17 +153,17 @@
"""
shape = data0.shape
kshape = kernel0.shape
- oversized = (num.array(shape) + num.array(kshape))
+ oversized = (np.array(shape) + np.array(kshape))
dy = kshape[0] // 2
dx = kshape[1] // 2
- kernel = num.zeros(oversized, dtype=num.float64)
+ kernel = np.zeros(oversized, dtype=np.float64)
kernel[:kshape[0], :kshape[1]] = kernel0[::-1,::-1] # convolution <-> correlation
data = iraf_frame.frame(data0, oversized, mode=mode, cval=cval)
- complex_result = (isinstance(data, num.complexfloating) or
- isinstance(kernel, num.complexfloating))
+ complex_result = (isinstance(data, np.complexfloating) or
+ isinstance(kernel, np.complexfloating))
Fdata = dft.fft2(data)
del data
@@ -171,7 +171,7 @@
Fkernel = dft.fft2(kernel)
del kernel
- num.multiply(Fdata, Fkernel, Fdata)
+ np.multiply(Fdata, Fkernel, Fdata)
del Fkernel
if complex_result:
@@ -196,14 +196,14 @@
commutative, _fix_data_kernel reverses kernel and data if necessary
and panics if there's no good order.
"""
- data, kernel = map(num.asarray, [data, kernel])
- if num.rank(data) == 0:
+ data, kernel = map(np.asarray, [data, kernel])
+ if np.rank(data) == 0:
data.shape = (1,1)
- elif num.rank(data) == 1:
+ elif np.rank(data) == 1:
data.shape = (1,) + data.shape
- if num.rank(kernel) == 0:
+ if np.rank(kernel) == 0:
kernel.shape = (1,1)
- elif num.rank(kernel) == 1:
+ elif np.rank(kernel) == 1:
kernel.shape = (1,) + kernel.shape
if (kernel.shape[0] > data.shape[0] and
kernel.shape[1] > data.shape[1]):
@@ -226,12 +226,12 @@
If fft is True, the correlation is performed using the FFT, else the
correlation is performed using the naive approach.
- >>> a = num.arange(20*20)
+ >>> a = np.arange(20*20)
>>> a = a.reshape((20,20))
- >>> b = num.ones((5,5), dtype=num.float64)
+ >>> b = np.ones((5,5), dtype=np.float64)
>>> rn = correlate2d(a, b, fft=0)
>>> rf = correlate2d(a, b, fft=1)
- >>> num.alltrue(num.ravel(rn-rf<1e-10))
+ >>> np.alltrue(np.ravel(rn-rf<1e-10))
True
"""
data, kernel = _fix_data_kernel(data, kernel)
@@ -252,12 +252,12 @@
'reflect' elements beyond boundary come from reflection on same array edge.
'constant' elements beyond boundary are set to 'cval'
- >>> a = num.arange(20*20)
+ >>> a = np.arange(20*20)
>>> a = a.reshape((20,20))
- >>> b = num.ones((5,5), dtype=num.float64)
+ >>> b = np.ones((5,5), dtype=np.float64)
>>> rn = convolve2d(a, b, fft=0)
>>> rf = convolve2d(a, b, fft=1)
- >>> num.alltrue(num.ravel(rn-rf<1e-10))
+ >>> np.alltrue(np.ravel(rn-rf<1e-10))
True
"""
data, kernel = _fix_data_kernel(data, kernel)
@@ -269,8 +269,8 @@
def _boxcar(data, output, boxshape, mode, cval):
if len(boxshape) == 1:
- _correlate.Boxcar2d(data[num.newaxis,...], 1, boxshape[0],
- output[num.newaxis,...], mode, cval)
+ _correlate.Boxcar2d(data[np.newaxis,...], 1, boxshape[0],
+ output[np.newaxis,...], mode, cval)
elif len(boxshape) == 2:
_correlate.Boxcar2d(data, boxshape[0], boxshape[1], output, mode, cval)
else:
@@ -290,19 +290,19 @@
'reflect' elements beyond boundary come from reflection on same array edge.
'constant' elements beyond boundary are set to 'cval'
- >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="nearest").astype(num.longlong)
+ >>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="nearest").astype(np.longlong)
array([ 6, 3, 0, 0, 0, 333, 666], dtype=int64)
- >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="wrap").astype(num.longlong)
+ >>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="wrap").astype(np.longlong)
array([336, 3, 0, 0, 0, 333, 336], dtype=int64)
- >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="reflect").astype(num.longlong)
+ >>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="reflect").astype(np.longlong)
array([ 6, 3, 0, 0, 0, 333, 666], dtype=int64)
- >>> boxcar(num.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="constant").astype(num.longlong)
+ >>> boxcar(np.array([10, 0, 0, 0, 0, 0, 1000]), (3,), mode="constant").astype(np.longlong)
array([ 3, 3, 0, 0, 0, 333, 333], dtype=int64)
- >>> a = num.zeros((10,10))
+ >>> a = np.zeros((10,10))
>>> a[0,0] = 100
>>> a[5,5] = 1000
>>> a[9,9] = 10000
- >>> boxcar(a, (3,3)).astype(num.longlong)
+ >>> boxcar(a, (3,3)).astype(np.longlong)
array([[ 44, 22, 0, 0, 0, 0, 0, 0, 0, 0],
[ 22, 11, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -313,7 +313,7 @@
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 1111, 2222],
[ 0, 0, 0, 0, 0, 0, 0, 0, 2222, 4444]], dtype=int64)
- >>> boxcar(a, (3,3), mode="wrap").astype(num.longlong)
+ >>> boxcar(a, (3,3), mode="wrap").astype(np.longlong)
array([[1122, 11, 0, 0, 0, 0, 0, 0, 1111, 1122],
[ 11, 11, 0, 0, 0, 0, 0, 0, 0, 11],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -324,7 +324,7 @@
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1111, 0, 0, 0, 0, 0, 0, 0, 1111, 1111],
[1122, 11, 0, 0, 0, 0, 0, 0, 1111, 1122]], dtype=int64)
- >>> boxcar(a, (3,3), mode="reflect").astype(num.longlong)
+ >>> boxcar(a, (3,3), mode="reflect").astype(np.longlong)
array([[ 44, 22, 0, 0, 0, 0, 0, 0, 0, 0],
[ 22, 11, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -335,7 +335,7 @@
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 1111, 2222],
[ 0, 0, 0, 0, 0, 0, 0, 0, 2222, 4444]], dtype=int64)
- >>> boxcar(a, (3,3), mode="constant").astype(num.longlong)
+ >>> boxcar(a, (3,3), mode="constant").astype(np.longlong)
array([[ 11, 11, 0, 0, 0, 0, 0, 0, 0, 0],
[ 11, 11, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -347,9 +347,9 @@
[ 0, 0, 0, 0, 0, 0, 0, 0, 1111, 1111],
[ 0, 0, 0, 0, 0, 0, 0, 0, 1111, 1111]], dtype=int64)
- >>> a = num.zeros((10,10))
+ >>> a = np.zeros((10,10))
>>> a[3:6,3:6] = 111
- >>> boxcar(a, (3,3)).astype(num.longlong)
+ >>> boxcar(a, (3,3)).astype(np.longlong)
array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 12, 24, 37, 24, 12, 0, 0, 0],
@@ -363,11 +363,11 @@
"""
mode = pix_modes[ mode ]
if output is None:
- woutput = data.astype(num.float64)
+ woutput = data.astype(np.float64)
else:
woutput = output
_fbroadcast(_boxcar, len(boxshape), data.shape,
- (data, woutput), (boxshape, mode, cval))
+ (data, woutput), (boxshape, mode, cval))
if output is None:
return woutput
Modified: trunk/scipy/stsci/convolve/lib/iraf_frame.py
===================================================================
--- trunk/scipy/stsci/convolve/lib/iraf_frame.py 2008-09-08 18:57:39 UTC (rev 4704)
+++ trunk/scipy/stsci/convolve/lib/iraf_frame.py 2008-09-09 13:46:55 UTC (rev 4705)
@@ -1,4 +1,4 @@
-import numpy as num
+import numpy as np
"""This module defines the function frame() which creates
a framed copy of an input array with the boundary pixels
@@ -12,7 +12,7 @@
and the contents of 'a' in the center. The boundary pixels are
copied from the nearest edge pixel in 'a'.
- >>> a = num.arange(16)
+ >>> a = np.arange(16)
>>> a.shape=(4,4)
>>> frame_nearest(a, (8,8))
array([[ 0, 0, 0, 1, 2, 3, 3, 3],
@@ -26,8 +26,8 @@
"""
- b = num.zeros(shape, dtype=a.dtype)
- delta = (num.array(b.shape) - num.array(a.shape))
+ b = np.zeros(shape, dtype=a.dtype)
+ delta = (np.array(b.shape) - np.array(a.shape))
dy = delta[0] // 2
dx = delta[1] // 2
my = a.shape[0] + dy
@@ -51,7 +51,7 @@
and the contents of 'a' in the center. The boundary pixels are
reflected from the nearest edge pixels in 'a'.
- >>> a = num.arange(16)
+ >>> a = np.arange(16)
>>> a.shape = (4,4)
>>> frame_reflect(a, (8,8))
array([[ 5, 4, 4, 5, 6, 7, 7, 6],
@@ -64,8 +64,8 @@
[ 9, 8, 8, 9, 10, 11, 11, 10]])
"""
- b = num.zeros(shape, dtype=a.dtype)
- delta = (num.array(b.shape) - num.array(a.shape))
+ b = np.zeros(shape, dtype=a.dtype)
+ delta = (np.array(b.shape) - np.array(a.shape))
dy = delta[0] // 2
dx = delta[1] // 2
my = a.shape[0] + dy
@@ -89,7 +89,7 @@
and the contents of 'a' in the center. The boundary pixels are
wrapped around to the opposite edge pixels in 'a'.
- >>> a = num.arange(16)
+ >>> a = np.arange(16)
>>> a.shape=(4,4)
>>> frame_wrap(a, (8,8))
array([[10, 11, 8, 9, 10, 11, 8, 9],
@@ -103,8 +103,8 @@
"""
- b = num.zeros(shape, dtype=a.dtype)
- delta = (num.array(b.shape) - num.array(a.shape))
+ b = np.zeros(shape, dtype=a.dtype)
+ delta = (np.array(b.shape) - np.array(a.shape))
dy = delta[0] // 2
dx = delta[1] // 2
my = a.shape[0] + dy
@@ -128,7 +128,7 @@
and the contents of 'a' in the center. The boundary pixels are
copied from the nearest edge pixel in 'a'.
- >>> a = num.arange(16)
+ >>> a = np.arange(16)
>>> a.shape=(4,4)
>>> frame_constant(a, (8,8), cval=42)
array([[42, 42, 42, 42, 42, 42, 42, 42],
@@ -142,8 +142,8 @@
"""
- b = num.zeros(shape, dtype=a.dtype)
- delta = (num.array(b.shape) - num.array(a.shape))
+ b = np.zeros(shape, dtype=a.dtype)
+ delta = (np.array(b.shape) - np.array(a.shape))
dy = delta[0] // 2
dx = delta[1] // 2
my = a.shape[0] + dy
@@ -183,7 +183,7 @@
"""unframe extracts the center slice of framed array 'a' which had
'shape' prior to framing."""
- delta = num.array(a.shape) - num.array(shape)
+ delta = np.array(a.shape) - np.array(shape)
dy = delta[0]//2
dx = delta[1]//2
my = shape[0] + dy
Modified: trunk/scipy/stsci/convolve/lib/lineshape.py
===================================================================
--- trunk/scipy/stsci/convolve/lib/lineshape.py 2008-09-08 18:57:39 UTC (rev 4704)
+++ trunk/scipy/stsci/convolve/lib/lineshape.py 2008-09-09 13:46:55 UTC (rev 4705)
@@ -40,11 +40,8 @@
__date__ = "$Date: 2007/03/14 16:35:57 $"[7:-11]
__version__ = "$Revision: 1.1 $"[11:-2]
-
-import numpy as num
from convolve._lineshape import *
-
class Profile(object):
"""An base object to provide a convolution kernel."""
Modified: trunk/scipy/stsci/image/lib/_image.py
===================================================================
--- trunk/scipy/stsci/image/lib/_image.py 2008-09-08 18:57:39 UTC (rev 4704)
+++ trunk/scipy/stsci/image/lib/_image.py 2008-09-09 13:46:55 UTC (rev 4705)
@@ -1,7 +1,6 @@
-import numpy as num
+import numpy as np
import scipy.stsci.convolve
import scipy.stsci.convolve._correlate as _correlate
-MLab=num
def _translate(a, dx, dy, output=None, mode="nearest", cval=0.0):
"""_translate does positive sub-pixel shifts using bilinear interpolation."""
@@ -14,10 +13,8 @@
y = (1-dx) * dy
z = dx * dy
- kernel = num.array([
- [ z, y ],
- [ x, w ],
- ])
+ kernel = np.array([[ z, y ],
+ [ x, w ]])
return convolve.correlate2d(a, kernel, output, mode, cval)
@@ -33,7 +30,7 @@
'reflect' elements beyond boundary come from reflection on same array edge.
'constant' elements beyond boundary are set to 'cval'
"""
- a = num.asarray(a)
+ a = np.asarray(a)
sdx, sdy = -sdx, -sdy # Flip sign to match IRAF sign convention
@@ -51,11 +48,11 @@
rotation = 0
dx, dy = abs(sdx), abs(sdy)
- b = MLab.rot90(a, rotation)
+ b = np.rot90(a, rotation)
c = _correlate.Shift2d(b, int(dx), int(dy),
mode=convolve.pix_modes[mode])
d = _translate(c, dx % 1, dy % 1, output, mode, cval)
if output is not None:
- output._copyFrom(MLab.rot90(output, -rotation%4))
+ output._copyFrom(np.rot90(output, -rotation%4))
else:
- return MLab.rot90(d, -rotation % 4).astype(a.type())
+ return np.rot90(d, -rotation % 4).astype(a.type())
Modified: trunk/scipy/stsci/image/lib/combine.py
===================================================================
--- trunk/scipy/stsci/image/lib/combine.py 2008-09-08 18:57:39 UTC (rev 4704)
+++ trunk/scipy/stsci/image/lib/combine.py 2008-09-09 13:46:55 UTC (rev 4705)
@@ -1,10 +1,10 @@
-import numpy as num
+import numpy as np
from _combine import combine as _comb
import operator as _operator
def _combine_f(funcstr, arrays, output=None, outtype=None, nlow=0, nhigh=0, badmasks=None):
- arrays = [ num.asarray(a) for a in arrays ]
+ arrays = [ np.asarray(a) for a in arrays ]
shape = arrays[0].shape
if output is None:
if outtype is not None:
@@ -44,7 +44,7 @@
indicates that a particular pixel is not to be included in the
median calculation.
- >>> a = num.arange(4)
+ >>> a = np.arange(4)
>>> a = a.reshape((2,2))
>>> arrays = [a*16, a*4, a*2, a*8]
>>> median(arrays)
@@ -56,10 +56,10 @@
>>> median(arrays, nlow=1)
array([[ 0, 8],
[16, 24]])
- >>> median(arrays, outtype=num.float32)
+ >>> median(arrays, outtype=np.float32)
array([[ 0., 6.],
[ 12., 18.]], dtype=float32)
- >>> bm = num.zeros((4,2,2), dtype=num.bool8)
+ >>> bm = np.zeros((4,2,2), dtype=np.bool8)
>>> bm[2,...] = 1
>>> median(arrays, badmasks=bm)
array([[ 0, 8],
@@ -94,7 +94,7 @@
indicates that a particular pixel is not to be included in the
average calculation.
- >>> a = num.arange(4)
+ >>> a = np.arange(4)
>>> a = a.reshape((2,2))
>>> arrays = [a*16, a*4, a*2, a*8]
>>> average(arrays)
@@ -106,10 +106,10 @@
>>> average(arrays, nlow=1)
array([[ 0, 9],
[18, 28]])
- >>> average(arrays, outtype=num.float32)
+ >>> average(arrays, outtype=np.float32)
array([[ 0. , 7.5],
[ 15. , 22.5]], dtype=float32)
- >>> bm = num.zeros((4,2,2), dtype=num.bool8)
+ >>> bm = np.zeros((4,2,2), dtype=np.bool8)
>>> bm[2,...] = 1
>>> average(arrays, badmasks=bm)
array([[ 0, 9],
@@ -145,7 +145,7 @@
indicates that a particular pixel is not to be included in the
minimum calculation.
- >>> a = num.arange(4)
+ >>> a = np.arange(4)
>>> a = a.reshape((2,2))
>>> arrays = [a*16, a*4, a*2, a*8]
>>> minimum(arrays)
@@ -157,10 +157,10 @@
>>> minimum(arrays, nlow=1)
array([[ 0, 4],
[ 8, 12]])
- >>> minimum(arrays, outtype=num.float32)
+ >>> minimum(arrays, outtype=np.float32)
array([[ 0., 2.],
[ 4., 6.]], dtype=float32)
- >>> bm = num.zeros((4,2,2), dtype=num.bool8)
+ >>> bm = np.zeros((4,2,2), dtype=np.bool8)
>>> bm[2,...] = 1
>>> minimum(arrays, badmasks=bm)
array([[ 0, 4],
@@ -178,9 +178,9 @@
boolean value is true where each of the arrays values
is < the low or >= the high threshholds.
- >>> a=num.arange(100)
+ >>> a=np.arange(100)
>>> a=a.reshape((10,10))
- >>> (threshhold(a, 1, 50)).astype(num.int8)
+ >>> (threshhold(a, 1, 50)).astype(np.int8)
array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -191,7 +191,7 @@
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=int8)
- >>> (threshhold([ range(10)]*10, 3, 7)).astype(num.int8)
+ >>> (threshhold([ range(10)]*10, 3, 7)).astype(np.int8)
array([[1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
@@ -202,7 +202,7 @@
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 1, 1, 1]], dtype=int8)
- >>> (threshhold(a, high=50)).astype(num.int8)
+ >>> (threshhold(a, high=50)).astype(np.int8)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -213,7 +213,7 @@
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=int8)
- >>> (threshhold(a, low=50)).astype(num.int8)
+ >>> (threshhold(a, low=50)).astype(np.int8)
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
@@ -227,12 +227,12 @@
"""
- if not isinstance(arrays[0], num.ndarray):
- return threshhold( num.asarray(arrays), low, high, outputs)
+ if not isinstance(arrays[0], np.ndarray):
+ return threshhold( np.asarray(arrays), low, high, outputs)
if outputs is None:
- outs = num.zeros(shape=(len(arrays),)+arrays[0].shape,
- dtype=num.bool8)
+ outs = np.zeros(shape=(len(arrays),)+arrays[0].shape,
+ dtype=np.bool8)
else:
outs = outputs
@@ -241,12 +241,12 @@
out[:] = 0
if high is not None:
- num.greater_equal(a, high, out)
+ np.greater_equal(a, high, out)
if low is not None:
- num.logical_or(out, a < low, out)
+ np.logical_or(out, a < low, out)
else:
if low is not None:
- num.less(a, low, out)
+ np.less(a, low, out)
if outputs is None:
return outs
@@ -254,16 +254,16 @@
def _bench():
"""time a 10**6 element median"""
import time
- a = num.arange(10**6)
+ a = np.arange(10**6)
a = a.reshape((1000, 1000))
arrays = [a*2, a*64, a*16, a*8]
t0 = time.clock()
median(arrays)
print "maskless:", time.clock()-t0
- a = num.arange(10**6)
+ a = np.arange(10**6)
a = a.reshape((1000, 1000))
arrays = [a*2, a*64, a*16, a*8]
t0 = time.clock()
- median(arrays, badmasks=num.zeros((1000,1000), dtype=num.bool8))
+ median(arrays, badmasks=np.zeros((1000,1000), dtype=np.bool8))
print "masked:", time.clock()-t0
More information about the Scipy-svn
mailing list