def test_defaults(self):
     """Test default arguments produce cube with expected dimensions
     and metadata"""
     result = set_up_percentile_cube(self.data, self.percentiles)
     perc_coord = result.coord("percentile_over_realization")
     self.assertArrayEqual(perc_coord.points, self.percentiles)
     self.assertEqual(perc_coord.units, "%")
Ejemplo n.º 2
0
 def test_percentile_coord_name(self):
     """Test ability to set a different name"""
     result = set_up_percentile_cube(self.data,
                                     self.percentiles,
                                     percentile_dim_name="percentile")
     dim_coords = [coord.name() for coord in result.coords(dim_coords=True)]
     self.assertIn("percentile", dim_coords)
Ejemplo n.º 3
0
 def test_error_non_probability_cube(self):
     """Test failure if cube doesn't contain probabilities"""
     perc_cube = set_up_percentile_cube(
         np.ones((3, 3, 3), dtype=np.float32),
         np.array((25, 50, 75), dtype=np.float32))
     plugin = OccurrenceBetweenThresholds([[25, 50]], 'K')
     msg = 'Input is not a probability cube'
     with self.assertRaisesRegex(ValueError, msg):
         plugin.process(perc_cube)
 def test_standard_grid_metadata(self):
     """Test standard grid metadata"""
     result = set_up_percentile_cube(self.data, self.percentiles,
                                     standard_grid_metadata='uk_ens')
     self.assertEqual(result.attributes['mosg__grid_type'], 'standard')
     self.assertEqual(result.attributes['mosg__grid_version'], '1.3.0')
     self.assertEqual(
         result.attributes['mosg__grid_domain'], 'uk_extended')
     self.assertEqual(
         result.attributes['mosg__model_configuration'], 'uk_ens')
Ejemplo n.º 5
0
 def test_ordering_for_percentile_coordinate(self):
     """Test that the cube has been reordered, if it is originally in an
     undesirable order and the cube contains a "percentile" coordinate."""
     data = np.ones((3, 4, 5), dtype=np.float32)
     cube = set_up_percentile_cube(data, np.array([10, 50, 90]))
     cube.transpose([2, 1, 0])
     save_netcdf(cube, self.filepath)
     result = load_cube(self.filepath)
     self.assertEqual(result.coord_dims("percentile")[0], 0)
     self.assertArrayAlmostEqual(result.coord_dims("latitude")[0], 1)
     self.assertArrayAlmostEqual(result.coord_dims("longitude")[0], 2)
Ejemplo n.º 6
0
    def setUp(self):
        """Set up some conformant cubes of air_temperature to test"""
        data = 275 * np.ones((3, 3), dtype=np.float32)
        self.data_cube = set_up_variable_cube(data, spatial_grid='equalarea')

        data = np.ones((3, 3, 3), dtype=np.float32)
        thresholds = np.array([272, 273, 274], dtype=np.float32)
        self.probability_cube = set_up_probability_cube(data, thresholds)

        data = np.array([
            274 * np.ones((3, 3), dtype=np.float32), 275 * np.ones(
                (3, 3), dtype=np.float32), 276 * np.ones(
                    (3, 3), dtype=np.float32)
        ])
        percentiles = np.array([25, 50, 75], np.float32)
        self.percentile_cube = set_up_percentile_cube(data, percentiles)
Ejemplo n.º 7
0
    def setUp(self):
        """Set up some conformant cubes of air_temperature to test"""
        data = 275 * np.ones((3, 3), dtype=np.float32)
        self.data_cube = set_up_variable_cube(data, spatial_grid='equalarea')

        data = np.ones((3, 3, 3), dtype=np.float32)
        thresholds = np.array([272, 273, 274], dtype=np.float32)
        self.probability_cube = set_up_probability_cube(data, thresholds)

        data = np.array([
            274 * np.ones((3, 3), dtype=np.float32), 275 * np.ones(
                (3, 3), dtype=np.float32), 276 * np.ones(
                    (3, 3), dtype=np.float32)
        ])
        percentiles = np.array([25, 50, 75], np.float32)
        self.percentile_cube = set_up_percentile_cube(data, percentiles)
        # set to real source here, to test consistency of setup functions
        # with up-to-date metadata standard
        cube_units.DEFAULT_UNITS = improver.units.DEFAULT_UNITS