Skip to content

Commit a2f49c3

Browse files
Unpin Matplotlib and proj (#3762)
* unpin proj, move cartopy pin forward * Explicit resolution of coastlines in tests - see SciTools/cartopy#1105. * Removed gdal optional requirement. * New target image for test_plot_custom_aggregation due to auto-sizing coastlines in SciTools/cartopy#1105. Twin commit: SciTools/test-iris-imagehash@9b4e50e. * New acceptable images for various tests due to minor changes in Matplotlib 3.3. Twin commit: SciTools/test-iris-imagehash@3babde5. * New target images for test plots affected by the gridline spacing change in SciTools/cartopy@2f5e568. Twin commit: SciTools/test-iris-imagehash@f071f2c. * New acceptable images to allow for minute colormap range changes in Matplotlib 3.3. Twin commit: SciTools/test-iris-imagehash@9f4b04e. * Improvement to quickplot time axis labelling and accompanying graphics test target changes. Twin commit: SciTools/test-iris-imagehash@3036a6f * Made quickplot time axis label sensitive to MPL version (see matplotlib/matplotlib#15008). * More target images following from 41b3b2a. Twin commit: SciTools/test-iris-imagehash@804ff68. * More target images following from 27ea2f2. Twin commit: SciTools/test-iris-imagehash@f559a36. * Mirroring _draw_2d_from_points() use of mpl date2num in _draw_2d_from_bounds(). Twin commit: SciTools/test-iris-imagehash@3c582dc. * Re-instated all valid image targets for TestPlotCoordinatesGiven.test_tx. * New target image for TestSimple.test_bounds following change to plot axis labelling. Twin commit: SciTools/test-iris-imagehash@770dc92. * modify raster tests to handle new gdal behaviour * modify raster tests to handle new gdal naming behaviour * modify tests to reflect new PROJ behaviour * modify parts of test_project to use Transverse Mercator * revert test_project to use Robinson, add warning to docstring * keep results consistent Co-authored-by: Martin Yeo <martin.yeo@metoffice.gov.uk>
1 parent c2a834f commit a2f49c3

14 files changed

Lines changed: 133 additions & 133 deletions

File tree

lib/iris/analysis/cartography.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,12 @@ def project(cube, target_proj, nx=None, ny=None):
599599
on the statistics of the data e.g. the mean and standard deviation
600600
will not be preserved.
601601
602+
.. warning::
603+
604+
If the target projection is non-rectangular, e.g. Robinson, the target
605+
grid may include points outside the boundary of the projection. The
606+
latitude/longitude of such points may be unpredictable.
607+
602608
"""
603609
try:
604610
lon_coord, lat_coord = _get_lon_lat_coords(cube)

lib/iris/plot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ def _draw_2d_from_bounds(draw_method_name, cube, *args, **kwargs):
441441
values = np.arange(data.shape[data_dim] + 1) - 0.5
442442
else:
443443
values = coord.contiguous_bounds()
444+
values = _fixup_dates(coord, values)
445+
if values.dtype == np.dtype(object) and isinstance(
446+
values[0], datetime.datetime
447+
):
448+
values = mpl_dates.date2num(values)
444449

445450
plot_arrays.append(values)
446451

lib/iris/quickplot.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""
1515

1616
import cf_units
17+
from matplotlib import __version__ as mpl_version
1718
import matplotlib.pyplot as plt
1819

1920
import iris.config
@@ -46,6 +47,13 @@ def _title(cube_or_coord, with_units):
4647

4748
if _use_symbol(units):
4849
units = units.symbol
50+
if units.is_time_reference():
51+
# iris.plot uses matplotlib.dates.date2num, which is fixed to the below unit.
52+
if mpl_version >= "3.3":
53+
days_since = "1970-01-01"
54+
else:
55+
days_since = "0001-01-01"
56+
units = "days since {}".format(days_since)
4957
title += " / {}".format(units)
5058

5159
return title

lib/iris/tests/experimental/test_raster.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def _check_tiff_export(self, masked, inverted=False):
7777
339,
7878
33550,
7979
33922,
80+
42113,
81+
# Don't add a check entry for this, as coding changed between gdal
82+
# version 1 and 2.
83+
# tif_header_entries[42113] = (u'1e+20',)
8084
]
8185
tif_header_entries = {
8286
256: (160,),
@@ -130,12 +134,6 @@ def _check_tiff_export(self, masked, inverted=False):
130134
# Mask some of the data + expect a slightly different header...
131135
cube.data = np.ma.masked_where(cube.data <= 380, cube.data)
132136

133-
# There is an additional key..
134-
tif_header_keys += [42113]
135-
# Don't add a check entry for this, as coding changed between gdal
136-
# version 1 and 2, *and* between Python2 and Python3.
137-
# tif_header_entries[42113] = (u'1e+20',)
138-
139137
if inverted:
140138
# Check with the latitude coordinate (and the corresponding
141139
# cube.data) inverted.

lib/iris/tests/integration/plot/test_plot_2d_coords.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def test_2d_coord_bounds_platecarree(self):
4343
cube = simple_cube_w_2d_coords()[0, 0]
4444
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
4545
qplt.pcolormesh(cube)
46-
ax.coastlines(color="red")
46+
ax.coastlines(resolution="110m", color="red")
4747
self.check_graphic()
4848

4949
def test_2d_coord_bounds_northpolarstereo(self):
5050
cube = simple_cube_w_2d_coords()[0, 0]
5151
ax = plt.axes(projection=ccrs.NorthPolarStereo())
5252
qplt.pcolormesh(cube)
53-
ax.coastlines(color="red")
53+
ax.coastlines(resolution="110m", color="red")
5454
self.check_graphic()
5555

5656

@@ -71,7 +71,7 @@ def test_2d_coords_contour(self):
7171
cube.add_aux_coord(co_x, (0, 1))
7272
ax = plt.axes(projection=ccrs.PlateCarree())
7373
qplt.contourf(cube)
74-
ax.coastlines(color="red")
74+
ax.coastlines(resolution="110m", color="red")
7575
ax.gridlines(draw_labels=True)
7676
ax.set_extent((0, 180, 0, 90))
7777
self.check_graphic()

lib/iris/tests/integration/plot/test_vector_plots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_2d_plain_latlon(self):
121121
self.plot(
122122
"latlon_2d", u_cube, v_cube, coords=("longitude", "latitude")
123123
)
124-
ax.coastlines(color="red")
124+
ax.coastlines(resolution="110m", color="red")
125125
ax.set_global()
126126
self.check_graphic()
127127

@@ -132,7 +132,7 @@ def test_2d_plain_latlon_on_polar_map(self):
132132
self.plot(
133133
"latlon_2d_polar", u_cube, v_cube, coords=("longitude", "latitude")
134134
)
135-
ax.coastlines(color="red")
135+
ax.coastlines(resolution="110m", color="red")
136136
self.check_graphic()
137137

138138
def test_2d_rotated_latlon(self):
@@ -142,7 +142,7 @@ def test_2d_rotated_latlon(self):
142142
self.plot(
143143
"2d_rotated", u_cube, v_cube, coords=("longitude", "latitude")
144144
)
145-
ax.coastlines(color="red")
145+
ax.coastlines(resolution="110m", color="red")
146146
ax.set_global()
147147
self.check_graphic()
148148

0 commit comments

Comments
 (0)