Permalink
Browse files

BUG: fix issue with ndimage.zoom. Closes ticket 1122.

Reviewed at #204.
  • Loading branch information...
1 parent 3931577 commit 07f84e32bf2e1f7d3a58a92d13243635ebd5cc37 @jjhelmus jjhelmus committed with rgommers May 7, 2012
Showing with 28 additions and 2 deletions.
  1. +2 −2 scipy/ndimage/interpolation.py
  2. +26 −0 scipy/ndimage/tests/test_ndimage.py
@@ -519,9 +519,9 @@ def zoom(input, zoom, output=None, order=3, mode='constant', cval=0.0,
zoom_div = numpy.array(output_shape, float) - 1
zoom = (numpy.array(input.shape) - 1) / zoom_div
- # Zooming to infinity is unpredictable, so just choose
+ # Zooming to non-finite values in unpredictable, so just choose
# zoom factor 1 instead
- zoom[numpy.isinf(zoom)] = 1
+ zoom[~numpy.isfinite(zoom)] = 1
output, return_value = _ni_support._get_output(output, input,
shape=output_shape)
@@ -2122,6 +2122,19 @@ def test_zoom2(self):
out = ndimage.zoom(ndimage.zoom(arr,2),0.5)
assert_array_equal(out,arr)
+ def test_zoom3(self):
+ "zoom 3"
+ err = numpy.seterr(invalid='ignore')
+ arr = numpy.array([[1, 2]])
+ try:
+ out1 = ndimage.zoom(arr, (2, 1))
+ out2 = ndimage.zoom(arr, (1,2))
+ finally:
+ numpy.seterr(**err)
+
+ assert_array_almost_equal(out1, numpy.array([[1, 2], [1, 2]]))
+ assert_array_almost_equal(out2, numpy.array([[1, 1, 2, 2]]))
+
def test_zoom_affine01(self):
"zoom by affine transformation 1"
data = [[1, 2, 3, 4],
@@ -2142,6 +2155,19 @@ def test_zoom_infinity(self):
finally:
numpy.seterr(**err)
+ def test_zoom_zoomfactor_one(self):
+ """Ticket #1122"""
+ arr = numpy.zeros((1, 5, 5))
+ zoom = (1.0, 2.0, 2.0)
+
+ err = numpy.seterr(invalid='ignore')
+ try:
+ out = ndimage.zoom(arr, zoom, cval=7)
+ finally:
+ numpy.seterr(**err)
+ ref = numpy.zeros((1, 10, 10))
+ assert_array_almost_equal(out, ref)
+
def test_rotate01(self):
"rotate 1"
data = numpy.array([[0, 0, 0, 0],

0 comments on commit 07f84e3

Please sign in to comment.