Skip to content

Commit 96f77d9

Browse files
authored
Merge pull request #1969 from greglucas/v0.20-pcolormesh
Backport recent master commits to v0.20.x
2 parents 4e581b0 + b940df0 commit 96f77d9

File tree

7 files changed

+77
-13
lines changed

7 files changed

+77
-13
lines changed

.github/workflows/ci-testing.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@ jobs:
2424
channels: conda-forge/label/testing,conda-forge
2525

2626
- name: Minimum packages
27-
# Only run on macos for now
27+
# Only run on Linux for now
2828
# Conda's linux packages don't grab the testing label of matplotlib causing failures due to freetype differences
29-
if: matrix.python-version == '3.7' && matrix.os == 'macos-latest'
29+
if: matrix.python-version == '3.7' && matrix.os == 'ubuntu-latest'
3030
id: minimum-packages
3131
run: |
3232
echo "PACKAGES=cython=0.28.5 matplotlib=3.1 numpy=1.18 owslib=0.17 pyproj=3.0 proj=8.0 scipy=1.2.0 shapely=1.6.4" >> $GITHUB_ENV
33-
echo "CFLAGS=-stdlib=libc++" >> $GITHUB_ENV
3433
3534
- name: Latest packages
3635
if: steps.minimum-packages.conclusion == 'skipped'
3736
run: |
38-
echo "PACKAGES=cython fiona matplotlib-base numpy pyproj pykdtree scipy shapely" >> $GITHUB_ENV
37+
echo "PACKAGES=cython fiona matplotlib-base numpy pyproj 'proj>=8' pykdtree scipy shapely" >> $GITHUB_ENV
3938
4039
- name: Coverage packages
4140
id: coverage
@@ -51,6 +50,10 @@ jobs:
5150
PACKAGES="$PACKAGES flufl.lock owslib pep8 pillow pyshp pytest"
5251
PACKAGES="$PACKAGES pytest-xdist requests setuptools_scm"
5352
PACKAGES="$PACKAGES setuptools_scm_git_archive shapely"
53+
# openssl 3.0 updated the legacy renegotiation default, which causes
54+
# failures in NASA's WMTS server. They will need to update their
55+
# server before we can use a newer openssl.
56+
PACKAGES="$PACKAGES openssl<3"
5457
conda install $PACKAGES
5558
conda info -a
5659
conda list

