Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66eb504

Browse files
committed
Remove mlab.griddata
1 parent b834f3f commit 66eb504

File tree

4 files changed

+2
-203
lines changed

4 files changed

+2
-203
lines changed

doc/api/next_api_changes/2018-09-18-DS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ in Matplotlib 2.2 has been removed. See below for a list:
2121
- `mlab.get_sparse_matrix`
2222
- `mlab.dist` (use numpy.hypot instead)
2323
- `mlab.dist_point_to_segment`
24+
- `mlab.griddata` (use scipy.interpolate.griddata)
2425
- `mlab.donothing_callback`

lib/matplotlib/mlab.py

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -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
##################################################

lib/matplotlib/pylab.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@
195195
_Other
196196
197197
angle - the angle of a complex array
198-
griddata - interpolate irregularly distributed data to a regular grid
199198
load - Deprecated--please use loadtxt.
200199
loadtxt - load ASCII data into array.
201200
polyfit - fit x, y to an n-th order polynomial
@@ -233,7 +232,7 @@
233232
amap, base_repr, binary_repr, csv2rec,
234233
demean, detrend, detrend_linear, detrend_mean, detrend_none,
235234
distances_along_curve, exp_safe,
236-
fftsurr, frange, griddata,
235+
fftsurr, frange,
237236
identity, inside_poly, is_closed_polygon, ispower2, isvector, l1norm,
238237
l2norm, log2, movavg, norm_flat,
239238
path_length, poly_below, poly_between,

lib/matplotlib/tests/test_mlab.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,81 +2081,6 @@ def test_cohere():
20812081
assert np.isreal(np.mean(cohsq))
20822082

20832083

2084-
def test_griddata_linear():
2085-
# z is a linear function of x and y.
2086-
def get_z(x, y):
2087-
return 3.0*x - y
2088-
2089-
# Passing 1D xi and yi arrays to griddata.
2090-
x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
2091-
y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
2092-
z = get_z(x, y)
2093-
xi = [0.2, 0.4, 0.6, 0.8]
2094-
yi = [0.1, 0.3, 0.7, 0.9]
2095-
with pytest.warns(MatplotlibDeprecationWarning):
2096-
zi = mlab.griddata(x, y, z, xi, yi, interp='linear')
2097-
xi, yi = np.meshgrid(xi, yi)
2098-
np.testing.assert_array_almost_equal(zi, get_z(xi, yi))
2099-
2100-
# Passing 2D xi and yi arrays to griddata.
2101-
with pytest.warns(MatplotlibDeprecationWarning):
2102-
zi = mlab.griddata(x, y, z, xi, yi, interp='linear')
2103-
np.testing.assert_array_almost_equal(zi, get_z(xi, yi))
2104-
2105-
# Masking z array.
2106-
z_masked = np.ma.array(z, mask=[False, False, False, True, False])
2107-
correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, get_z(xi, yi))
2108-
with pytest.warns(MatplotlibDeprecationWarning):
2109-
zi = mlab.griddata(x, y, z_masked, xi, yi, interp='linear')
2110-
matest.assert_array_almost_equal(zi, correct_zi_masked)
2111-
np.testing.assert_array_equal(np.ma.getmask(zi),
2112-
np.ma.getmask(correct_zi_masked))
2113-
2114-
2115-
def test_griddata_nn():
2116-
pytest.importorskip('mpl_toolkits.natgrid')
2117-
2118-
# z is a linear function of x and y.
2119-
def get_z(x, y):
2120-
return 3.0*x - y
2121-
2122-
# Passing 1D xi and yi arrays to griddata.
2123-
x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
2124-
y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
2125-
z = get_z(x, y)
2126-
xi = [0.2, 0.4, 0.6, 0.8]
2127-
yi = [0.1, 0.3, 0.7, 0.9]
2128-
correct_zi = [[0.49999252, 1.0999978, 1.7000030, 2.3000080],
2129-
[0.29999208, 0.8999978, 1.5000029, 2.1000059],
2130-
[-0.1000099, 0.4999943, 1.0999964, 1.6999979],
2131-
[-0.3000128, 0.2999894, 0.8999913, 1.4999933]]
2132-
with pytest.warns(MatplotlibDeprecationWarning):
2133-
zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
2134-
np.testing.assert_array_almost_equal(zi, correct_zi, 5)
2135-
2136-
with pytest.warns(MatplotlibDeprecationWarning):
2137-
# Decreasing xi or yi should raise ValueError.
2138-
with pytest.raises(ValueError):
2139-
mlab.griddata(x, y, z, xi[::-1], yi, interp='nn')
2140-
with pytest.raises(ValueError):
2141-
mlab.griddata(x, y, z, xi, yi[::-1], interp='nn')
2142-
2143-
# Passing 2D xi and yi arrays to griddata.
2144-
xi, yi = np.meshgrid(xi, yi)
2145-
with pytest.warns(MatplotlibDeprecationWarning):
2146-
zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
2147-
np.testing.assert_array_almost_equal(zi, correct_zi, 5)
2148-
2149-
# Masking z array.
2150-
z_masked = np.ma.array(z, mask=[False, False, False, True, False])
2151-
correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, correct_zi)
2152-
with pytest.warns(MatplotlibDeprecationWarning):
2153-
zi = mlab.griddata(x, y, z_masked, xi, yi, interp='nn')
2154-
np.testing.assert_array_almost_equal(zi, correct_zi_masked, 5)
2155-
np.testing.assert_array_equal(np.ma.getmask(zi),
2156-
np.ma.getmask(correct_zi_masked))
2157-
2158-
21592084
#*****************************************************************
21602085
# These Tests where taken from SCIPY with some minor modifications
21612086
# this can be retrieved from:

0 commit comments

Comments
 (0)