def test_alphas_shape_does_not_match_data_shape_when_alphas_not_none(self): """Test if array dimensions of alphas array do not match dimensions of data_array when alphas is not set to None (invalid).""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) msg = "Dimensions of alphas array do not match dimensions " with self.assertRaisesRegexp(ValueError, msg): plugin.set_alphas(self.cube, self.alpha_x, self.alphas_cube2)
def test_alphas_cube_and_alpha_not_set(self): """Test error is raised when both alphas_cube and alpha are set to None (invalid).""" alpha_x = None alpha_y = None alphas_cube = None plugin = RecursiveFilter(alpha_x=alpha_x, alpha_y=alpha_y, iterations=self.iterations) msg = "A value for alpha must be set if alphas_cube is " with self.assertRaisesRegexp(ValueError, msg): plugin.set_alphas(self.cube, alpha_x, alphas_cube)
def test_alphas_array_as_expected_when_alphas_is_not_none(self): """Test that the returned alphas array has the expected result when alphas=None.""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) result = plugin.set_alphas(self.cube, self.alpha_x, self.alphas_cube1) expected_result = 0.5 self.assertIsInstance(result.data, np.ndarray) self.assertEqual(result.data[0][2], expected_result) # Check shape: Array should be padded with 4 extra rows/columns expected_shape = (9, 9) self.assertEqual(result.shape, expected_shape)
def test_basic(self): """Test that the run_recursion method returns an iris.cube.Cube.""" edge_width = 1 alphas_x = None alphas_y = None plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) alphas_x = plugin.set_alphas(self.cube, self.alpha_x, alphas_x) alphas_y = plugin.set_alphas(self.cube, self.alpha_y, alphas_y) padded_cube = SquareNeighbourhood().pad_cube_with_halo(self.cube, edge_width, edge_width) result = plugin.run_recursion(padded_cube, alphas_x, alphas_y, self.iterations) self.assertIsInstance(result, Cube)
def test_expected_result(self): """Test that the run_recursion method returns an iris.cube.Cube.""" edge_width = 1 alphas_x = None alphas_y = None plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) alphas_x = plugin.set_alphas(self.cube, self.alpha_x, alphas_x) alphas_y = plugin.set_alphas(self.cube, self.alpha_y, alphas_y) padded_cube = SquareNeighbourhood().pad_cube_with_halo(self.cube, edge_width, edge_width) result = plugin.run_recursion(padded_cube, alphas_x, alphas_y, self.iterations) expected_result = 0.13382206 self.assertAlmostEqual(result.data[4][4], expected_result)