def test_easy(self): img = array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) x = [1, 2, 3] y = [1, 2, 3] xx, yy, zz = mm.interp_max(img, x=x, y=y) self.assertAlmostEqual(xx, 2) self.assertAlmostEqual(yy, 2) self.assertAlmostEqual(zz, 1)
def test_surface(self): precision = 200 # restrict range of zero to middle or 1x1 grid xm = rand()*0.8 + 0.1 ym = rand()*0.8 + 0.1 x = linspace(0, 1, 10) y = linspace(0, 1, 10) X, Y = meshgrid(x, y) def func(x, y): return -3*(x - xm)**2 - (y - ym)**2 Z = reshape(array(map(func, X, Y)), (len(x), len(y))) xx, yy, zz = mm.interp_max(Z, x, y, precision=precision) expected_places = 1 self.assertAlmostEqual(xx, xm, places=expected_places) self.assertAlmostEqual(yy, ym, places=expected_places)
def test_surface(self): precision = 200 # restrict range of zero to middle or 1x1 grid xm = rand() * 0.8 + 0.1 ym = rand() * 0.8 + 0.1 x = linspace(0, 1, 10) y = linspace(0, 1, 10) X, Y = meshgrid(x, y) def func(x, y): return -3 * (x - xm)**2 - (y - ym)**2 Z = reshape(array(map(func, X, Y)), (len(x), len(y))) xx, yy, zz = mm.interp_max(Z, x, y, precision=precision) expected_places = 1 self.assertAlmostEqual(xx, xm, places=expected_places) self.assertAlmostEqual(yy, ym, places=expected_places)
def test_easy_using_indices(self): img = array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) xx, yy, zz = mm.interp_max(img) self.assertAlmostEqual(xx, 1) self.assertAlmostEqual(yy, 1) self.assertAlmostEqual(zz, 1)