[Scipy-svn] r6904 - in trunk/scipy/interpolate: . tests

scipy-svn@scip... scipy-svn@scip...
Wed Nov 17 14:48:53 CST 2010


Author: ptvirtan
Date: 2010-11-17 14:48:53 -0600 (Wed, 17 Nov 2010)
New Revision: 6904

Modified:
   trunk/scipy/interpolate/ndgriddata.py
   trunk/scipy/interpolate/tests/test_ndgriddata.py
Log:
BUG: interpolate: make griddata work for 1-D data, and add tests for this case

Modified: trunk/scipy/interpolate/ndgriddata.py
===================================================================
--- trunk/scipy/interpolate/ndgriddata.py	2010-11-17 14:35:25 UTC (rev 6903)
+++ trunk/scipy/interpolate/ndgriddata.py	2010-11-17 20:48:53 UTC (rev 6904)
@@ -155,11 +155,18 @@
     """
 
     points = _ndim_coords_from_arrays(points)
-    xi = _ndim_coords_from_arrays(xi)
 
-    ndim = points.shape[-1]
+    if points.ndim < 2:
+        ndim = points.ndim
+    else:
+        ndim = points.shape[-1]
 
     if ndim == 1 and method in ('nearest', 'linear', 'cubic'):
+        from interpolate import interp1d
+        points = points.ravel()
+        if (isinstance(xi, tuple) or isinstance(xi, list)) \
+               and xi and isinstance(xi[0], np.ndarray):
+            xi, = xi
         ip = interp1d(points, values, kind=method, axis=0, bounds_error=False,
                       fill_value=fill_value)
         return ip(xi)

Modified: trunk/scipy/interpolate/tests/test_ndgriddata.py
===================================================================
--- trunk/scipy/interpolate/tests/test_ndgriddata.py	2010-11-17 14:35:25 UTC (rev 6903)
+++ trunk/scipy/interpolate/tests/test_ndgriddata.py	2010-11-17 20:48:53 UTC (rev 6904)
@@ -65,5 +65,17 @@
             assert_allclose(yi, np.tile(y[:,None], (1, 3)),
                             atol=1e-14, err_msg=method)
 
+    def test_1d(self):
+        x = np.array([1, 2.5, 3, 4.5, 5, 6])
+        y = np.array([1,   2, 0, 3.9, 2, 1])
+
+        for method in ('nearest', 'linear', 'cubic'):
+            assert_allclose(griddata(x, y, x, method=method), y,
+                            err_msg=method, atol=1e-14)
+            assert_allclose(griddata(x.reshape(6, 1), y, x, method=method), y,
+                            err_msg=method, atol=1e-14)
+            assert_allclose(griddata((x,), y, (x,), method=method), y,
+                            err_msg=method, atol=1e-14)
+
 if __name__ == "__main__":
     run_module_suite()



More information about the Scipy-svn mailing list