Ejemplo n.º 1
0
 def test_day_night(self):
     """Test process returns the right values for night. """
     plugin = WeatherSymbols()
     for i, cube in enumerate(self.cubes):
         self.cubes[i].coord("time").points = cube.coord("time").points + 3600 * 12
     result = plugin.process(self.cubes)
     self.assertArrayEqual(result.data, self.expected_wxcode_night)
Ejemplo n.º 2
0
    def test_weather_data_global(self):
        """Test process returns the right weather values global part2 """
        plugin = WeatherSymbols(wxtree='global')

        data_snow = np.array([
            0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.1, 0.0, 0.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
            1.0
        ]).reshape((3, 3, 3))
        data_rain = np.array([
            1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
            0.0
        ]).reshape((3, 3, 3))
        data_cloud = np.array([
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
            0.0, 1.0, 0.0, 1.0, 1.0
        ]).reshape((2, 3, 3))
        data_cld_low = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                 0.0]).reshape((1, 3, 3))
        data_vis = np.array([
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0
        ]).reshape((2, 3, 3))
        cubes = self.cubes.extract(self.gbl)
        cubes[0].data = data_snow
        cubes[1].data = data_rain
        cubes[2].data = data_cloud
        cubes[3].data = data_cld_low
        cubes[4].data = data_vis
        result = plugin.process(cubes)
        self.assertArrayEqual(result.data, self.expected_wxcode_alternate)
Ejemplo n.º 3
0
 def test_basic_global(self):
     """Test process returns a wxcode cube with right values for global. """
     plugin = WeatherSymbols(wxtree="global")
     cubes = self.cubes.extract(self.gbl)
     result = plugin.process(cubes)
     self.assertArrayAndMaskEqual(result.data,
                                  self.expected_wxcode_no_lightning)
Ejemplo n.º 4
0
 def test_no_lightning(self):
     """Test process returns right values if no lightning. """
     plugin = WeatherSymbols()
     cubes = self.cubes.extract(self.uk_no_lightning)
     result = plugin.process(cubes)
     self.assertArrayAndMaskEqual(result.data,
                                  self.expected_wxcode_no_lightning)
Ejemplo n.º 5
0
    def test_sleet(self):
        """Test process returns the sleet weather code."""
        plugin = WeatherSymbols()
        data_snow = np.zeros_like(self.cubes[0].data)
        data_sleet = np.ones_like(self.cubes[0].data)
        data_rain = np.zeros_like(self.cubes[0].data)
        # pylint: disable=no-member
        data_precip = np.maximum.reduce([data_snow, data_sleet, data_rain])
        data_precipv = np.ones_like(self.cubes[0].data)
        data_cloud = np.ones_like(self.cubes[4].data)
        data_cld_low = np.ones_like(self.cubes[5].data)
        data_vis = np.zeros_like(self.cubes[6].data)
        data_lightning = np.zeros_like(self.cubes[7].data)
        expected = np.ones_like(self.expected_wxcode_alternate) * 18

        cubes = self.cubes
        cubes[0].data = data_snow
        cubes[1].data = data_sleet
        cubes[2].data = data_rain
        cubes[3].data = data_precipv
        cubes[4].data = data_cloud
        cubes[5].data = data_cld_low
        cubes[6].data = data_vis
        cubes[7].data = data_lightning
        cubes[8].data = data_precip
        result = plugin.process(cubes)
        self.assertArrayEqual(result.data, expected)
Ejemplo n.º 6
0
    def test_weather_data_global(self):
        """Test process returns the right weather values global part2 """
        plugin = WeatherSymbols(wxtree='global')

        data_snow = np.array([
            0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.1, 0.0, 0.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
            1.0
        ]).reshape(3, 1, 3, 3)
        data_rain = np.array([
            1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
            0.0
        ]).reshape(3, 1, 3, 3)
        data_cloud = np.array([
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
            0.0, 1.0, 0.0, 1.0, 1.0
        ]).reshape(2, 1, 3, 3)
        data_cld_low = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                 0.0]).reshape(1, 1, 3, 3)
        data_vis = np.array([
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0
        ]).reshape(2, 1, 3, 3)
        cubes = set_up_wxcubes_global()
        cubes[0].data = data_snow
        cubes[1].data = data_rain
        cubes[2].data = data_cloud
        cubes[3].data = data_cld_low
        cubes[4].data = data_vis
        result = plugin.process(cubes)
        expected_wxcode = np.array([14, 15, 17, 18, 23, 24, 26, 27,
                                    27]).reshape(1, 3, 3)
        self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 7
0
 def test_basic(self):
     """Test process returns a weather code cube with right values and type.
     """
     plugin = WeatherSymbols()
     result = plugin.process(self.cubes)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertArrayEqual(result.attributes["weather_code"], self.wxcode)
     self.assertEqual(result.attributes["weather_code_meaning"], self.wxmeaning)
     self.assertArrayEqual(result.data, self.expected_wxcode)
     self.assertEqual(result.dtype, np.int32)
