diff --git a/lib/iris/plot.py b/lib/iris/plot.py index f0dfccd8c5..e3193e96a4 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -317,13 +317,14 @@ def _check_bounds_contiguity_and_mask(coord, data, atol=None): elif coord.ndim == 2: if atol: - args = {'atol': atol} + kwargs = {'atol': atol} else: - args = {} - contiguous, diffs = coord._discontiguity_in_bounds(*args) - diffs_along_x, diffs_along_y = diffs + kwargs = {} + contiguous, diffs = coord._discontiguity_in_bounds(**kwargs) if not contiguous and data_is_masked: + diffs_along_x, diffs_along_y = diffs + # Check along both dimensions. not_masked_at_discontiguity_along_x = np.any( np.logical_and(mask_invert[:, :-1], diffs_along_x)) diff --git a/lib/iris/tests/unit/coords/test_Coord.py b/lib/iris/tests/unit/coords/test_Coord.py index 58fc3e1f9e..8cf79caad3 100644 --- a/lib/iris/tests/unit/coords/test_Coord.py +++ b/lib/iris/tests/unit/coords/test_Coord.py @@ -504,6 +504,16 @@ def test_2d_discontiguous_along_x_and_y(self): self.assertArrayEqual(diffs_along_x, exp_x_diffs) self.assertArrayEqual(diffs_along_y, exp_y_diffs) + def test_2d_contiguous_along_x_atol(self): + coord = AuxCoord(self.points_3by3[:, ::2], + bounds=self.lon_bounds_3by3[:, ::2, :]) + # Set a high atol that allows small discontiguities. + contiguous, diffs = coord._discontiguity_in_bounds(atol=2) + diffs_along_x, diffs_along_y = diffs + self.assertTrue(contiguous) + self.assertArrayEqual(diffs_along_x, np.array([2, 2, 2]).reshape(3, 1)) + self.assertTrue(not diffs_along_y.any()) + def test_2d_one_cell(self): # Test a 2D coord with a single cell, where the coord has shape (1, 1). coord = AuxCoord(self.points_3by3[:1, :1], diff --git a/lib/iris/tests/unit/plot/test__check_bounds_contiguity_and_mask.py b/lib/iris/tests/unit/plot/test__check_bounds_contiguity_and_mask.py index b067b3f387..225aa2890e 100644 --- a/lib/iris/tests/unit/plot/test__check_bounds_contiguity_and_mask.py +++ b/lib/iris/tests/unit/plot/test__check_bounds_contiguity_and_mask.py @@ -24,6 +24,8 @@ # importing anything else. import iris.tests as tests +import mock + import numpy as np import numpy.ma as ma @@ -72,6 +74,19 @@ def test_2d_contiguous(self): iplt._check_bounds_contiguity_and_mask(cube.coord('longitude'), cube.data) + def test_2d_contiguous_atol(self): + # Check the atol is passed correctly. + cube = sample_2d_latlons() + with mock.patch('iris.coords.Coord._discontiguity_in_bounds' + ) as discontiguity_check: + # Discontiguity returns two objects that are unpacked in + # `_check_bounds_contiguity_and_mask`. + discontiguity_check.return_value = [True, None] + iplt._check_bounds_contiguity_and_mask(cube.coord('longitude'), + cube.data, + atol=1e-3) + discontiguity_check.assert_called_with(atol=1e-3) + def test_2d_discontigous_masked(self): # Test a 2D coordinate which is discontiguous but masked at # discontiguities.