Skip to content

Commit 7fd0c9a

Browse files
authored
Merge pull request #88 from CLIVAR-PRP/87_basemap_conflict_numpy2
map plotting library update
2 parents cb8b02f + a827242 commit 7fd0c9a

File tree

4 files changed

+60
-23
lines changed

4 files changed

+60
-23
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,28 @@ Metrics and collections devised by CLIVAR ENSO group
1919
### Reference
2020

2121
Planton, Y., E. Guilyardi, A. T. Wittenberg, J. Lee, P. J. Gleckler, T. Bayr, S. McGregor, M. J. McPhaden, S. Power, R. Roehrig, J. Vialard, A. Voldoire, 2021: A New Way of Evaluating ENSO in Climate Models: The CLIVAR ENSO Metrics Package. Bulletin of the American Meteorological Society, 102, 1073-1080, [doi: 10.1175/BAMS-D-19-0337.A](https://doi.org/10.1175/BAMS-D-19-0337.A)
22+
23+
Documentation for ENSO metrics: https://github.com/CLIVAR-PRP/ENSO_metrics/wiki
24+
25+
26+
### Release Notes and History
27+
28+
| <div style="width:300%">[Versions]</div> | Update summary |
29+
| ------------| ------------------------------------- |
30+
| [v1.1.4] | Technical update: map plotting library changed to cartopy to comply w/ newer numpy versions
31+
| [v1.1.3] | Technical update: resolve conflict with newer matplotlib versions
32+
| [v1.1.2] | Technical update: to comply w/ newer numpy versions
33+
| [v1.1.1] | Technical update: license, copyright, and conda-forge distribution
34+
| [v1.1] | Technical update: enable Python 3
35+
| [v1.0] | Initial release that is used for [Planton et al. (2021)]
36+
37+
38+
[Versions]: https://github.com/PCMDI/pcmdi_metrics/releases
39+
[v1.1.4]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.4
40+
[v1.1.3]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.3
41+
[v1.1.2]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.2
42+
[v1.1.1]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.1
43+
[v1.1]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1
44+
[v1.0]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.0
45+
46+
[Planton et al. (2021)]: https://doi.org/10.1175/BAMS-D-19-0337.A

lib/version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '1.1.3'
2-
__git_tag_describe__ = '1.1.3'
3-
__git_sha1__ = b'd877b5c4ce7cbc41bddf43120ea50db604b81142'
1+
__version__ = '1.1.4'
2+
__git_tag_describe__ = '1.1.4'
3+
__git_sha1__ = b'cb8b02fe775225b420d0fe43649e5547e1f29b98'

plots/EnsoPlotTemplate.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
from copy import deepcopy
44
from math import ceil as MATHceil
55
from math import floor as MATHfloor
6+
import cartopy.crs as ccrs
7+
import cartopy.feature as cfeature
8+
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
69
from matplotlib.colors import BoundaryNorm, ListedColormap
710
from matplotlib.gridspec import GridSpec
811
from matplotlib.lines import Line2D
912
from matplotlib.patches import Polygon
1013
from matplotlib.ticker import MaxNLocator
14+
import matplotlib.ticker as mticker
1115
import matplotlib.pyplot as plt
12-
from mpl_toolkits.basemap import Basemap
1316
from numpy import arange as NUMPYarange
1417
from numpy import array as NUMPYarray
1518
from numpy import linspace as NUMPYlinspace
@@ -1019,9 +1022,11 @@ def my_map(model, filename_nc, dict_param, reference, metric_variables, figure_n
10191022
"reg_pr_over_sst_map" in variables or "reg_slp_over_sst_map" in variables or
10201023
"reg_ts_over_sst_map" in variables or "djf_map__" in variables or "jja_map__" in variables)) or\
10211024
(isinstance(variables, list) is True and ("djf_map__" in variables[0] or "jja_map__" in variables[0])):
1022-
fig, axes = plt.subplots(nbrl, nbrc, figsize=(6 * nbrc, 6 * nbrl), sharex="col", sharey="row")
1025+
fig, axes = plt.subplots(nbrl, nbrc, figsize=(6 * nbrc, 6 * nbrl), sharex="col", sharey="row",
1026+
subplot_kw={'projection': ccrs.PlateCarree(central_longitude=180)})
10231027
else:
1024-
fig, axes = plt.subplots(nbrl, nbrc, figsize=(4 * nbrc, 4 * nbrl), sharex="col", sharey="row")
1028+
fig, axes = plt.subplots(nbrl, nbrc, figsize=(4 * nbrc, 4 * nbrl), sharex="col", sharey="row",
1029+
subplot_kw={'projection': ccrs.PlateCarree(central_longitude=180)})
10251030
hspa1 = 0.1
10261031
hspa2 = 0.01
10271032
if ((nbrc == 2 and nbrl == 2) or (nbrc == 1 and plot_ref is True)) and isinstance(variables, list) is True and\
@@ -1143,26 +1148,33 @@ def my_map(model, filename_nc, dict_param, reference, metric_variables, figure_n
11431148
transform=ax.transAxes)
11441149
# map
11451150
xx, yy = NUMPYmeshgrid(lon, lat)
1151+
# set extent
11461152
if lat[-1] - lat[0] < 40:
1147-
locmap = Basemap(projection="cyl", llcrnrlat=lat[0] - 5, urcrnrlat=lat[-1] + 5, llcrnrlon=lon[0],
1148-
urcrnrlon=lon[-1], ax=ax)
1153+
ax.set_extent([lon[0], lon[-1], lat[0] - 5, lat[-1] + 5], crs=ccrs.PlateCarree())
11491154
else:
1150-
locmap = Basemap(projection="cyl", llcrnrlat=lat[0], urcrnrlat=lat[-1], llcrnrlon=lon[0], urcrnrlon=lon[-1],
1151-
ax=ax)
1155+
ax.set_extent([lon[0], lon[-1], lat[0], lat[-1]], crs=ccrs.PlateCarree())
11521156
# draw coastlines
1153-
locmap.drawcoastlines()
1157+
ax.coastlines()
11541158
# fill continents
1155-
if maskland is True:
1156-
locmap.fillcontinents(color="gainsboro")
1157-
if maskocean is True:
1158-
locmap.drawmapboundary(fill_color="white")
1159-
# draw parallels
1160-
locmap.drawparallels(ylabel_ticks, labels=[1, 0, 0, 0], fontsize=12, dashes=[3, 1], linewidth=1)
1161-
# draw meridians
1162-
locmap.drawmeridians(xlabel_ticks, labels=[0, 0, 0, 1], fontsize=12, dashes=[3, 1], linewidth=1)
1163-
#cs = locmap.pcolormesh(xx, yy, tab[ii], vmin=min(labelbar), vmax=max(labelbar), cmap=colorbar)
1159+
if maskland:
1160+
ax.add_feature(cfeature.LAND, color="gainsboro")
1161+
if maskocean:
1162+
ax.add_feature(cfeature.OCEAN, color="white")
1163+
# adjust the yticks to convert longitude over 180 to negative to properly add gridlines
1164+
xlabel_ticks_adjusted = [i if i < 180 else i - 360 for i in xlabel_ticks]
1165+
# draw parallels and meridians by adding grid lines only at specified ticks
1166+
gl = ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree(), linestyle='--', color='k')
1167+
gl.xlocator = mticker.FixedLocator(xlabel_ticks_adjusted)
1168+
gl.ylocator = mticker.FixedLocator(ylabel_ticks)
1169+
gl.xformatter = LongitudeFormatter()
1170+
gl.yformatter = LatitudeFormatter()
1171+
gl.top_labels = False
1172+
gl.right_labels = False
1173+
gl.xlabel_style = {'size': 12}
1174+
gl.ylabel_style = {'size': 12}
1175+
# contour plot
11641176
levels = create_levels(labelbar)
1165-
cs = locmap.contourf(xx, yy, tab[ii], levels=levels, extend="both", cmap=colorbar)
1177+
cs = ax.contourf(xx, yy, tab[ii], levels=levels, extend="both", cmap=colorbar, transform=ccrs.PlateCarree())
11661178
# my text
11671179
if (ii > 0 and plot_metric is True and isinstance(variables, list) is False) or\
11681180
(isinstance(variables, list) is True and "nina" in variables[0] and "nino" in variables[1] and
@@ -1219,7 +1231,7 @@ def my_map(model, filename_nc, dict_param, reference, metric_variables, figure_n
12191231
lreg = ReferenceRegions(regions[metric_variables[0]])
12201232
lons = [lreg["longitude"][0]] * 2 + [lreg["longitude"][1]] * 2
12211233
lats = list(lreg["latitude"]) + list(reversed(list(lreg["latitude"])))
1222-
x, y = locmap(lons, lats)
1234+
x, y = lons, lats
12231235
ax.add_patch(Polygon(list(zip(x, y)), edgecolor="k", linewidth=3, linestyle="-", facecolor="none"))
12241236
# if ii == 0 and plot_metric is True:
12251237
# x1 = ax.get_position().x1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import subprocess
33
import glob
44

5-
Version = "1.1.3"
5+
Version = "1.1.4"
66

77
p = subprocess.Popen(
88
("git",

0 commit comments

Comments
 (0)