示例#1
0
 def test_fails_coord_not_in_cube(self):
     """Test it raises a Value Error if coord not in the cube."""
     coord = "notset"
     plugin = WeightedBlend(coord)
     msg = ('Expected to find exactly 1  coordinate, but found none.')
     with self.assertRaisesRegexp(CoordinateNotFoundError, msg):
         plugin.process(self.cube)
示例#2
0
 def test_coord_adjust_set(self):
     """Test it works with coord adjust set."""
     coord = "time"
     coord_adjust = example_coord_adjust
     plugin = WeightedBlend(coord, coord_adjust)
     result = plugin.process(self.cube)
     self.assertAlmostEquals(result.coord(coord).points, [402193.5])
示例#3
0
 def test_weights_equal_array(self):
     """Test it works with weights set to array (0.8, 0.2)."""
     coord = "time"
     plugin = WeightedBlend(coord)
     weights = np.array([0.8, 0.2])
     result = plugin.process(self.cube, weights)
     expected_result_array = np.ones((2, 2)) * 1.2
     self.assertArrayAlmostEqual(result.data, expected_result_array)
示例#4
0
 def test_weights_equal_list(self):
     """Test it work with weights set to list [0.2, 0.8]."""
     coord = "time"
     plugin = WeightedBlend(coord)
     weights = [0.2, 0.8]
     result = plugin.process(self.cube, weights)
     expected_result_array = np.ones((2, 2)) * 1.8
     self.assertArrayAlmostEqual(result.data, expected_result_array)
示例#5
0
 def test_weights_equal_none(self):
     """Test it works with weights set to None."""
     coord = "time"
     plugin = WeightedBlend(coord)
     weights = None
     result = plugin.process(self.cube, weights)
     expected_result_array = np.ones((2, 2)) * 1.5
     self.assertArrayAlmostEqual(result.data, expected_result_array)
示例#6
0
 def test_fails_input_not_a_cube(self):
     """Test it raises a Value Error if not supplied with a cube."""
     coord = "time"
     plugin = WeightedBlend(coord)
     notacube = 0.0
     msg = ('The first argument must be an instance of ' + 'iris.cube.Cube')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(notacube)
示例#7
0
 def test_percentiles_weights_equal_none(self):
     """Test it works for percentiles with weights set to None."""
     coord = "time"
     plugin = WeightedBlend(coord)
     weights = None
     perc_cube = percentile_cube()
     result = plugin.process(perc_cube, weights)
     expected_result_array = np.reshape(BLENDED_PERCENTILE_DATA1, (6, 2, 2))
     self.assertArrayAlmostEqual(result.data, expected_result_array)
示例#8
0
 def test_fails_weights_shape(self):
     """Test it raises a Value Error if weights shape does not match
        coord shape."""
     coord = "time"
     plugin = WeightedBlend(coord)
     weights = [0.1, 0.2, 0.7]
     msg = ('The weights array must match the shape ' +
            'of the coordinate in the input cube')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(self.cube, weights)
示例#9
0
 def test_fails_more_than_one_perc_coord(self):
     """Test it raises a Value Error if more than one percentile coord."""
     coord = "time"
     plugin = WeightedBlend(coord)
     new_cube = percentile_cube()
     new_cube.add_aux_coord(
         AuxCoord([10.0], long_name="percentile_over_dummy"))
     msg = ('There should only be one percentile coord ' 'on the cube.')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(new_cube)
示例#10
0
 def test_fails_perc_coord_not_dim(self):
     """Test it raises a Value Error if not percentile coord not a dim."""
     coord = "time"
     plugin = WeightedBlend(coord)
     new_cube = self.cube.copy()
     new_cube.add_aux_coord(
         AuxCoord([10.0], long_name="percentile_over_time"))
     msg = ('The percentile coord must be a dimension ' 'of the cube.')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(new_cube)
示例#11
0
 def test_fails_only_one_percentile_value(self):
     """Test it raises a Value Error if there is only one percentile."""
     coord = "time"
     plugin = WeightedBlend(coord)
     new_cube = Cube([[0.0]])
     new_cube.add_dim_coord(
         DimCoord([10.0], long_name="percentile_over_time"), 0)
     new_cube.add_dim_coord(DimCoord([10.0], long_name="time"), 1)
     msg = ('Percentile coordinate does not have enough points'
            ' in order to blend. Must have at least 2 percentiles.')
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(new_cube)
示例#12
0
 def test_scalar_coord(self):
     """Test it works on scalar coordinate
        and check that a warning has been raised
        if the dimension that you want to blend on
        is a scalar coordinate.
     """
     coord = "dummy_scalar_coord"
     plugin = WeightedBlend(coord)
     weights = np.array([1.0])
     with warnings.catch_warnings(record=True) as warning_list:
         warnings.simplefilter("always")
         result = plugin.process(self.cube_with_scalar, weights)
         self.assertTrue(
             any(item.category == UserWarning for item in warning_list))
         warning_msg = "Trying to blend across a scalar coordinate"
         self.assertTrue(
             any(warning_msg in str(item) for item in warning_list))
         self.assertArrayAlmostEqual(result.data, self.cube.data)
示例#13
0
 def test_basic(self):
     """Test that the plugin returns an iris.cube.Cube."""
     coord = "time"
     plugin = WeightedBlend(coord)
     result = plugin.process(self.cube)
     self.assertIsInstance(result, Cube)
示例#14
0
 def test_basic(self):
     """Test that the __repr__ returns the expected string."""
     result = str(WeightedBlend('time'))
     msg = '<WeightedBlend: coord = time>'
     self.assertEqual(result, msg)