Ejemplo n.º 8
0
 def test_day_night(self):
     """Test process returns the right values for night. """
     plugin = WeatherSymbols()
     for i, cube in enumerate(self.cubes):
         self.cubes[i].coord('time').points = (cube.coord('time').points +
                                               11.5)
     result = plugin.process(self.cubes)
     expected_wxcode = np.array([0, 2, 5, 6, 7, 8, 9, 11,
                                 12]).reshape(1, 3, 3)
     self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 9
0
    def test_weather_data_global(self):
        """Test process returns the right weather values global part2 """
        plugin = WeatherSymbols(wxtree="global")

        data_snow = np.array(
            [
                [[0.0, 0.0, 0.0], [0.0, 1.0, 1.0], [1.0, 1.0, 0.1]],
                [[0.0, 0.0, 0.0], [0.0, 1.0, 1.0], [1.0, 1.0, 0.0]],
                [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]],
            ],
            dtype=np.float32,
        )
        data_sleet = np.array(
            [
                [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
            ],
            dtype=np.float32,
        )
        data_rain = np.array(
            [
                [[1.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                [[1.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                [[1.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
            ],
            dtype=np.float32,
        )
        data_cloud = np.array(
            [
                [[0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]],
                [[0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]],
            ],
            dtype=np.float32,
        )
        data_cld_low = np.zeros((3, 3), dtype=np.float32)
        data_vis = np.zeros((2, 3, 3), dtype=np.float32)
        data_precip = np.max(np.array([data_snow, data_sleet, data_rain]),
                             axis=0)
        data_convective_ratio = np.array(
            [[1.0, 0.0, 1.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0]],
            dtype=np.float32,
        )
        cubes = self.cubes.extract(self.gbl)
        cubes[0].data = data_snow
        cubes[1].data = data_sleet
        cubes[2].data = data_rain
        cubes[3].data = data_cloud
        cubes[4].data = data_cld_low
        cubes[5].data = data_vis
        cubes[6].data = data_precip
        cubes[7].data = data_convective_ratio
        result = plugin.process(cubes)
        self.assertArrayAndMaskEqual(result.data,
                                     self.expected_wxcode_alternate)
Ejemplo n.º 10
0
 def test_lightning(self):
     """Test process returns right values if all lightning. """
     plugin = WeatherSymbols()
     data_lightning = np.ones((1, 3, 3))
     cubes = self.cubes
     cubes[7].data = data_lightning
     result = plugin.process(self.cubes)
     expected_wxcode = np.ones((3, 3)) * 29
     expected_wxcode[1, 1:] = 30
     expected_wxcode[2, 2] = 30
     self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 11
0
 def test_no_lightning(self):
     """Test process returns right values if no lightning. """
     plugin = WeatherSymbols()
     result = plugin.process(self.cubes_no_lightning)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertArrayEqual(result.attributes['weather_code'], self.wxcode)
     self.assertEqual(result.attributes['weather_code_meaning'],
                      self.wxmeaning)
     expected_wxcode = np.array([1, 3, 5, 6, 7, 8, 10, 11,
                                 12]).reshape(1, 3, 3)
     self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 12
0
    def test_weather_data(self):
        """Test process returns the right weather values with a different
        set of data to walk the tree differently."""
        plugin = WeatherSymbols()
        data_snow = np.array([[[0.0, 0.0, 1.0], [1.0, 1.0, 1.0],
                               [1.0, 1.0, 0.1]],
                              [[0.0, 0.0, 0.0], [0.0, 1.0, 1.0],
                               [1.0, 1.0, 0.0]],
                              [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
                               [1.0, 1.0, 0.0]]])
        data_sleet = np.array([[[0.0, 0.0, 1.0], [1.0, 0.0, 0.0],
                                [0.0, 0.0, 0.0]],
                               [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0],
                                [0.0, 0.0, 0.0]],
                               [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0],
                                [0.0, 0.0, 0.0]]])
        data_rain = np.array([[[1.0, 1.0, 1.0], [1.0, 0.0, 0.0],
                               [0.0, 0.0, 0.0]],
                              [[1.0, 1.0, 0.0], [0.0, 0.0, 0.0],
                               [0.0, 0.0, 0.0]],
                              [[1.0, 1.0, 0.0], [0.0, 0.0, 0.0],
                               [0.0, 0.0, 0.0]]])
        # pylint: disable=no-member
        data_precip = np.maximum.reduce([data_snow, data_sleet, data_rain])
        data_precipv = np.array([
            1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
            1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
            1.0
        ]).reshape((3, 3, 3))
        data_cloud = np.array([
            0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
            0.0, 1.0, 0.0, 1.0, 1.0
        ]).reshape((2, 3, 3))
        data_cld_low = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                 0.0]).reshape((1, 3, 3))
        data_vis = np.array([
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0
        ]).reshape((2, 3, 3))
        data_lightning = np.zeros((1, 3, 3))

        cubes = self.cubes
        cubes[0].data = data_snow
        cubes[1].data = data_sleet
        cubes[2].data = data_rain
        cubes[3].data = data_precipv
        cubes[4].data = data_cloud
        cubes[5].data = data_cld_low
        cubes[6].data = data_vis
        cubes[7].data = data_lightning
        cubes[8].data = data_precip
        result = plugin.process(cubes)
        self.assertArrayEqual(result.data, self.expected_wxcode_alternate)
Ejemplo n.º 13
0
 def test_basic_global(self):
     """Test process returns a wxcode cube with right values for global. """
     plugin = WeatherSymbols(wxtree='global')
     cubes = set_up_wxcubes_global()
     result = plugin.process(cubes)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertArrayEqual(result.attributes['weather_code'], self.wxcode)
     self.assertEqual(result.attributes['weather_code_meaning'],
                      self.wxmeaning)
     expected_wxcode = np.array([1, 3, 5, 6, 7, 8, 10, 11,
                                 12]).reshape(1, 3, 3)
     self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 14
0
 def test_masked_precip(self):
     """Test process returns right values when precipitation data are fully masked
     (e.g. nowcast-only). The only possible non-masked result is a lightning code as
     these do not include precipitation in any of their decision routes."""
     plugin = WeatherSymbols()
     data_precip = np.ma.masked_all_like(self.cubes[8].data)
     cubes = self.cubes
     cubes[8].data = data_precip
     result = plugin.process(self.cubes)
     expected_wxcode = np.ma.masked_all_like(self.expected_wxcode)
     expected_wxcode[0, 1] = self.expected_wxcode[0, 1]
     self.assertArrayAndMaskEqual(result.data, expected_wxcode)
Ejemplo n.º 15
0
 def test_lightning(self):
     """Test process returns right values if all lightning. """
     plugin = WeatherSymbols()
     data_lightning = np.ones((1, 1, 3, 3))
     cubes = self.cubes
     cubes[7].data = data_lightning
     result = plugin.process(self.cubes)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertArrayEqual(result.attributes['weather_code'], self.wxcode)
     self.assertEqual(result.attributes['weather_code_meaning'],
                      self.wxmeaning)
     expected_wxcode = np.ones((1, 3, 3)) * 29
     expected_wxcode[0, 1, 1:] = 30
     expected_wxcode[0, 2, 2] = 30
     self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 16
0
 def test_weather_data(self):
     """Test process returns the right weather values.part2 """
     plugin = WeatherSymbols()
     data_snow = np.array([
         0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.1, 0.0, 0.0, 1.0, 1.0,
         1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
         0.0
     ]).reshape(3, 1, 3, 3)
     data_rain = np.array([
         1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
         0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
         0.0
     ]).reshape(3, 1, 3, 3)
     data_snowv = np.array([
         0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
         1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
         1.0
     ]).reshape(3, 1, 3, 3)
     data_rainv = np.array([
         1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
         0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
         0.0
     ]).reshape(3, 1, 3, 3)
     data_cloud = np.array([
         0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
         0.0, 1.0, 0.0, 1.0, 1.0
     ]).reshape(2, 1, 3, 3)
     data_cld_1000ft = np.array(
         [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).reshape(1, 1, 3, 3)
     data_vis = np.array([
         0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
         0.0, 0.0, 0.0, 0.0, 0.0
     ]).reshape(2, 1, 3, 3)
     cubes = self.cubes
     cubes[0].data = data_snow
     cubes[1].data = data_rain
     cubes[2].data = data_snowv
     cubes[3].data = data_rainv
     cubes[4].data = data_cloud
     cubes[5].data = data_cld_1000ft
     cubes[6].data = data_vis
     result = plugin.process(cubes)
     expected_wxcode = np.array([14, 15, 17, 18, 23, 24, 26, 27,
                                 27]).reshape(1, 3, 3)
     self.assertArrayEqual(result.data, expected_wxcode)
Ejemplo n.º 17
0
    def test_weather_data_global(self):
        """Test process returns the right weather values global part2 """
        plugin = WeatherSymbols(wxtree="global")

        data_snow = np.array(
            [
                [[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.1]],
                [[0.0, 0.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]],
                [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 1.0]],
            ],
            dtype=np.float32,
        )
        data_rain = np.array(
            [
                [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                [[1.0, 1.0, 1.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
            ],
            dtype=np.float32,
        )
        data_cloud = np.array(
            [
                [[0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]],
                [[0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0]],
            ],
            dtype=np.float32,
        )
        data_cld_low = np.zeros((1, 3, 3), dtype=np.float32)
        data_vis = np.zeros((2, 3, 3), dtype=np.float32)
        cubes = self.cubes.extract(self.gbl)
        cubes[0].data = data_snow
        cubes[1].data = data_rain
        cubes[2].data = data_cloud
        cubes[3].data = data_cld_low
        cubes[4].data = data_vis
        result = plugin.process(cubes)
        self.assertArrayEqual(result.data, self.expected_wxcode_alternate)