def test_process(self): """Test that the RecursiveFilter plugin returns the correct data""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) result = plugin.process(self.cube, alphas_x=None, alphas_y=None) expected = 0.13382206 self.assertAlmostEqual(result.data[0][2][2], expected)
def test_return_type(self): """Test that the RecursiveFilter plugin returns an iris.cube.Cube.""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) result = plugin.process(self.cube, alphas_x=None, alphas_y=None) self.assertIsInstance(result, Cube)
def test_alpha_floats_nan_in_data(self): """Test that the RecursiveFilter plugin returns the correct data when using float alpha values and the data contains nans.""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) self.cube.data[0][3][2] = np.nan result = plugin.process(self.cube, alphas_x=None, alphas_y=None) expected = 0.11979733 self.assertAlmostEqual(result.data[0][2][2], expected)
def test_dimensions_of_output_array_is_as_expected(self): """Test that the RecursiveFilter plugin returns a data array with the correct dimensions""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) result = plugin.process(self.cube, alphas_x=None, alphas_y=None) # Output data array should have same dimensions as input data array expected_shape = (1, 5, 5) self.assertEqual(result.data.shape, expected_shape) self.assertEqual(result.data.shape, expected_shape)
def test_alpha_cubes_masked_data(self): """Test that the RecursiveFilter plugin returns the correct data when using alpha cubes and a masked data cube.""" plugin = RecursiveFilter(alpha_x=None, alpha_y=None, iterations=self.iterations) mask = np.zeros((self.cube.data.shape)) mask[0][3][2] = 1 self.cube.data = np.ma.MaskedArray(self.cube.data, mask=mask) result = plugin.process(self.cube, alphas_x=self.alphas_cube, alphas_y=self.alphas_cube) expected = 0.11979733 self.assertAlmostEqual(result.data[0][2][2], expected)
def test_alpha_floats_nan_in_masked_data(self): """Test that the RecursiveFilter plugin returns the correct data when using float alpha values, the data contains nans and the data is masked (but not the nan value).""" plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=self.alpha_y, iterations=self.iterations) self.cube.data[0][3][2] = np.nan mask = np.zeros((self.cube.data.shape)) mask[0][1][2] = 1 self.cube.data = np.ma.MaskedArray(self.cube.data, mask=mask) result = plugin.process(self.cube, alphas_x=None, alphas_y=None) expected = 0.105854129 self.assertAlmostEqual(result.data[0][2][2], expected)
def test_coordinate_reordering_with_different_alphas(self): """Test that x and y alphas still apply to the right coordinate when the input cube spatial dimensions are (x, y) not (y, x)""" alpha_y = 0.5*self.alpha_x cube = enforce_coordinate_ordering(self.cube, ["time", "longitude", "latitude"]) plugin = RecursiveFilter(alpha_x=self.alpha_x, alpha_y=alpha_y, iterations=self.iterations) result = plugin.process(cube) expected_result = np.array( [[0.01620921, 0.03978802, 0.10592333, 0.03978982, 0.01621686], [0.02866841, 0.06457599, 0.15184643, 0.06457873, 0.02868005], [0.05077430, 0.10290188, 0.19869247, 0.10290585, 0.05079120], [0.02881413, 0.06486591, 0.15238355, 0.06486866, 0.02882582], [0.01657352, 0.04051282, 0.10726611, 0.04051464, 0.01658128]]) self.assertSequenceEqual([x.name() for x in result.coords()], ["time", "longitude", "latitude"]) self.assertArrayAlmostEqual(result.data[0], expected_result)