class Test__create_new_weights_cube(IrisTest): """Test the _create_new_weights_cube function. """ def setUp(self): """Set up some plugin inputs""" self.plugin = ChooseWeightsLinear( "forecast_period", config_dict=CONFIG_DICT_UKV) self.cube, = self.plugin._slice_input_cubes( set_up_basic_model_config_cube()) self.weights = np.array([0., 0., 0.2]) def test_with_dict(self): """Test a new weights cube is created as intended, with the desired cube name.""" new_weights_cube = self.plugin._create_new_weights_cube( self.cube, self.weights) self.assertArrayAlmostEqual(new_weights_cube.data, self.weights) self.assertEqual(new_weights_cube.name(), "weights") # test only relevant coordinates have been retained on the weights cube expected_coords = { 'time', 'forecast_reference_time', 'forecast_period', 'model_id', 'model_configuration'} result_coords = {coord.name() for coord in new_weights_cube.coords()} self.assertSetEqual(result_coords, expected_coords) def test_with_dict_masked_input_cube(self): """Test a new weights cube is created as intended when we have a masked input cube.""" self.cube.data = np.ma.masked_array( self.cube.data, np.ones(self.cube.data.shape)*True) new_weights_cube = self.plugin._create_new_weights_cube( self.cube, self.weights) self.assertEqual(np.ma.is_masked(new_weights_cube.data), False) self.assertArrayAlmostEqual(new_weights_cube.data, self.weights)
def test_with_dict(self): """Test a new weights cube is created as intended, with the desired cube name.""" plugin = ChooseWeightsLinear( self.weighting_coord_name, self.config_dict) new_weights_cube = plugin._create_new_weights_cube( self.cube, self.weights) self.assertArrayAlmostEqual(new_weights_cube.data, self.expected_weights[..., 0, 0]) self.assertEqual(new_weights_cube.name(), "weights")
def test_with_dict_masked_input_cube(self): """Test a new weights cube is created as intended when we have a masked input cube.""" self.cube.data = np.ma.masked_array( self.cube.data, np.ones(self.cube.data.shape)*True) plugin = ChooseWeightsLinear( self.weighting_coord_name, config_dict=self.config_dict) new_weights_cube = plugin._create_new_weights_cube( self.cube, self.weights) self.assertEqual(np.ma.is_masked(new_weights_cube.data), False) self.assertArrayAlmostEqual(new_weights_cube.data, self.expected_weights[..., 0, 0])