Skip to content
This repository
Browse code

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

Reviewed at #204.
  • Loading branch information...
commit 07f84e32bf2e1f7d3a58a92d13243635ebd5cc37 1 parent 3931577
Jonathan J. Helmus authored May 07, 2012 rgommers committed June 09, 2012
4  scipy/ndimage/interpolation.py
@@ -519,9 +519,9 @@ def zoom(input, zoom, output=None, order=3, mode='constant', cval=0.0,
519 519
     zoom_div = numpy.array(output_shape, float) - 1
520 520
     zoom = (numpy.array(input.shape) - 1) / zoom_div
521 521
 
522  
-    # Zooming to infinity is unpredictable, so just choose
  522
+    # Zooming to non-finite values in unpredictable, so just choose
523 523
     # zoom factor 1 instead
524  
-    zoom[numpy.isinf(zoom)] = 1
  524
+    zoom[~numpy.isfinite(zoom)] = 1
525 525
 
526 526
     output, return_value = _ni_support._get_output(output, input,
527 527
                                                    shape=output_shape)
26  scipy/ndimage/tests/test_ndimage.py
@@ -2122,6 +2122,19 @@ def test_zoom2(self):
2122 2122
         out = ndimage.zoom(ndimage.zoom(arr,2),0.5)
2123 2123
         assert_array_equal(out,arr)
2124 2124
 
  2125
+    def test_zoom3(self):
  2126
+        "zoom 3"
  2127
+        err = numpy.seterr(invalid='ignore')
  2128
+        arr = numpy.array([[1, 2]])
  2129
+        try:
  2130
+            out1 = ndimage.zoom(arr, (2, 1))
  2131
+            out2 = ndimage.zoom(arr, (1,2))
  2132
+        finally:
  2133
+            numpy.seterr(**err)
  2134
+
  2135
+        assert_array_almost_equal(out1, numpy.array([[1, 2], [1, 2]]))
  2136
+        assert_array_almost_equal(out2, numpy.array([[1, 1, 2, 2]]))
  2137
+
2125 2138
     def test_zoom_affine01(self):
2126 2139
         "zoom by affine transformation 1"
2127 2140
         data = [[1, 2, 3, 4],
@@ -2142,6 +2155,19 @@ def test_zoom_infinity(self):
2142 2155
         finally:
2143 2156
             numpy.seterr(**err)
2144 2157
 
  2158
+    def test_zoom_zoomfactor_one(self):
  2159
+        """Ticket #1122"""
  2160
+        arr = numpy.zeros((1, 5, 5))
  2161
+        zoom = (1.0, 2.0, 2.0)
  2162
+
  2163
+        err = numpy.seterr(invalid='ignore')
  2164
+        try:
  2165
+            out = ndimage.zoom(arr, zoom, cval=7)
  2166
+        finally:
  2167
+            numpy.seterr(**err)
  2168
+        ref = numpy.zeros((1, 10, 10))
  2169
+        assert_array_almost_equal(out, ref)
  2170
+
2145 2171
     def test_rotate01(self):
2146 2172
         "rotate 1"
2147 2173
         data = numpy.array([[0, 0, 0, 0],

0 notes on commit 07f84e3

Please sign in to comment.
Something went wrong with that request. Please try again.