示例#1
0
    def test_cubelist_mosg__model_configuration_mismatched(self):
        """Test that the utility adds coords for model if not matching and that
        mosg__model_configuration is changed to "blend" ensuring the two cubes
        can be combined."""

        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'mosg__model_configuration': 'uk_det'})
        cube2.attributes.update({'mosg__model_configuration': 'uk_ens'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(
            cubelist, model_id_attr="mosg__model_configuration")

        self.assertArrayAlmostEqual(result[0].coord("model_id").points,
                                    np.array([0]))
        self.assertEqual(result[0].coord("model_configuration").points[0],
                         'uk_det')
        self.assertArrayAlmostEqual(result[1].coord("model_id").points,
                                    np.array([1000]))
        self.assertEqual(result[1].coord("model_configuration").points[0],
                         'uk_ens')
        self.assertIn("mosg__model_configuration", result[0].attributes.keys())
        self.assertEqual(result[0].attributes["mosg__model_configuration"],
                         "blend")
        self.assertIn("mosg__model_configuration", result[1].attributes.keys())
        self.assertEqual(result[1].attributes["mosg__model_configuration"],
                         "blend")
    def test_cubelist_grid_id_same(self):
        """Test that the utility updates grid_id if in list and not matching"""

        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'grid_id': 'ukvx_standard_v1'})
        cube2.attributes.update({'grid_id': 'ukvx_standard_v1'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)

        self.assertEqual(result[0].attributes["grid_id"],
                         result[1].attributes["grid_id"])
示例#3
0
    def test_cubelist_no_history_removal(self):
        """Test that the utility does not remove history attribute,
        if they are the same.
        """
        cube1 = self.cube.copy()
        cube2 = self.cube.copy()
        cube2.coord("time").points = 402195.0
        cube1.attributes["history"] = "2017-01-18T08:59:53: StaGE Decoupler"
        cube2.attributes["history"] = "2017-01-18T08:59:53: StaGE Decoupler"

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)
        self.assertIn("history", result[0].attributes.keys())
        self.assertIn("history", result[1].attributes.keys())
    def test_cubelist_title_identical(self):
        """Test that the utility does nothing to title if they match"""

        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'title': 'Operational UKV Model Forecast'})
        cube2.attributes.update({'title': 'Operational UKV Model Forecast'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)
        self.assertEqual(result[0].attributes["title"],
                         result[1].attributes["title"])
        self.assertEqual(result[0].attributes["title"],
                         'Operational UKV Model Forecast')
示例#5
0
    def test_unknown_attribute(self, warning_list=None):
        """Test that the utility returns warning and removes unknown
        mismatching attribute."""
        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'unknown_attribute': '1'})
        cube2.attributes.update({'unknown_attribute': '2'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)
        self.assertTrue(
            any(item.category == UserWarning for item in warning_list))
        warning_msg = "Do not know what to do with "
        self.assertTrue(any(warning_msg in str(item) for item in warning_list))
        self.assertNotIn("unknown_attribute", result[0].attributes.keys())
        self.assertNotIn("unknown_attribute", result[1].attributes.keys())
示例#6
0
    def test_cubelist_mosg__model_configuration_identical(self):
        """
        Test that the utility does nothing to mosg__model_configuration if
        they match
        """

        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'mosg__model_configuration': 'uk_det'})
        cube2.attributes.update({'mosg__model_configuration': 'uk_det'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)
        self.assertEqual(result[0].attributes["mosg__model_configuration"],
                         result[1].attributes["mosg__model_configuration"])
        self.assertEqual(result[0].attributes["mosg__model_configuration"],
                         'uk_det')
    def test_cubelist_grid_id_not_in_list(self):
        """Test leaves grid_id alone if grid_id not matching and not in list
        In this case the cubes would not merge.
        """

        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'grid_id': 'ukx_standard_v1'})
        cube2.attributes.update({'grid_id': 'unknown_grid'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)

        self.assertIn("grid_id", result[0].attributes.keys())
        self.assertEqual(result[0].attributes["grid_id"], 'ukx_standard_v1')
        self.assertIn("grid_id", result[1].attributes.keys())
        self.assertEqual(result[1].attributes["grid_id"], 'unknown_grid')
    def test_cubelist_title(self):
        """Test that the utility adds coords for model if not matching"""

        cube1 = self.cube_ukv.copy()
        cube2 = self.cube.copy()
        cube1.attributes.update({'title': 'Operational UKV Model Forecast'})
        cube2.attributes.update(
            {'title': 'Operational Mogreps UK Model Forecast'})

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _equalise_cube_attributes(cubelist)

        self.assertArrayAlmostEqual(result[0].coord("model_id").points,
                                    np.array([0]))
        self.assertEqual(result[0].coord("model").points[0],
                         'Operational UKV Model Forecast')
        self.assertArrayAlmostEqual(result[1].coord("model_id").points,
                                    np.array([1000]))
        self.assertEqual(result[1].coord("model").points[0],
                         'Operational Mogreps UK Model Forecast')
        self.assertNotIn("title", result[0].attributes.keys())
        self.assertNotIn("title", result[1].attributes.keys())