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.assertRaisesRegex(ValueError, msg): pad_coord(coord, width, method)
def test_add_y_reorder(self): """Test the functionality to add still works if y is negative.""" expected = np.linspace(105., -15., 7) y_coord = self.cube_y_reorder.coord("projection_y_coordinate") expected_bounds = np.array([expected + 10, expected - 10]).T width = 1 method = "add" new_coord = pad_coord(y_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.linspace(0., 60., 7) coord = self.cube.coord("projection_x_coordinate") expected_bounds = np.array([expected - 5, expected + 5]).T width = 1 method = "add" new_coord = 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_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([20., 30., 40.]) expected_bounds = np.array([expected - 5, expected + 5]).T coord = self.cube.coord("projection_x_coordinate") width = 1 method = "remove" new_coord = pad_coord(coord, width, method) self.assertIsInstance(new_coord, DimCoord) self.assertArrayAlmostEqual(new_coord.points, expected) self.assertArrayEqual(new_coord.bounds, expected_bounds)