def test_exception(self): """Test an exception is raised if the chosen coordinate is non-uniform.""" coord_points = np.arange(10., 60., 10.) coord_points[0] = -200. self.cube.coord("projection_x_coordinate").points = coord_points coord = self.cube.coord("projection_x_coordinate") width = 1 method = "add" msg = "Non-uniform increments between grid points" with self.assertRaisesRegexp(ValueError, msg): SquareNeighbourhood.pad_coord(coord, width, method)
def test_remove(self): """Test the functionality to remove padding from the chosen coordinate. Includes a test that the coordinate bounds array is modified to reflect the new values.""" expected = np.array([30.]) expected_bounds = np.array([expected - 5, expected + 5]).T coord = self.cube.coord("projection_x_coordinate") width = 1 method = "remove" new_coord = SquareNeighbourhood.pad_coord(coord, width, method) self.assertIsInstance(new_coord, DimCoord) self.assertArrayAlmostEqual(new_coord.points, expected) self.assertArrayEqual(new_coord.bounds, expected_bounds)
def test_add(self): """Test the functionality to add padding to the chosen coordinate. Includes a test that the coordinate bounds array is modified to reflect the new values.""" expected = np.array([-10., 0., 10., 20., 30., 40., 50., 60., 70.]) coord = self.cube.coord("projection_x_coordinate") expected_bounds = np.array([expected - 5, expected + 5]).T width = 1 method = "add" new_coord = SquareNeighbourhood.pad_coord(coord, width, method) self.assertIsInstance(new_coord, DimCoord) self.assertArrayAlmostEqual(new_coord.points, expected) self.assertArrayEqual(new_coord.bounds, expected_bounds)