Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for issue #997 #998

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/matplotlib/delaunay/_delaunay.cpp
Expand Up @@ -293,17 +293,19 @@ static PyObject *linear_interpolate_grid(double x0, double x1, int xsteps,
dy = (y1 - y0) / (ysteps-1);

rowtri = 0;
targety = y0;
for (iy=0; iy<ysteps; iy++) {
targety = y0 + dy*iy;
rowtri = walking_triangles(rowtri, x0, targety, x, y, nodes, neighbors);
tri = rowtri;
targetx = x0;
for (ix=0; ix<xsteps; ix++) {
targetx = x0 + dx*ix;
INDEXN(z_ptr, xsteps, iy, ix) = linear_interpolate_single(
targetx, targety,
x, y, nodes, neighbors, planes, defvalue, tri, &coltri);
if (coltri != -1) tri = coltri;
targetx+=dx;
}
targety+=dy;
}

return z;
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 32 additions & 4 deletions lib/matplotlib/tests/test_delaunay.py
Expand Up @@ -93,13 +93,18 @@ def cosine_peak(x, y):
allfuncs = [exponential, cliff, saddle, gentle, steep, sphere, trig, gauss, cloverleaf, cosine_peak]


def _expand_range(range,epsilon=1e-6):
delta = (range[1]-range[0])*epsilon/2.0
return (range[0]-delta, range[1]+delta)

class LinearTester(object):
name = 'Linear'
def __init__(self, xrange=(0.0, 1.0), yrange=(0.0, 1.0), nrange=101, npoints=250):
self.xrange = xrange
self.yrange = yrange
self.nrange = nrange
self.npoints = npoints
self.bbox = _expand_range(xrange) + _expand_range(yrange)

rng = np.random.RandomState(1234567890)
self.x = rng.uniform(xrange[0], xrange[1], size=npoints)
Expand All @@ -113,7 +118,7 @@ def replace_data(self, dataset):

def interpolator(self, func):
z = func(self.x, self.y)
return self.tri.linear_extrapolator(z, bbox=self.xrange+self.yrange)
return self.tri.linear_extrapolator(z, bbox=self.bbox)

def plot(self, func, interp=True, plotter='imshow'):
if interp:
Expand Down Expand Up @@ -157,9 +162,9 @@ class NNTester(LinearTester):
name = 'Natural Neighbors'
def interpolator(self, func):
z = func(self.x, self.y)
return self.tri.nn_extrapolator(z, bbox=self.xrange+self.yrange)
return self.tri.nn_extrapolator(z, bbox=self.bbox)

def make_all_testfuncs(allfuncs=allfuncs):
def make_all_2d_testfuncs(allfuncs=allfuncs):
def make_test(func):
filenames = [
'%s-%s' % (func.func_name, x) for x in
Expand All @@ -186,4 +191,27 @@ def reference_test():
for func in allfuncs:
globals()['test_%s' % func.func_name] = make_test(func)

make_all_testfuncs()
make_all_2d_testfuncs()

# 1d and 0d grid tests

ref_interpolator = Triangulation([0,10,10,0],
[0,0,10,10]).linear_interpolator([1,10,5,2.0])

def equal_arrays(a1,a2, tolerance=1e-10):
return np.all(np.absolute(a1 - a2) < tolerance)

def test_1d_grid():
res = ref_interpolator[3:6:2j,1:1:1j]
assert equal_arrays(res, [[1.6],[1.9]])

def test_0d_grid():
res = ref_interpolator[3:3:1j,1:1:1j]
assert equal_arrays(res, [[1.6]])

@image_comparison(baseline_images=['delaunay-1d-interp'], extensions=['png'])
def test_1d_plots():
x_range = slice(0.25,9.75,20j)
x = np.mgrid[x_range]
for y in xrange(2,10,2):
plt.plot(x, ref_interpolator[x_range,y:y:1j])