def test_with_weights(self): """Test function when a data cube and a weights cube are provided.""" coord = "forecast_reference_time" plugin = WeightedBlendAcrossWholeDimension(coord, 'weighted_maximum') result = plugin.weighted_maximum(self.cube, self.weights1d) expected = np.full((2, 2), 0.6) self.assertIsInstance(result, iris.cube.Cube) self.assertArrayAlmostEqual(result.data, expected)
def test_without_weights(self): """Test function when a data cube is provided, but no weights cube which should result in equal weightings.""" coord = "forecast_reference_time" plugin = WeightedBlendAcrossWholeDimension(coord, 'weighted_maximum') result = plugin.weighted_maximum(self.cube, None) expected = np.full((2, 2), 1.) self.assertIsInstance(result, iris.cube.Cube) self.assertArrayAlmostEqual(result.data, expected)
def test_with_spatially_varying_weights(self): """Test function when a data cube and a multi dimensional weights cube are provided. This tests spatially varying weights, where each x-y position is weighted differently in each slice along the blending coordinate.""" coord = "forecast_reference_time" plugin = WeightedBlendAcrossWholeDimension(coord, 'weighted_maximum') result = plugin.weighted_maximum(self.cube, self.weights3d) expected = np.array([[2.4, 1.2], [1.8, 0.8]]) self.assertIsInstance(result, iris.cube.Cube) self.assertArrayAlmostEqual(result.data, expected)