Skip to content

Commit

Permalink
Merge pull request #80 from dabail10/seaice2
Browse files Browse the repository at this point in the history
Add new external functions to the sea ice notebook.
  • Loading branch information
mnlevy1981 authored Mar 8, 2024
2 parents b70f539 + c4e1d60 commit 643d7e7
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 234 deletions.
9 changes: 7 additions & 2 deletions examples/coupled_model/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ compute_notebooks:
parameter_groups:
none:
cases:
- b.e23_alpha16g.BLT1850.ne30_t232.075
- b.e23_alpha16g.BLT1850.ne30_t232.078
- g.e23_a16g.GJRAv4.TL319_t232_hycom1_N75.2024.005
- g.e23_a16g.GJRAv4.TL319_t232_zstar_N65.2024.004
begyr1: 245
endyr1: 305
begyr2: 245
endyr2: 305
nyears: 25


########### JUPYTER BOOK CONFIG ###########
Expand Down
92 changes: 92 additions & 0 deletions examples/nblibrary/plot_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.path as mpath
from matplotlib.gridspec import GridSpec
import cartopy.crs as ccrs
import cartopy.feature as cfeature

def plot_diff(field1, field2, levels, case1, case2, title, proj, TLAT, TLON):
# make circular boundary for polar stereographic circular plots
theta = np.linspace(0, 2*np.pi, 100)
center, radius = [0.5, 0.5], 0.5
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)


if (np.size(levels) > 2):
cmap = mpl.colormaps['tab20']
norm = mpl.colors.BoundaryNorm(levels, ncolors=cmap.N)

# set up the figure with a North Polar Stereographic projection
fig = plt.figure(tight_layout=True)
gs = GridSpec(2, 4)

if (proj == "N"):
ax = fig.add_subplot(gs[0,:2], projection=ccrs.NorthPolarStereo())
# sets the latitude / longitude boundaries of the plot
ax.set_extent([0.005, 360, 90, 45], crs=ccrs.PlateCarree())
if (proj == "S"):
ax = fig.add_subplot(gs[0,:2], projection=ccrs.SouthPolarStereo())
# sets the latitude / longitude boundaries of the plot
ax.set_extent([0.005, 360, -90, -45], crs=ccrs.PlateCarree())

ax.set_boundary(circle, transform=ax.transAxes)
ax.add_feature(cfeature.LAND,zorder=100,edgecolor='k')

field_diff = field2.values-field1.values
field_std = field_diff.std()

this=ax.pcolormesh(TLON,
TLAT,
field1,
norm = norm,
cmap="tab20",
transform=ccrs.PlateCarree())
plt.colorbar(this,orientation='vertical',fraction=0.04,pad=0.01)
plt.title(case1,fontsize=10)

if (proj == "N"):
ax = fig.add_subplot(gs[0,2:], projection=ccrs.NorthPolarStereo())
# sets the latitude / longitude boundaries of the plot
ax.set_extent([0.005, 360, 90, 45], crs=ccrs.PlateCarree())
if (proj == "S"):
ax = fig.add_subplot(gs[0,2:], projection=ccrs.SouthPolarStereo())
# sets the latitude / longitude boundaries of the plot
ax.set_extent([0.005, 360, -90, -45], crs=ccrs.PlateCarree())

ax.set_boundary(circle, transform=ax.transAxes)
ax.add_feature(cfeature.LAND,zorder=100,edgecolor='k')

this=ax.pcolormesh(TLON,
TLAT,
field2,
norm=norm,
cmap="tab20",
transform=ccrs.PlateCarree())
plt.colorbar(this,orientation='vertical',fraction=0.04,pad=0.01)
plt.title(case2,fontsize=10)

if (proj == "N"):
ax = fig.add_subplot(gs[1,1:3], projection=ccrs.NorthPolarStereo())
# sets the latitude / longitude boundaries of the plot
ax.set_extent([0.005, 360, 90, 45], crs=ccrs.PlateCarree())
if (proj == "S"):
ax = fig.add_subplot(gs[1,1:3], projection=ccrs.SouthPolarStereo())
# sets the latitude / longitude boundaries of the plot
ax.set_extent([0.005, 360, -90, -45], crs=ccrs.PlateCarree())

ax.set_boundary(circle, transform=ax.transAxes)
ax.add_feature(cfeature.LAND,zorder=100,edgecolor='k')

this=ax.pcolormesh(TLON,
TLAT,
field_diff,
cmap="seismic",vmax=field_std*2.0,vmin=-field_std*2.0,
transform=ccrs.PlateCarree())
plt.colorbar(this,orientation='vertical',fraction=0.04,pad=0.01)
plt.title(case2+"-"+case1,fontsize=10)

plt.suptitle(title)

Loading

0 comments on commit 643d7e7

Please sign in to comment.