Esempio n. 1
0
 def test_coords_update_fail_bounds(self):
     """Test _update_coord fails if shape of new bounds do not match. """
     cube = create_cube_with_threshold(threshold_values=self.thresholds)
     changes = {'bounds': [0.1, 2.0]}
     msg = "The shape of the bounds array should be"
     with self.assertRaisesRegex(ValueError, msg):
         _update_coord(cube, self.coord_name, changes)
Esempio n. 2
0
 def test_alternative_incompatible_changes_requested(self):
     """Test that _update_coord raises an exception if 'bounds' and 'units'
     are requested to be changed."""
     cube = create_cube_with_threshold()
     changes = {'bounds': [0.1, 2.0], 'units': 'mm/hr'}
     msg = "When updating a coordinate"
     with self.assertRaisesRegex(ValueError, msg):
         _update_coord(cube, self.coord_name, changes)
Esempio n. 3
0
 def test_warning_messages_with_update(self, warning_list=None):
     """Test warning message is raised correctly when updating coord. """
     changes = {'points': [2.0], 'bounds': [0.1, 2.0]}
     warning_msg = "Updated coordinate"
     _update_coord(self.cube, self.coord_name, changes, warnings_on=True)
     self.assertTrue(
         any(item.category == UserWarning for item in warning_list))
     self.assertTrue(any(warning_msg in str(item) for item in warning_list))
Esempio n. 4
0
 def test_coords_update_fails_bounds_differ(self):
     """Test that _update_coord fails if bounds differ."""
     cube = create_cube_with_threshold(threshold_values=self.thresholds)
     cube.coord(self.coord_name).guess_bounds()
     changes = {'bounds': [[0.1, 2.0], [2.0, 3.0], [3.0, 4.0]]}
     msg = "Mismatch in bounds in existing coord and updated metadata"
     with self.assertRaisesRegex(ValueError, msg):
         _update_coord(cube, self.coord_name, changes)
Esempio n. 5
0
 def test_warning_messages_with_delete(self, warning_list=None):
     """Test warning message is raised correctly when deleting coord. """
     changes = 'delete'
     warning_msg = "Deleted coordinate"
     _update_coord(self.cube, self.coord_name, changes, warnings_on=True)
     self.assertTrue(
         any(item.category == UserWarning for item in warning_list))
     self.assertTrue(any(warning_msg in str(item) for item in warning_list))
Esempio n. 6
0
 def test__update_attributes(self):
     """Test update attributes associated with a coordinate."""
     cube = create_cube_with_threshold()
     changes = {'attributes': {'spp__relative_to_threshold': "below"}}
     result = _update_coord(cube, self.coord_name, changes)
     self.assertIsInstance(result, Cube)
     self.assertEqual(
         result.coord(self.coord_name).attributes, changes["attributes"])
Esempio n. 7
0
 def test_coords_deleted(self):
     """Test _update_coord deletes coordinate. """
     changes = 'delete'
     result = _update_coord(self.cube, self.coord_name, changes)
     found_key = self.coord_name in [
         coord.name() for coord in result.coords()
     ]
     self.assertArrayEqual(found_key, False)
Esempio n. 8
0
 def test_coords_update_bounds_succeed(self):
     """Test that _update_coord succeeds if bounds do match """
     cube = create_cube_with_threshold(threshold_values=self.thresholds)
     cube.coord(self.coord_name).guess_bounds()
     changes = {'bounds': [[0.1, 2.0], [2.0, 3.0]]}
     result = _update_coord(cube, self.coord_name, changes)
     self.assertArrayEqual(
         result.coord(self.coord_name).bounds,
         np.array([[0.1, 2.0], [2.0, 3.0]], dtype=np.float32))
Esempio n. 9
0
 def test_convert_units(self):
     """Test _update_coord returns a Cube and converts units correctly. """
     cube = create_cube_with_threshold()
     changes = {'units': 'km s-1'}
     result = _update_coord(cube, self.coord_name, changes)
     self.assertIsInstance(result, Cube)
     self.assertEqual(
         result.coord(self.coord_name).points,
         np.array([0.001], dtype=np.float32))
     self.assertEqual(str(result.coord(self.coord_name).units), 'km s-1')
Esempio n. 10
0
 def test_basic(self):
     """Test _update_coord returns a Cube and updates coord correctly and
     does not modify the input cube. """
     original_cube = self.cube.copy()
     changes = {'points': [2.0], 'bounds': [0.1, 2.0]}
     result = _update_coord(self.cube, self.coord_name, changes)
     self.assertIsInstance(result, Cube)
     self.assertArrayAlmostEqual(
         result.coord(self.coord_name).points,
         np.array([2.0], dtype=np.float32))
     self.assertArrayAlmostEqual(
         result.coord(self.coord_name).bounds,
         np.array([[0.1, 2.0]], dtype=np.float32))
     self.assertEqual(self.cube, original_cube)
Esempio n. 11
0
 def test_coords_update_fail_points(self):
     """Test that _update_coord fails if points do not match. """
     changes = {'points': [2.0, 3.0]}
     msg = "Mismatch in points in existing coord and updated metadata"
     with self.assertRaisesRegex(ValueError, msg):
         _update_coord(self.cube, self.coord_name, changes)
Esempio n. 12
0
 def test_coords_deleted_fails(self):
     """Test _update_coord fails to delete coord of len > 1. """
     changes = 'delete'
     msg = "Can only remove a coordinate of length 1"
     with self.assertRaisesRegex(ValueError, msg):
         _update_coord(self.cube, 'time', changes)