def test_basic(self): """ Test that the plugin returns an iris.cube.Cube, the cube has a realization coordinate and is correctly re-ordered to match the source realizations. """ expected_data = self.raw_cube.data.copy() result = Plugin().process(self.post_processed_percentiles, self.raw_cube) self.assertIsInstance(result, Cube) self.assertTrue(result.coords("realization")) self.assertArrayEqual(result.coord("realization").points, [0, 1, 2]) self.assertArrayAlmostEqual(result.data, expected_data)
def test_realization_for_equal(self): """ Test to check the behaviour when the number of percentiles equals the number of realizations. """ expected_data = np.array([ [[4.0, 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.0]], [[6.0, 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.0]], [[8.0, 8.625, 9.25], [9.875, 10.5, 11.125], [11.75, 12.375, 13.0]], ]) result = Plugin()._recycle_raw_ensemble_realizations( self.percentile_cube, self.realization_cube, self.perc_coord, ) self.assertIsInstance(result, Cube) self.assertArrayEqual(result.coord("realization").points, [0, 1, 2]) self.assertArrayAlmostEqual(result.data, expected_data)
def test_realization_for_less_than(self): """ Test to check the behaviour when the number of percentiles is less than the number of realizations. """ expected_data = np.array([ [[4.0, 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.0]], [[6.0, 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.0]], ]) post_processed_forecast_percentiles = self.percentile_cube[:2, :, :] result = Plugin()._recycle_raw_ensemble_realizations( post_processed_forecast_percentiles, self.realization_cube, self.perc_coord, ) self.assertIsInstance(result, Cube) self.assertArrayEqual(result.coord("realization").points, [0, 1]) self.assertArrayAlmostEqual(result.data, expected_data)
def test_basic_masked_input_data_not_nans(self): """ Test that the plugin returns an iris.cube.Cube, the cube has a realization coordinate with specific realization numbers and is correctly re-ordered to match the source realizations, when the input data is masked and the masked data is not a nan. """ # Assuming input data and raw ensemble are masked in the same way. self.raw_cube.data[:, 0, 0] = 1000 self.raw_cube.data = np.ma.masked_equal(self.raw_cube.data, 1000) self.post_processed_percentiles.data[:, 0, 0] = 1000 self.post_processed_percentiles.data = np.ma.masked_equal( self.post_processed_percentiles.data, 1000) expected_data = self.raw_cube.data.copy() result = Plugin().process(self.post_processed_percentiles, self.raw_cube) self.assertIsInstance(result, Cube) self.assertTrue(result.coords("realization")) self.assertEqual(result.coord("realization"), self.raw_cube.coord("realization")) self.assertArrayAlmostEqual(result.data, expected_data) self.assertArrayEqual(result.data.mask, expected_data.mask)