lib/cartopy/mpl/geoaxes.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,10 +1863,6 @@ def _wrap_quadmesh(self, collection, **kwargs):
18631863
cross the boundary of the projection.
18641864
"""
18651865
t = kwargs.get('transform', None)
1866-
if not (getattr(t, '_wrappable', False) and
1867-
getattr(self.projection, '_wrappable', False)):
1868-
# Nothing to do
1869-
return collection
18701866

18711867
# Get the quadmesh data coordinates
18721868
coords = collection._coordinates
@@ -1902,8 +1898,25 @@ def _wrap_quadmesh(self, collection, **kwargs):
19021898
np.isnan(diagonal1_lengths) |
19031899
(diagonal1_lengths > size_limit))
19041900

1905-
if not np.any(mask):
1906-
# No wrapping needed
1901+
# Update the data limits based on the corners of the mesh
1902+
# in transformed coordinates, ignoring nan values
1903+
with warnings.catch_warnings():
1904+
warnings.filterwarnings('ignore', 'All-NaN slice encountered')
1905+
# If we have all nans, that is OK and will be handled by the
1906+
# Bbox calculations later, so suppress that warning from the user
1907+
corners = ((np.nanmin(xs), np.nanmin(ys)),
1908+
(np.nanmax(xs), np.nanmax(ys)))
1909+
collection._corners = mtransforms.Bbox(corners)
1910+
self.update_datalim(collection._corners)
1911+
1912+
# We need to keep the transform/projection check after
1913+
# update_datalim to make sure we are getting the proper
1914+
# datalims on the returned collection
1915+
if (not (getattr(t, '_wrappable', False) and
1916+
getattr(self.projection, '_wrappable', False)) or
1917+
not np.any(mask)):
1918+
# If both projections are unwrappable
1919+
# or if there aren't any points to wrap
19071920
return collection
19081921

19091922
# Wrapping with gouraud shading is error-prone. We will do our best,

lib/cartopy/mpl/geocollection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ def set_clim(self, vmin=None, vmax=None):
5252

5353
# Update color limits for the rest of the cells.
5454
super().set_clim(vmin, vmax)
55+
56+
def get_datalim(self, transData):
57+
# Return the corners that were calculated in
58+
# the pcolormesh routine.
59+
return self._corners
-1.12 KB
Loading

lib/cartopy/tests/mpl/test_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@pytest.mark.filterwarnings("ignore:Downloading")
1818
@pytest.mark.natural_earth
19-
@ImageTesting(['natural_earth'])
19+
@ImageTesting(['natural_earth'], tolerance=0.97)
2020
def test_natural_earth():
2121
ax = plt.axes(projection=ccrs.PlateCarree())
2222
ax.add_feature(cfeature.LAND)

lib/cartopy/tests/mpl/test_mpl_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# This is due to a change in MPL 3.5 contour line paths changing
2121
# ever so slightly.
22-
contour_tol = 2.24
22+
contour_tol = 2.25
2323
@pytest.mark.natural_earth
2424
@ImageTesting(['global_contour_wrap'], style='mpl20',
2525
tolerance=contour_tol)
@@ -257,7 +257,7 @@ def test_cursor_values():
257257

258258

259259
@pytest.mark.natural_earth
260-
@ImageTesting(['natural_earth_interface'], tolerance=0.21)
260+
@ImageTesting(['natural_earth_interface'], tolerance=1.21)
261261
def test_axes_natural_earth_interface():
262262
rob = ccrs.Robinson()
263263

lib/cartopy/tests/mpl/test_pseudo_color.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,46 @@ def test_pcolormesh_arg_interpolation():
8484
[2, 20],
8585
[4, 20]]])
8686
np.testing.assert_array_almost_equal(expected, coll._coordinates)
87+
88+
89+
def test_pcolormesh_datalim():
90+
# Test that wrapping the coordinates still produces proper data limits
91+
x = [359, 1, 3]
92+
y = [-10, 10]
93+
94+
xs, ys = np.meshgrid(x, y)
95+
# Z with the same shape as X/Y to force the interpolation
96+
z = np.zeros(xs.shape)
97+
98+
ax = plt.subplot(2, 1, 1, projection=ccrs.PlateCarree())
99+
coll = ax.pcolormesh(xs, ys, z, shading='auto',
100+
transform=ccrs.PlateCarree())
101+
102+
coll_bbox = coll.get_datalim(ax.transData)
103+
np.testing.assert_array_equal(coll_bbox, [[-2, -20], [4, 20]])
104+
105+
# Non-wrapped coordinates
106+
x = [-80, 0, 80]
107+
y = [-10, 10]
108+
109+
xs, ys = np.meshgrid(x, y)
110+
ax = plt.subplot(2, 1, 1, projection=ccrs.PlateCarree())
111+
coll = ax.pcolormesh(xs, ys, z, shading='auto',
112+
transform=ccrs.PlateCarree())
113+
114+
coll_bbox = coll.get_datalim(ax.transData)
115+
np.testing.assert_array_equal(coll_bbox, [[-120, -20], [120, 20]])
116+
117+
# A projection that doesn't support wrapping
118+
x = [-10, 0, 10]
119+
y = [-10, 10]
120+
121+
xs, ys = np.meshgrid(x, y)
122+
ax = plt.subplot(2, 1, 1, projection=ccrs.Orthographic())
123+
coll = ax.pcolormesh(xs, ys, z, shading='auto',
124+
transform=ccrs.PlateCarree())
125+
126+
coll_bbox = coll.get_datalim(ax.transData)
127+
expected = [[-1650783.327873, -2181451.330891],
128+
[1650783.327873, 2181451.330891]]
129+
np.testing.assert_array_almost_equal(coll_bbox, expected)

0 commit comments

Comments
 (0)