@@ -2556,132 +2556,6 @@ def newfunc(val, mask, mval):
25562556 fh .close ()
25572557
25582558
2559- @cbook .deprecated ('2.2' , alternative = 'scipy.interpolate.griddata' )
2560- def griddata (x , y , z , xi , yi , interp = 'nn' ):
2561- """
2562- Interpolates from a nonuniformly spaced grid to some other grid.
2563-
2564- Fits a surface of the form z = f(`x`, `y`) to the data in the
2565- (usually) nonuniformly spaced vectors (`x`, `y`, `z`), then
2566- interpolates this surface at the points specified by
2567- (`xi`, `yi`) to produce `zi`.
2568-
2569- Parameters
2570- ----------
2571- x, y, z : 1d array_like
2572- Coordinates of grid points to interpolate from.
2573- xi, yi : 1d or 2d array_like
2574- Coordinates of grid points to interpolate to.
2575- interp : string key from {'nn', 'linear'}
2576- Interpolation algorithm, either 'nn' for natural neighbor, or
2577- 'linear' for linear interpolation.
2578-
2579- Returns
2580- -------
2581- 2d float array
2582- Array of values interpolated at (`xi`, `yi`) points. Array
2583- will be masked is any of (`xi`, `yi`) are outside the convex
2584- hull of (`x`, `y`).
2585-
2586- Notes
2587- -----
2588- If `interp` is 'nn' (the default), uses natural neighbor
2589- interpolation based on Delaunay triangulation. This option is
2590- only available if the mpl_toolkits.natgrid module is installed.
2591- This can be downloaded from https://github.com/matplotlib/natgrid.
2592- The (`xi`, `yi`) grid must be regular and monotonically increasing
2593- in this case.
2594-
2595- If `interp` is 'linear', linear interpolation is used via
2596- matplotlib.tri.LinearTriInterpolator.
2597-
2598- Instead of using `griddata`, more flexible functionality and other
2599- interpolation options are available using a
2600- matplotlib.tri.Triangulation and a matplotlib.tri.TriInterpolator.
2601- """
2602- # Check input arguments.
2603- x = np .asanyarray (x , dtype = np .float64 )
2604- y = np .asanyarray (y , dtype = np .float64 )
2605- z = np .asanyarray (z , dtype = np .float64 )
2606- if x .shape != y .shape or x .shape != z .shape or x .ndim != 1 :
2607- raise ValueError ("x, y and z must be equal-length 1-D arrays" )
2608-
2609- xi = np .asanyarray (xi , dtype = np .float64 )
2610- yi = np .asanyarray (yi , dtype = np .float64 )
2611- if xi .ndim != yi .ndim :
2612- raise ValueError ("xi and yi must be arrays with the same number of "
2613- "dimensions (1 or 2)" )
2614- if xi .ndim == 2 and xi .shape != yi .shape :
2615- raise ValueError ("if xi and yi are 2D arrays, they must have the same "
2616- "shape" )
2617- if xi .ndim == 1 :
2618- xi , yi = np .meshgrid (xi , yi )
2619-
2620- if interp == 'nn' :
2621- use_nn_interpolation = True
2622- elif interp == 'linear' :
2623- use_nn_interpolation = False
2624- else :
2625- raise ValueError ("interp keyword must be one of 'linear' (for linear "
2626- "interpolation) or 'nn' (for natural neighbor "
2627- "interpolation). Default is 'nn'." )
2628-
2629- # Remove masked points.
2630- mask = np .ma .getmask (z )
2631- if mask is not np .ma .nomask :
2632- x = x .compress (~ mask )
2633- y = y .compress (~ mask )
2634- z = z .compressed ()
2635-
2636- if use_nn_interpolation :
2637- try :
2638- from mpl_toolkits .natgrid import _natgrid
2639- except ImportError :
2640- raise RuntimeError (
2641- "To use interp='nn' (Natural Neighbor interpolation) in "
2642- "griddata, natgrid must be installed. Either install it "
2643- "from http://github.com/matplotlib/natgrid or use "
2644- "interp='linear' instead." )
2645-
2646- if xi .ndim == 2 :
2647- # natgrid expects 1D xi and yi arrays.
2648- xi = xi [0 , :]
2649- yi = yi [:, 0 ]
2650-
2651- # Override default natgrid internal parameters.
2652- _natgrid .seti (b'ext' , 0 )
2653- _natgrid .setr (b'nul' , np .nan )
2654-
2655- if np .min (np .diff (xi )) < 0 or np .min (np .diff (yi )) < 0 :
2656- raise ValueError ("Output grid defined by xi,yi must be monotone "
2657- "increasing" )
2658-
2659- # Allocate array for output (buffer will be overwritten by natgridd)
2660- zi = np .empty ((yi .shape [0 ], xi .shape [0 ]), np .float64 )
2661-
2662- # Natgrid requires each array to be contiguous rather than e.g. a view
2663- # that is a non-contiguous slice of another array. Use numpy.require
2664- # to deal with this, which will copy if necessary.
2665- x = np .require (x , requirements = ['C' ])
2666- y = np .require (y , requirements = ['C' ])
2667- z = np .require (z , requirements = ['C' ])
2668- xi = np .require (xi , requirements = ['C' ])
2669- yi = np .require (yi , requirements = ['C' ])
2670- _natgrid .natgridd (x , y , z , xi , yi , zi )
2671-
2672- # Mask points on grid outside convex hull of input data.
2673- if np .any (np .isnan (zi )):
2674- zi = np .ma .masked_where (np .isnan (zi ), zi )
2675- return zi
2676- else :
2677- # Linear interpolation performed using a matplotlib.tri.Triangulation
2678- # and a matplotlib.tri.LinearTriInterpolator.
2679- from .tri import Triangulation , LinearTriInterpolator
2680- triang = Triangulation (x , y )
2681- interpolator = LinearTriInterpolator (triang , z )
2682- return interpolator (xi , yi )
2683-
2684-
26852559##################################################
26862560# Linear interpolation algorithms
26872561##################################################
0 commit comments