Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport recent master commits to v0.20.x #1969

Merged
merged 6 commits into from
Dec 25, 2021
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
11 changes: 7 additions & 4 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ jobs:
channels: conda-forge/label/testing,conda-forge

- name: Minimum packages
# Only run on macos for now
# Only run on Linux for now
# Conda's linux packages don't grab the testing label of matplotlib causing failures due to freetype differences
if: matrix.python-version == '3.7' && matrix.os == 'macos-latest'
if: matrix.python-version == '3.7' && matrix.os == 'ubuntu-latest'
id: minimum-packages
run: |
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
echo "CFLAGS=-stdlib=libc++" >> $GITHUB_ENV

- name: Latest packages
if: steps.minimum-packages.conclusion == 'skipped'
run: |
echo "PACKAGES=cython fiona matplotlib-base numpy pyproj pykdtree scipy shapely" >> $GITHUB_ENV
echo "PACKAGES=cython fiona matplotlib-base numpy pyproj 'proj>=8' pykdtree scipy shapely" >> $GITHUB_ENV

- name: Coverage packages
id: coverage
Expand All @@ -51,6 +50,10 @@ jobs:
PACKAGES="$PACKAGES flufl.lock owslib pep8 pillow pyshp pytest"
PACKAGES="$PACKAGES pytest-xdist requests setuptools_scm"
PACKAGES="$PACKAGES setuptools_scm_git_archive shapely"
# openssl 3.0 updated the legacy renegotiation default, which causes
# failures in NASA's WMTS server. They will need to update their
# server before we can use a newer openssl.
PACKAGES="$PACKAGES openssl<3"
conda install $PACKAGES
conda info -a
conda list
Expand Down
25 changes: 19 additions & 6 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1863,10 +1863,6 @@ def _wrap_quadmesh(self, collection, **kwargs):
cross the boundary of the projection.
"""
t = kwargs.get('transform', None)
if not (getattr(t, '_wrappable', False) and
getattr(self.projection, '_wrappable', False)):
# Nothing to do
return collection

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

if not np.any(mask):
# No wrapping needed
# Update the data limits based on the corners of the mesh
# in transformed coordinates, ignoring nan values
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'All-NaN slice encountered')
# If we have all nans, that is OK and will be handled by the
# Bbox calculations later, so suppress that warning from the user
corners = ((np.nanmin(xs), np.nanmin(ys)),
(np.nanmax(xs), np.nanmax(ys)))
collection._corners = mtransforms.Bbox(corners)
self.update_datalim(collection._corners)

# We need to keep the transform/projection check after
# update_datalim to make sure we are getting the proper
# datalims on the returned collection
if (not (getattr(t, '_wrappable', False) and
getattr(self.projection, '_wrappable', False)) or
not np.any(mask)):
# If both projections are unwrappable
# or if there aren't any points to wrap
return collection

# Wrapping with gouraud shading is error-prone. We will do our best,
Expand Down
5 changes: 5 additions & 0 deletions lib/cartopy/mpl/geocollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ def set_clim(self, vmin=None, vmax=None):

# Update color limits for the rest of the cells.
super().set_clim(vmin, vmax)

def get_datalim(self, transData):
# Return the corners that were calculated in
# the pcolormesh routine.
return self._corners
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/cartopy/tests/mpl/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@pytest.mark.filterwarnings("ignore:Downloading")
@pytest.mark.natural_earth
@ImageTesting(['natural_earth'])
@ImageTesting(['natural_earth'], tolerance=0.97)
def test_natural_earth():
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND)
Expand Down
4 changes: 2 additions & 2 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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


@pytest.mark.natural_earth
@ImageTesting(['natural_earth_interface'], tolerance=0.21)
@ImageTesting(['natural_earth_interface'], tolerance=1.21)
def test_axes_natural_earth_interface():
rob = ccrs.Robinson()

Expand Down
43 changes: 43 additions & 0 deletions lib/cartopy/tests/mpl/test_pseudo_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,46 @@ def test_pcolormesh_arg_interpolation():
[2, 20],
[4, 20]]])
np.testing.assert_array_almost_equal(expected, coll._coordinates)


def test_pcolormesh_datalim():
# Test that wrapping the coordinates still produces proper data limits
x = [359, 1, 3]
y = [-10, 10]

xs, ys = np.meshgrid(x, y)
# Z with the same shape as X/Y to force the interpolation
z = np.zeros(xs.shape)

ax = plt.subplot(2, 1, 1, projection=ccrs.PlateCarree())
coll = ax.pcolormesh(xs, ys, z, shading='auto',
transform=ccrs.PlateCarree())

coll_bbox = coll.get_datalim(ax.transData)
np.testing.assert_array_equal(coll_bbox, [[-2, -20], [4, 20]])

# Non-wrapped coordinates
x = [-80, 0, 80]
y = [-10, 10]

xs, ys = np.meshgrid(x, y)
ax = plt.subplot(2, 1, 1, projection=ccrs.PlateCarree())
coll = ax.pcolormesh(xs, ys, z, shading='auto',
transform=ccrs.PlateCarree())

coll_bbox = coll.get_datalim(ax.transData)
np.testing.assert_array_equal(coll_bbox, [[-120, -20], [120, 20]])

# A projection that doesn't support wrapping
x = [-10, 0, 10]
y = [-10, 10]

xs, ys = np.meshgrid(x, y)
ax = plt.subplot(2, 1, 1, projection=ccrs.Orthographic())
coll = ax.pcolormesh(xs, ys, z, shading='auto',
transform=ccrs.PlateCarree())

coll_bbox = coll.get_datalim(ax.transData)
expected = [[-1650783.327873, -2181451.330891],
[1650783.327873, 2181451.330891]]
np.testing.assert_array_almost_equal(coll_bbox, expected)