Esempio n. 1
0
 def test_basic(self):
     """Test that the function returns a Cube and Coord."""
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     result, perc_coord = (plugin.extract_percentile_data(
         self.cube_wg, self.wg_perc, "wind_speed_of_gust"))
     self.assertIsInstance(result, Cube)
     self.assertIsInstance(perc_coord, iris.coords.Coord)
Esempio n. 2
0
 def test_fails_if_req_percentile_not_in_cube(self):
     """Test it raises a Value Error if req_perc not in cube."""
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     msg = ('Could not find required percentile')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.extract_percentile_data(self.cube_wg, 20.0,
                                        "wind_speed_of_gust")
Esempio n. 3
0
 def test_updated_metadata(self):
     """Test that the metadata is set as expected """
     plugin = WindGustDiagnostic(50.0, 80.0)
     result = plugin.update_metadata_after_max(self.cube, self.perc_coord)
     msg = 'Expected to find exactly 1  coordinate, but found none.'
     with self.assertRaisesRegexp(CoordinateNotFoundError, msg):
         result.coord(self.perc_coord)
Esempio n. 4
0
 def test_returns_correct_cube_and_coord(self):
     """Test it returns the correct Cube and Coord."""
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     result, perc_coord = (plugin.extract_percentile_data(
         self.cube_wg, self.wg_perc, "wind_speed_of_gust"))
     self.assertEqual(perc_coord.name(), "percentile_over_nbhood")
     self.assertEqual(
         result.coord("percentile_over_nbhood").points, [self.wg_perc])
 def test_raises_error_points_mismatch_and_no_bounds(self):
     """Test raises Value Error if points mismatch and no bounds """
     cube_wg = self.cube_wg
     cube_wg.coord('time').points = [402192.5, 402194.5]
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     msg = ('Could not match time coordinate')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(cube_wg, self.cube_ws)
 def test_raises_error_points_mismatch_and_invalid_bounds(self):
     """Test raises Value Error if points mismatch and bounds are invalid"""
     cube_wg = self.cube_wg
     cube_wg.coord('time').points = [402192.0, 402193.0]
     cube_wg.coord('time').bounds = [[402191.5], [402193.5]]
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     msg = ('Could not match time coordinate')
     with self.assertRaisesRegex(ValueError, msg):
         plugin.process(cube_wg, self.cube_ws)
Esempio n. 7
0
 def test_fails_if_data_is_not_cube(self):
     """Test it raises a Type Error if cube is not a cube."""
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     msg = ('Expecting wind_speed_of_gust data to be an instance of '
            'iris.cube.Cube but is'
            ' {0:s}.'.format(type(self.wg_perc)))
     with self.assertRaisesRegexp(TypeError, msg):
         plugin.extract_percentile_data(self.wg_perc, self.wg_perc,
                                        "wind_speed_of_gust")
Esempio n. 8
0
 def test_metadata(self):
     """Test that the metadata is set as expected """
     plugin = WindGustDiagnostic(50.0, 80.0)
     result = plugin.add_metadata(self.cube_wg)
     self.assertEqual(result.standard_name, "wind_speed_of_gust")
     self.assertEqual(result.long_name, "wind_gust_diagnostic")
     msg = ('<WindGustDiagnostic: wind-gust perc=50.0, '
            'wind-speed perc=80.0>')
     self.assertEqual(result.attributes['wind_gust_diagnostic'], msg)
