Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
15 changes: 15 additions & 0 deletions lib/iris/tests/unit/plot/test__check_bounds_contiguity_and_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# importing anything else.
import iris.tests as tests

import mock

import numpy as np
import numpy.ma as ma

Expand Down Expand Up @@ -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.
Expand Down