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

Make Iris backwards compatible with Cartopy #6172

Merged
merged 3 commits into from
Oct 14, 2024
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
7 changes: 4 additions & 3 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ This document explains the changes made to Iris for this release
🔗 Dependencies
===============

#. `@trexfeathers`_ introduced a ``!=0.23`` Cartopy pin, to avoid
a previous bug of titles clashing with axis labels.
(`cartopy#2390`_, :pull:`6171`)
#. N/A


📚 Documentation
Expand All @@ -95,6 +93,9 @@ This document explains the changes made to Iris for this release
in Iris v3.10.0, :pull:`5948`) to use the same statistical repeat strategy
as timing benchmarks. (:pull:`5981`)

#. `@trexfeathers`_ adapted Iris to work with Cartopy v0.24. (:pull:`6171`,
:pull:`6172`)


.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
Expand Down
22 changes: 22 additions & 0 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime
import warnings

import cartopy
import cartopy.crs as ccrs
from cartopy.geodesic import Geodesic
import cartopy.mpl.geoaxes
Expand All @@ -25,6 +26,7 @@
import matplotlib.transforms as mpl_transforms
import numpy as np
import numpy.ma as ma
from packaging.version import Version

import iris.analysis.cartography as cartography
import iris.coord_systems
Expand All @@ -43,6 +45,26 @@
PlotDefn = collections.namedtuple("PlotDefn", ("coords", "transpose"))


class _GeoAxesPatched(cartopy.mpl.geoaxes.GeoAxes):
# Workaround for a bug where titles collide with axis labels (cartopy#2390)
# Bug is only present in Cartopy v0.23, so this will only be invoked for
# that version.
def _draw_preprocess(self, renderer):
super()._draw_preprocess(renderer)

for artist in self.artists:
if hasattr(artist, "_draw_gridliner"):
# Note this is only necessary since Cartopy v0.23, but is not
# wasteful for earlier versions as _draw_gridliner() includes
# a check for whether a draw is necessary.
artist._draw_gridliner(renderer=renderer)
pp-mo marked this conversation as resolved.
Show resolved Hide resolved


cartopy_version = Version(cartopy.__version__)
if cartopy_version.major == 0 and cartopy_version.minor == 23:
cartopy.mpl.geoaxes.GeoAxes = _GeoAxesPatched


def _get_plot_defn_custom_coords_picked(cube, coords, mode, ndims=2):
def names(coords):
result = []
Expand Down
2 changes: 1 addition & 1 deletion requirements/py310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- setuptools-scm >=7

# Core dependencies.
- cartopy >=0.21,!=0.23
- cartopy >=0.21
- cf-units >=3.1
- cftime >=1.5
- dask-core >=2022.9.0,!=2024.8.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/py311.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- setuptools-scm >=7

# Core dependencies.
- cartopy >=0.21,!=0.23
- cartopy >=0.21
- cf-units >=3.1
- cftime >=1.5
- dask-core >=2022.9.0,!=2024.8.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/py312.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- setuptools-scm >=7

# Core dependencies.
- cartopy >=0.21,!=0.23
- cartopy >=0.21
- cf-units >=3.1
- cftime >=1.5
- dask-core >=2022.9.0,!=2024.8.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/pypi-core.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cartopy>=0.21,!=0.23
cartopy>=0.21
cf-units>=3.1
cftime>=1.5.0
dask[array]>=2022.9.0,!=2024.8.0
Expand Down
Loading