def test_no_weights_cube_provided(self): """Test that if a weights cube is not provided, the function generates a weights array that will equally weight all fields along the blending coordinate.""" plugin = WeightedBlendAcrossWholeDimension(self.coord) result = plugin.non_percentile_weights(self.cube, None) (blending_coord_length, ) = self.cube.coord(self.coord).shape expected = (np.ones(blending_coord_length) / blending_coord_length).astype(np.float32) self.assertEqual(self.cube.shape, result.shape) self.assertArrayEqual(expected, result[:, 0, 0])
def test_1D_weights_3D_cube_custom_aggregator(self): """Test a 1D cube of weights results in a 3D array of weights. With the weighted maximum method (custom_aggregator=True) the shape will be almost the same as the data cube, but the blending coordinate will have been moved to the -1 position.""" coord = "forecast_reference_time" plugin = WeightedBlendAcrossWholeDimension(coord, 'weighted_mean') expected_shape = (2, 2, 3) result = plugin.non_percentile_weights(self.cube, self.weights1d, custom_aggregator=True) self.assertEqual(expected_shape, result.shape) self.assertArrayEqual(self.weights1d.data, result[0, 0, :])