def assert_values(self, values):
        # values is a list of [x, y, [val1, val2]]
        xs, ys, expecteds = zip(*values)
        expecteds = np.array(expecteds)[None, None, ...]
        result = _regrid_bilinear_array(
            self.data, self.x_dim, self.y_dim, self.x, self.y, np.array([xs]), np.array([ys])
        )
        self.assertArrayAllClose(result, expecteds, rtol=1e-04)

        # Check that transposing the input data results in the same values
        ndim = self.data.ndim
        result2 = _regrid_bilinear_array(
            self.data.T, ndim - self.x_dim - 1, ndim - self.y_dim - 1, self.x, self.y, np.array([xs]), np.array([ys])
        )
        self.assertArrayEqual(result.T, result2)
    def assert_values(self, values):
        # values is a list of [x, y, [val1, val2]]
        xs, ys, expecteds = zip(*values)
        expecteds = np.array(expecteds)[None, None, ...]
        result = _regrid_bilinear_array(self.data, self.x_dim, self.y_dim,
                                        self.x, self.y, np.array([xs]),
                                        np.array([ys]))
        self.assertArrayAllClose(result, expecteds, rtol=1e-04)

        # Check that transposing the input data results in the same values
        ndim = self.data.ndim
        result2 = _regrid_bilinear_array(self.data.T, ndim - self.x_dim - 1,
                                         ndim - self.y_dim - 1, self.x, self.y,
                                         np.array([xs]), np.array([ys]))
        self.assertArrayEqual(result.T, result2)
 def test_reverse_x_coord(self):
     index = [slice(None)] * self.data.ndim
     index[self.x_dim] = slice(None, None, -1)
     result = _regrid_bilinear_array(self.data[index], self.x_dim,
                                     self.y_dim, self.x[::-1], self.y,
                                     self.target_x, self.target_y)
     self.assertArrayEqual(result, self.expected)
 def test_reverse_x_coord(self):
     index = [slice(None)] * self.data.ndim
     index[self.x_dim] = slice(None, None, -1)
     result = _regrid_bilinear_array(self.data[index], self.x_dim,
                                     self.y_dim, self.x[::-1], self.y,
                                     self.target_x, self.target_y)
     self.assertArrayEqual(result, self.expected)
 def test_circular_x_coord(self):
     # Check that interpolation of a circular src coordinate doesn't result
     # in an out of bounds value.
     self.x.circular = True
     self.x.units = "degree"
     result = _regrid_bilinear_array(
         self.data, self.x_dim, self.y_dim, self.x, self.y, np.array([[58]]), np.array([[0]])
     )
     self.assertArrayAlmostEqual(result, np.array([56.80398671, 113.60797342], ndmin=self.data.ndim))
 def test_circular_x_coord(self):
     # Check that interpolation of a circular src coordinate doesn't result
     # in an out of bounds value.
     self.x.circular = True
     self.x.units = 'degree'
     result = _regrid_bilinear_array(self.data, self.x_dim, self.y_dim,
                                     self.x, self.y, np.array([[58]]),
                                     np.array([[0]]))
     self.assertArrayAlmostEqual(
         result, np.array([56.80398671, 113.60797342],
                          ndmin=self.data.ndim))
 def test_simple_masked(self):
     data = np.ma.MaskedArray(self.data, mask=True)
     data.mask[:, 1:30, 1:30] = False
     result = _regrid_bilinear_array(data, self.x_dim, self.y_dim, self.x,
                                     self.y, self.target_x, self.target_y)
     expected_mask = np.array(
         [[[[True, True], [True, True], [True, True], [True, True]],
           [[True, True], [False, False], [True, True], [True, True]],
           [[True, True], [True, True], [True, True], [True, True]]]],
         dtype=bool)
     expected = np.ma.MaskedArray(self.expected, mask=expected_mask)
     self.assertMaskedArrayEqual(result, expected)
 def _regrid(self, data, extrapolation_mode=None):
     x = np.arange(4)
     y = np.arange(3)
     x_coord = DimCoord(x)
     y_coord = DimCoord(y)
     x_dim, y_dim = 1, 0
     grid_x, grid_y = np.meshgrid(np.arange(5), y)
     kwargs = {}
     if extrapolation_mode is not None:
         kwargs['extrapolation_mode'] = extrapolation_mode
     result = _regrid_bilinear_array(data, x_dim, y_dim, x_coord, y_coord,
                                     grid_x, grid_y, **kwargs)
     return result
 def test_simple_masked(self):
     data = np.ma.MaskedArray(self.data, mask=True)
     data.mask[:, 1:30, 1:30] = False
     result = _regrid_bilinear_array(data, self.x_dim, self.y_dim,
                                     self.x, self.y,
                                     self.target_x, self.target_y)
     expected_mask = np.array([[[[True, True], [True, True],
                                 [True, True], [True, True]],
                                [[True, True], [False, False],
                                 [True, True], [True, True]],
                                [[True, True], [True, True],
                                 [True, True], [True, True]]]], dtype=bool)
     expected = np.ma.MaskedArray(self.expected,
                                  mask=expected_mask)
     self.assertMaskedArrayEqual(result, expected)
 def test_simple_result(self):
     result = _regrid_bilinear_array(self.data, self.x_dim, self.y_dim,
                                     self.x, self.y, self.target_x,
                                     self.target_y)
     self.assertArrayEqual(result, self.expected)
 def test_result_transpose_shape(self):
     ndim = self.data.ndim
     result = _regrid_bilinear_array(self.data.T, ndim - self.x_dim - 1,
                                     ndim - self.y_dim - 1, self.x, self.y,
                                     self.target_x, self.target_y)
     self.assertArrayEqual(result, self.expected.T)
 def test_simple_masked_no_mask(self):
     data = np.ma.MaskedArray(self.data, mask=False)
     result = _regrid_bilinear_array(data, self.x_dim, self.y_dim, self.x,
                                     self.y, self.target_x, self.target_y)
     self.assertIsInstance(result, np.ma.MaskedArray)
 def test_simple_result(self):
     result = _regrid_bilinear_array(self.data, self.x_dim, self.y_dim,
                                     self.x, self.y,
                                     self.target_x, self.target_y)
     self.assertArrayEqual(result, self.expected)
 def test_result_transpose_shape(self):
     ndim = self.data.ndim
     result = _regrid_bilinear_array(self.data.T, ndim - self.x_dim - 1,
                                     ndim - self.y_dim - 1, self.x, self.y,
                                     self.target_x, self.target_y)
     self.assertArrayEqual(result, self.expected.T)
 def test_simple_masked_no_mask(self):
     data = np.ma.MaskedArray(self.data, mask=False)
     result = _regrid_bilinear_array(data, self.x_dim, self.y_dim,
                                     self.x, self.y,
                                     self.target_x, self.target_y)
     self.assertIsInstance(result, np.ma.MaskedArray)