def test_interpolate_block_2(self): def f(i, j): return float(i + j) origin = (0, 0) shape = (3, 5) # nrows, ncols fUL = f(0, 0) # 0.0 fUR = f(0, 4) # 4.0 fLL = f(2, 0) # 2.0 fLR = f(2, 4) # 6.0 a = bilinear(shape, fUL, fUR, fLR, fLL) # print '\n', a self.assertEqual(a[0, 0], fUL) self.assertEqual(a[0, -1], fUR) self.assertEqual(a[-1, -1], fLR) self.assertEqual(a[-1, 0], fLL) b = interpolate_block(origin, shape, f, grid=None) # print '\n', b self.assert_(numpy.max(b - a) < 0.000001)
def test_bilinear_2(self): a = bilinear((5, 5), 0.0, 1.0, 2.0, 1.0) # print '\n', a self.assertEqual(a[0, 0], 0.0) self.assertEqual(a[0, 4], 1.0) self.assertEqual(a[4, 0], 1.0) self.assertEqual(a[2, 2], 1.0) self.assertEqual(a[4, 4], 2.0)
def test_bilinear_0(self): x = math.pi a = bilinear((5, 5), x, x, x, x) self.assertEqual(a[0, 0], x) self.assertEqual(a[0, 4], x) self.assertEqual(a[4, 4], x) self.assertEqual(a[2, 2], x) self.assertEqual(a[4, 0], x)
def test_bilinear(self): """ Simple test case for the bilinear interpolation function """ expected = np.arange(0, 100, dtype=np.float64).reshape(10,10) in_arr = np.zeros(100).reshape(10,10) result = bilinear(in_arr.shape, 0, 9, 99, 90) self.assertTrue(np.allclose(result, expected))
def test_interpolate_block_3(self): def f(i, j): return float(i)**2 * math.sqrt(float(j)) origin = (0, 0) shape = (3, 5) # nrows, ncols fUL = f(0, 0) fUR = f(0, 4) fLL = f(2, 0) fLR = f(2, 4) a = bilinear(shape, fUL, fUR, fLR, fLL) # print '\n', a self.assertEqual(a[0, 0], fUL) self.assertEqual(a[0, -1], fUR) self.assertEqual(a[-1, -1], fLR) self.assertEqual(a[-1, 0], fLL) b = interpolate_block(origin, shape, f, grid=None) # print '\n', b self.assertTrue(numpy.max(b - a) < 0.000001)