Skip to content

Commit

Permalink
Merge pull request #88 from CLIVAR-PRP/87_basemap_conflict_numpy2
Browse files Browse the repository at this point in the history
map plotting library update
  • Loading branch information
lee1043 authored Dec 4, 2024
2 parents cb8b02f + a827242 commit 7fd0c9a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,28 @@ Metrics and collections devised by CLIVAR ENSO group
### Reference

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)

Documentation for ENSO metrics: https://github.com/CLIVAR-PRP/ENSO_metrics/wiki


### Release Notes and History

| <div style="width:300%">[Versions]</div> | Update summary |
| ------------| ------------------------------------- |
| [v1.1.4] | Technical update: map plotting library changed to cartopy to comply w/ newer numpy versions
| [v1.1.3] | Technical update: resolve conflict with newer matplotlib versions
| [v1.1.2] | Technical update: to comply w/ newer numpy versions
| [v1.1.1] | Technical update: license, copyright, and conda-forge distribution
| [v1.1] | Technical update: enable Python 3
| [v1.0] | Initial release that is used for [Planton et al. (2021)]


[Versions]: https://github.com/PCMDI/pcmdi_metrics/releases
[v1.1.4]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.4
[v1.1.3]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.3
[v1.1.2]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.2
[v1.1.1]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1.1
[v1.1]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.1
[v1.0]: https://github.com/CLIVAR-PRP/ENSO_metrics/releases/tag/v1.0