Esempio n. 9
0
 def test_returns_wind_gust_diagnostic(self):
     """Test that the plugin returns a Cube. """
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     result = plugin.process(self.cube_wg, self.cube_ws)
     expected_data = np.zeros((2, 2, 2))
     expected_data[0, :, :] = 3.0
     expected_data[1, :, :] = 2.0
     self.assertArrayAlmostEqual(result.data, expected_data)
     self.assertEqual(result.attributes['wind_gust_diagnostic'],
                      'Typical gusts')
    def test_no_raises_error_if_ws_point_in_bounds(self):
        """Test raises no Value Error if wind-speed point in bounds """
        cube_wg = self.cube_wg
        cube_wg.coord('time').points = [402192.0, 402193.0]
        cube_wg.coord('time').bounds = [[402191.5, 402192.5],
                                        [402192.5, 402193.5]]

        plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
        result = plugin.process(cube_wg, self.cube_ws)
        self.assertIsInstance(result, Cube)
 def test_raises_error_for_no_time_coord(self):
     """Test raises Value Error if cubes have no time coordinate """
     cube_wg = self.cube_wg[:, 0, ::]
     cube_ws = self.cube_ws[:, 0, ::]
     cube_wg.remove_coord('time')
     cube_wg = iris.util.squeeze(cube_wg)
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     msg = ('Could not match time coordinate')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(cube_wg, cube_ws)
 def test_warning_if_standard_names_do_not_match(self, warning_list=None):
     """Test it raises a warning if standard names do not match."""
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     warning_msg = ('Warning mismatching name for data expecting')
     result, perc_coord = (plugin.extract_percentile_data(
         self.cube_wg, self.wg_perc, "wind_speed"))
     self.assertTrue(
         any(item.category == UserWarning for item in warning_list))
     self.assertTrue(any(warning_msg in str(item) for item in warning_list))
     self.assertIsInstance(result, Cube)
     self.assertIsInstance(perc_coord, iris.coords.Coord)
Esempio n. 13
0
 def test_raises_error_for_mismatching_perc_coords(self):
     """Test raises an error for mismatching perc coords. """
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     data_wg = np.zeros((1, 2, 2, 2))
     data_wg[0, 0, :, :] = 3.0
     data_wg[0, 1, :, :] = 1.5
     gust = "wind_speed_of_gust"
     cube_wg = (create_cube_with_percentile_coord(
         data=data_wg,
         perc_values=[self.wg_perc],
         standard_name=gust,
         perc_name='percentile_dummy'))
     msg = ('Percentile coord of wind-gust data'
            'does not match coord of wind-speed data')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(cube_wg, self.cube_ws)
Esempio n. 14
0
 def test_basic(self):
     """Test that the __repr__ returns the expected string."""
     result = str(WindGustDiagnostic(50.0, 95.0))
     msg = ('<WindGustDiagnostic: wind-gust perc=50.0, '
            'wind-speed perc=95.0>')
     self.assertEqual(result, msg)
Esempio n. 15
0
 def test_basic(self):
     """Test that the __init__ sets things up correctly"""
     plugin = (WindGustDiagnostic(50.0, 95.0))
     self.assertEqual(plugin.percentile_gust, 50.0)
     self.assertEqual(plugin.percentile_windspeed, 95.0)
Esempio n. 16
0
 def test_basic(self):
     """Test that the function returns a Cube. """
     plugin = WindGustDiagnostic(50.0, 95.0)
     result = plugin.add_metadata(self.cube_wg)
     self.assertIsInstance(result, Cube)
Esempio n. 17
0
 def test_basic(self):
     """Test that the plugin returns a Cube. """
     plugin = WindGustDiagnostic(self.wg_perc, self.ws_perc)
     result = plugin.process(self.cube_wg, self.cube_ws)
     self.assertIsInstance(result, Cube)
Esempio n. 18
0
 def test_diagnostic_typical_txt(self):
     """Test that the attribute is set as expected for typical gusts"""
     plugin = WindGustDiagnostic(50.0, 95.0)
     result = plugin.add_metadata(self.cube_wg)
     msg = 'Typical gusts'
     self.assertEqual(result.attributes['wind_gust_diagnostic'], msg)
Esempio n. 19
0
 def test_diagnostic_extreme_txt(self):
     """Test that the attribute is set as expected for extreme gusts"""
     plugin = WindGustDiagnostic(95.0, 100.0)
     result = plugin.add_metadata(self.cube_wg)
     msg = 'Extreme gusts'
     self.assertEqual(result.attributes['wind_gust_diagnostic'], msg)
Esempio n. 20
0
 def test_basic(self):
     """Test that the function returns a Cube. """
     plugin = WindGustDiagnostic(50.0, 95.0)
     result = plugin.update_metadata_after_max(self.cube, self.perc_coord)
     self.assertIsInstance(result, Cube)