def test_1d_coord_no_bounds_warning(self): coord = DimCoord([0, 1, 2], standard_name='latitude') msg = "Coordinate 'latitude' is not bounded, guessing contiguous " \ "bounds." with warnings.catch_warnings(): # Cause all warnings to raise Exceptions warnings.simplefilter("error") with self.assertRaisesRegexp(Warning, msg): coord.contiguous_bounds()
def test_1d_coord_no_bounds_warning(self): coord = DimCoord([0, 1, 2], standard_name="latitude") msg = ("Coordinate 'latitude' is not bounded, guessing contiguous " "bounds.") with warnings.catch_warnings(): # Cause all warnings to raise Exceptions warnings.simplefilter("error") with self.assertRaisesRegex(Warning, msg): coord.contiguous_bounds()
def test_longitude_0_360_one_degree(self): x = np.arange(0.5, 360.5, 1) y = np.array([50.5, 51.5]) values = np.arange(len(y) * len(x)).reshape((len(y), len(x))) latitude = DimCoord(y, standard_name='latitude', units='degrees') longitude = DimCoord(x, standard_name='longitude', units='degrees') data = make_from_cube(Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)])) out_values, out_x, out_y= Generic2DPlot._cube_manipulation(data, longitude.contiguous_bounds(), latitude.contiguous_bounds()) x_bounds = np.arange(0, 361, 1) y_bounds = np.array([50, 51, 52]) assert_arrays_equal(out_x, x_bounds) assert_arrays_equal(out_y, y_bounds)
def test_longitude_0_360_one_degree(self): x = np.arange(0.5, 360.5, 1) y = np.array([50.5, 51.5]) values = np.arange(len(y) * len(x)).reshape((len(y), len(x))) latitude = DimCoord(y, standard_name='latitude', units='degrees') longitude = DimCoord(x, standard_name='longitude', units='degrees') data = make_from_cube( Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)])) out_values, out_x, out_y = Generic2DPlot._cube_manipulation( data, longitude.contiguous_bounds(), latitude.contiguous_bounds()) x_bounds = np.arange(0, 361, 1) y_bounds = np.array([50, 51, 52]) assert_arrays_equal(out_x, x_bounds) assert_arrays_equal(out_y, y_bounds)
def test_1d_coord_discontiguous(self): coord = DimCoord([2, 4, 6], standard_name='latitude', bounds=[[1, 3], [4, 5], [5, 7]]) expected = np.array([1, 4, 5, 7]) result = coord.contiguous_bounds() self.assertArrayEqual(result, expected)
def test_lat_lon_decreasing_no_bounds(self): x = np.array([0.5, -0.5]) y = np.array([51.5, 50.5]) values = np.array([[1, 2], [3, 4]]) latitude = DimCoord(y, standard_name='latitude', units='degrees') longitude = DimCoord(x, standard_name='longitude', units='degrees') data = make_from_cube(Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)])) out_values, out_x, out_y= Generic2DPlot._cube_manipulation(data, longitude.contiguous_bounds(), latitude.contiguous_bounds()) expected_x = np.array([1, 0, -1]) expected_y = np.array([52, 51, 50]) expected_v = np.array([[1, 2], [3, 4]]) assert_arrays_equal(out_x, expected_x) assert_arrays_equal(out_y, expected_y) assert_arrays_equal(out_values, expected_v)
def test_lat_lon_increasing_no_bounds(self): x = np.array([0.5, 1.5]) y = np.array([50.5, 51.5]) values = np.array([[1, 2], [3, 4]]) latitude = DimCoord(y, standard_name='latitude', units='degrees') longitude = DimCoord(x, standard_name='longitude', units='degrees') data = make_from_cube( Cube(values, dim_coords_and_dims=[(latitude, 0), (longitude, 1)])) out_values, out_x, out_y = Generic2DPlot._cube_manipulation( data, longitude.contiguous_bounds(), latitude.contiguous_bounds()) expected_x = np.array([0, 1, 2]) expected_y = np.array([50, 51, 52]) expected_v = np.array([[1, 2], [3, 4]]) assert_arrays_equal(out_x, expected_x) assert_arrays_equal(out_y, expected_y) assert_arrays_equal(out_values, expected_v)
def test__sanity_check_bounds_call(self): coord = DimCoord([5, 15, 25], bounds=[[0, 10], [10, 20], [20, 30]]) with mock.patch( "iris.coords.Coord._sanity_check_bounds") as bounds_check: coord.contiguous_bounds() bounds_check.assert_called_once()
def test__sanity_check_bounds_call(self): coord = DimCoord([5, 15, 25], bounds=[[0, 10], [10, 20], [20, 30]]) with mock.patch('iris.coords.Coord._sanity_check_bounds' ) as bounds_check: coord.contiguous_bounds() bounds_check.assert_called_once()