[Planton et al. (2021)]: https://doi.org/10.1175/BAMS-D-19-0337.A
6 changes: 3 additions & 3 deletions lib/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '1.1.3'
__git_tag_describe__ = '1.1.3'
__git_sha1__ = b'd877b5c4ce7cbc41bddf43120ea50db604b81142'
__version__ = '1.1.4'
__git_tag_describe__ = '1.1.4'
__git_sha1__ = b'cb8b02fe775225b420d0fe43649e5547e1f29b98'
50 changes: 31 additions & 19 deletions plots/EnsoPlotTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
from copy import deepcopy
from math import ceil as MATHceil
from math import floor as MATHfloor
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from matplotlib.colors import BoundaryNorm, ListedColormap
from matplotlib.gridspec import GridSpec
from matplotlib.lines import Line2D
from matplotlib.patches import Polygon
from matplotlib.ticker import MaxNLocator
import matplotlib.ticker as mticker
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from numpy import arange as NUMPYarange
from numpy import array as NUMPYarray
from numpy import linspace as NUMPYlinspace
Expand Down Expand Up @@ -1019,9 +1022,11 @@ def my_map(model, filename_nc, dict_param, reference, metric_variables, figure_n
"reg_pr_over_sst_map" in variables or "reg_slp_over_sst_map" in variables or
"reg_ts_over_sst_map" in variables or "djf_map__" in variables or "jja_map__" in variables)) or\
(isinstance(variables, list) is True and ("djf_map__" in variables[0] or "jja_map__" in variables[0])):
fig, axes = plt.subplots(nbrl, nbrc, figsize=(6 * nbrc, 6 * nbrl), sharex="col", sharey="row")
fig, axes = plt.subplots(nbrl, nbrc, figsize=(6 * nbrc, 6 * nbrl), sharex="col", sharey="row",
subplot_kw={'projection': ccrs.PlateCarree(central_longitude=180)})
else:
fig, axes = plt.subplots(nbrl, nbrc, figsize=(4 * nbrc, 4 * nbrl), sharex="col", sharey="row")
fig, axes = plt.subplots(nbrl, nbrc, figsize=(4 * nbrc, 4 * nbrl), sharex="col", sharey="row",
subplot_kw={'projection': ccrs.PlateCarree(central_longitude=180)})
hspa1 = 0.1
hspa2 = 0.01
if ((nbrc == 2 and nbrl == 2) or (nbrc == 1 and plot_ref is True)) and isinstance(variables, list) is True and\
Expand Down Expand Up @@ -1143,26 +1148,33 @@ def my_map(model, filename_nc, dict_param, reference, metric_variables, figure_n
transform=ax.transAxes)
# map
xx, yy = NUMPYmeshgrid(lon, lat)
# set extent
if lat[-1] - lat[0] < 40:
locmap = Basemap(projection="cyl", llcrnrlat=lat[0] - 5, urcrnrlat=lat[-1] + 5, llcrnrlon=lon[0],
urcrnrlon=lon[-1], ax=ax)
ax.set_extent([lon[0], lon[-1], lat[0] - 5, lat[-1] + 5], crs=ccrs.PlateCarree())
else:
locmap = Basemap(projection="cyl", llcrnrlat=lat[0], urcrnrlat=lat[-1], llcrnrlon=lon[0], urcrnrlon=lon[-1],
ax=ax)
ax.set_extent([lon[0], lon[-1], lat[0], lat[-1]], crs=ccrs.PlateCarree())
# draw coastlines
locmap.drawcoastlines()
ax.coastlines()
# fill continents
if maskland is True:
locmap.fillcontinents(color="gainsboro")
if maskocean is True:
locmap.drawmapboundary(fill_color="white")
# draw parallels
locmap.drawparallels(ylabel_ticks, labels=[1, 0, 0, 0], fontsize=12, dashes=[3, 1], linewidth=1)
# draw meridians
locmap.drawmeridians(xlabel_ticks, labels=[0, 0, 0, 1], fontsize=12, dashes=[3, 1], linewidth=1)
#cs = locmap.pcolormesh(xx, yy, tab[ii], vmin=min(labelbar), vmax=max(labelbar), cmap=colorbar)
if maskland:
ax.add_feature(cfeature.LAND, color="gainsboro")
if maskocean:
ax.add_feature(cfeature.OCEAN, color="white")
# adjust the yticks to convert longitude over 180 to negative to properly add gridlines
xlabel_ticks_adjusted = [i if i < 180 else i - 360 for i in xlabel_ticks]
# draw parallels and meridians by adding grid lines only at specified ticks
gl = ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree(), linestyle='--', color='k')
gl.xlocator = mticker.FixedLocator(xlabel_ticks_adjusted)
gl.ylocator = mticker.FixedLocator(ylabel_ticks)
gl.xformatter = LongitudeFormatter()
gl.yformatter = LatitudeFormatter()
gl.top_labels = False
gl.right_labels = False
gl.xlabel_style = {'size': 12}
gl.ylabel_style = {'size': 12}
# contour plot
levels = create_levels(labelbar)
cs = locmap.contourf(xx, yy, tab[ii], levels=levels, extend="both", cmap=colorbar)
cs = ax.contourf(xx, yy, tab[ii], levels=levels, extend="both", cmap=colorbar, transform=ccrs.PlateCarree())
# my text
if (ii > 0 and plot_metric is True and isinstance(variables, list) is False) or\
(isinstance(variables, list) is True and "nina" in variables[0] and "nino" in variables[1] and
Expand Down Expand Up @@ -1219,7 +1231,7 @@ def my_map(model, filename_nc, dict_param, reference, metric_variables, figure_n
lreg = ReferenceRegions(regions[metric_variables[0]])
lons = [lreg["longitude"][0]] * 2 + [lreg["longitude"][1]] * 2
lats = list(lreg["latitude"]) + list(reversed(list(lreg["latitude"])))
x, y = locmap(lons, lats)
x, y = lons, lats
ax.add_patch(Polygon(list(zip(x, y)), edgecolor="k", linewidth=3, linestyle="-", facecolor="none"))
# if ii == 0 and plot_metric is True:
# x1 = ax.get_position().x1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
import glob

Version = "1.1.3"
Version = "1.1.4"

p = subprocess.Popen(
("git",
Expand Down

0 comments on commit 7fd0c9a

Please sign in to comment.