Skip to content

Commit

Permalink
Make Iris backwards compatible with Cartopy.
Browse files Browse the repository at this point in the history
  • Loading branch information
trexfeathers committed Oct 11, 2024
1 parent ef2bf01 commit 142ef30
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
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)


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

0 comments on commit 142ef30

Please sign in to comment.