def test_incompatible_weights_and_data_cubes_shape(self):
     """Test an exception is raised if the weights cube and the data cube
     have incompatible shapes."""
     plugin = WeightedBlendAcrossWholeDimension(self.coord)
     msg = "Weights cube is not a compatible shape"
     with self.assertRaisesRegex(ValueError, msg):
         plugin.shape_weights(self.cube[:1], self.weights1d)
 def test_incompatible_weights_and_data_cubes(self):
     """Test an exception is raised if the weights cube and the data cube
     have incompatible coordinates."""
     self.weights1d.coord(self.coord).rename("threshold")
     plugin = WeightedBlendAcrossWholeDimension(self.coord)
     msg = ("threshold is a coordinate on the weights cube but it "
            "is not found on the cube we are trying to collapse.")
     with self.assertRaisesRegex(ValueError, msg):
         plugin.shape_weights(self.cube, self.weights1d)
예제 #3
0
    def test_incompatible_weights_and_data_cubes(self):
        """Test an exception is raised if the weights cube and the data cube
        have incompatible coordinates."""

        coord = "forecast_reference_time"
        plugin = WeightedBlendAcrossWholeDimension(coord, 'weighted_mean')
        msg = (
            "precipitation_amount is a coordinate on the weights cube but it "
            "is not found on the cube we are trying to collapse.")
        with self.assertRaisesRegex(ValueError, msg):
            plugin.shape_weights(self.cube, self.weights_threshold)
 def test_3D_weights_3D_cube_weighted_mean_unmatched_coordinate(self):
     """Test a 3D cube of weights results in a 3D array of weights of the
     same shape as the data cube. In this test the weights cube has the
     same shape but different coordinates to the diagnostic cube, raising
     a ValueError as a result."""
     plugin = WeightedBlendAcrossWholeDimension(self.coord)
     weights = self.weights3d.copy()
     weights.coord("longitude").rename("projection_x_coordinate")
     msg = ("projection_x_coordinate is a coordinate on the weights cube "
            "but it is not found on the cube we are trying to collapse.")
     with self.assertRaisesRegex(ValueError, msg):
         plugin.shape_weights(self.cube, weights)
 def test_3D_weights_3D_cube_weighted_mean(self):
     """Test a 3D cube of weights results in a 3D array of weights of the
     same shape as the data cube."""
     plugin = WeightedBlendAcrossWholeDimension(self.coord)
     result = plugin.shape_weights(self.cube, self.weights3d)
     self.assertEqual(self.cube.shape, result.shape)
     self.assertArrayEqual(self.weights3d.data, result)
    def test_1D_weights_3D_cube_weighted_mean(self):
        """Test a 1D cube of weights results in a 3D array of weights of the
        same shape as the data cube."""

        coord = "forecast_reference_time"
        plugin = WeightedBlendAcrossWholeDimension(coord)
        result = plugin.shape_weights(self.cube, self.weights1d)
        self.assertEqual(self.cube.shape, result.shape)
        self.assertArrayEqual(self.weights1d.data, result[:, 0, 0])
 def test_3D_weights_3D_cube_weighted_mean_wrong_order(self):
     """Test a 3D cube of weights results in a 3D array of weights of the
     same shape as the data cube. In this test the weights cube has the
     same coordinates but slightly differently ordered. These should be
     reordered to match the cube."""
     plugin = WeightedBlendAcrossWholeDimension(self.coord)
     expected = self.weights3d.copy().data
     self.weights3d.transpose([1, 0, 2])
     result = plugin.shape_weights(self.cube, self.weights3d)
     self.assertEqual(expected.shape, result.shape)
     self.assertArrayEqual(expected.data, result)
 def test_3D_weights_4D_cube_weighted_mean_wrong_order(self):
     """Test a 4D cube of weights results in a 3D array of weights of the
     same shape as the data cube. In this test the input cube has the
     same coordinates but slightly differently ordered. The weights cube
     should be reordered to match the cube."""
     # Add a new axis to input cube to make it 4D
     cube = iris.util.new_axis(self.cube, scalar_coord="time")
     cube.transpose([3, 2, 0, 1])
     plugin = WeightedBlendAcrossWholeDimension(self.coord)
     # Create an expected array which has been transposed to match
     # input cube with the extra axis added.
     expected = self.weights3d.copy()
     expected.transpose([2, 1, 0])
     expected = np.expand_dims(expected.data, axis=2)
     result = plugin.shape_weights(cube, self.weights3d)
     self.assertEqual(expected.shape, result.shape)
     self.assertArrayEqual(expected, result)