Results from this notebook:
Caveats regarding this notebook:
Hopes for the use of this notebook:
This iPython notebook was originally developed at NOAA/GFDL, and it is provided freely to the MOM6 community. GFDL scientists developing MOM6 make extensive use of Python for diagnostics. We solicit modifications/fixes that are useful to the MOM6 community.
In [1]:
import matplotlib.pyplot as plt # For plotting
import netCDF4 # For reading data
pylab.rcParams['figure.figsize'] = (17.0, 10.0) # Large figures
#path = '../WSwPSBF.C20cm/'
path = '../WSwPSBF.C1m/'
#path = '../WSwPSBF.C10m/'
#path = '../WSwPSBF.CCM4/'
#path = './'
#deltaz = '20cm'
deltaz = '1m'
#deltaz = '10m'
#deltaz = 'CM4'
#fname_deltaz = '_20cm'
fname_deltaz = '_1m'
#fname_deltaz = '_10m'
#fname_deltaz = '_CM4'
dpi=200
In [2]:
visc = netCDF4.Dataset(path+'visc.nc')
for v in visc.variables: print v,
# recall data layout is (t,z,y,x)
time = visc.variables['Time'][:]
# KPP boundary layer depth as function of time (metre)
h = visc.variables['KPP_OBLdepth'][:,0,0]
# KPP tracer diffusivity as function of time and depth (m2/sec)
Kt = visc.variables['KPP_Kheat'][:,:,0,0]
# KPP velocity diffusivity as function of time and depth (m2/sec)
Ku = visc.variables['KPP_Kv'][:,:,0,0]
# surface (and penetrating) buoyancy flux, as used by [CVmix] KPP (m2/s3)
KPP_buoyFlux = visc.variables['KPP_buoyFlux'][:,:,0,0]
# Temperature tendency due to non-local transport of heat, as calculated by KPP (K/s)
KPP_dTdt = visc.variables['KPP_dTdt'][:,:,0,0]
In [3]:
prog = netCDF4.Dataset(path+'prog.nc')
for v in prog.variables: print v,
# depth of cell interface
zi = prog.variables['zi'][:]
# depth of cell center
zl = prog.variables['zl'][:]
# zonal velocity as function of time and depth
u = prog.variables['u'][:,:,0,0]
# zonal velocity as function of time and depth
v = prog.variables['v'][:,:,0,0]
# temperature as function of time and depth
temp = prog.variables['temp'][:,:,0,0]
In [8]:
# thickness of cells
dz = zi[1:]-zi[:-1]
field = zi[1:]+dz[:]
#depth = np.ma.masked_array(data, mask=[data>400.])
depth = field
#print dz
#print dz[1901:2000]
print zi
figure(1)
fig, ax = plt.subplots(figsize=(16, 10), dpi=dpi)
S = plt.plot(dz,-depth,'-',linewidth=3)
yticks = [-400, -350, -300, -250, -200, -150, -100, -50, 0]
ax.set_yticks(yticks)
#xticks = [0, .1, .2, .3, .4, .5]
xticks = [0, .2, .4, .6, .8, 1.0, 1.2]
ax.set_xticks(xticks)
plt.grid()
plt.xlabel('Delta z (m)',fontsize=14)
plt.ylabel('depth (m)',fontsize=14)
plt.title(r'$\Delta z$ (m) for configuration '+deltaz,fontsize=16)
ax.set_yticklabels(["$%.1f$" % y for y in yticks], fontsize=18)
ax.set_xticklabels(["$%.1f$" % x for x in xticks], fontsize=18);
In [9]:
# KPP related fields
plt.subplot(2,2,1)
data = Kt
field = np.ma.masked_array(data, mask=[data==0.])
plt.pcolormesh(time, -zi, field.T,vmin=0, vmax=0.008)
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'$\kappa_{\Theta} (m^2/s)$ with $\Delta z$ ='+deltaz,fontsize=18)
plt.subplot(2,2,2)
data = Ku
field = np.ma.masked_array(data, mask=[data==0.])
plt.pcolormesh(time, -zi, field.T,vmin=0, vmax=0.008)
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'$\kappa_u (m^2/s)$ with $\Delta z$ ='+deltaz,fontsize=18)
plt.subplot(2,2,3)
data = KPP_buoyFlux
field = np.ma.masked_array(data, mask=[data==0.])
plt.pcolormesh(time, -zi, field.T, vmin=0, vmax=1.5e-7)
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'Buoyancy flux $(m^2/s^3)$ with $\Delta z$ ='+deltaz,fontsize=18)
plt.xlabel('Time (days)',fontsize=14)
plt.subplot(2,2,4)
data = KPP_dTdt
field = np.ma.masked_array(data, mask=[data==0.])
plt.contourf(time, -zl, field.T, 16)
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'Non-local $\Theta$ tendency $(K/s)$ with $\Delta z$ ='+deltaz ,fontsize=18)
plt.xlabel('Time (days)',fontsize=14);
In [10]:
# Boundary layer depth and SST
figure(4)
fig, ax = plt.subplots(figsize=(16, 10), dpi=dpi)
CS = plt.plot(time, -h,'-',linewidth=3)
yticks = [-30, -20, -10, 0]
ax.set_yticks(yticks)
xticks = [0, 3, 6, 9, 12, 15]
ax.set_xticks(xticks)
plt.grid()
plt.xlabel('Time (days)',fontsize=14)
plt.ylabel('z (m)',fontsize=14)
plt.title(r'KPP boundary layer depth for WSwPSBF.C with $\Delta z$ ='+deltaz,fontsize=16)
ax.set_yticklabels(["$%.1f$" % y for y in yticks], fontsize=18)
ax.set_xticklabels(["$%.1f$" % x for x in xticks], fontsize=18);
figure(5)
fig, ax = plt.subplots(figsize=(16, 10), dpi=dpi)
CS = plt.plot(time, temp[:,0],'-',linewidth=3)
yticks = [14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5]
ax.set_yticks(yticks)
xticks = [0, 3, 6, 9, 12, 15]
ax.set_xticks(xticks)
plt.grid()
plt.xlabel('Time (days)',fontsize=14)
plt.ylabel('z (m)',fontsize=14)
plt.title(r'SST for WSwPSBF.C with $\Delta z$ ='+deltaz,fontsize=16)
ax.set_yticklabels(["$%.1f$" % y for y in yticks], fontsize=18)
ax.set_xticklabels(["$%.1f$" % x for x in xticks], fontsize=18);
In [11]:
# u,v,temp
plt.subplot(2,2,1)
data = u
field = np.ma.masked_array(data, mask=[data==0.])
plt.contourf(time, -zl, field.T, levels=numpy.arange(-.15,.15,.01))
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title('u (m/s) with $\Delta z$ ='+deltaz,fontsize=16)
plt.subplot(2,2,2)
data = v
field = np.ma.masked_array(data, mask=[data==0.])
plt.contourf(time, -zl, field.T, levels=numpy.arange(-.15,.15,.01))
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title('v (m/s) with $\Delta z$ ='+deltaz,fontsize=16)
plt.subplot(2,2,3)
CS = plt.contourf(time, -zl, temp.T,levels=numpy.arange(14,20,.05))
plt.colorbar()
C = plt.contour(time, -zl, temp.T, 8,linewidth=.5, colors='black')
plt.clabel(C, inline=1, fontsize=10)
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'$\Theta$ ($\degree$C) with $\Delta z$ ='+deltaz,fontsize=16)
plt.xlabel('Time (days)',fontsize=14);
plt.subplot(2,2,4)
difftemp = temp[:,:] - temp[0,:]
data = difftemp
field = np.ma.masked_array(data, mask=[data==0.])
CS = plt.contourf(time, -zl, field.T,levels=numpy.arange(-.6,5,.05))
plt.colorbar()
C = plt.contour(time, -zl, difftemp.T, 8,linewidth=.5, colors='black')
plt.clabel(C, inline=1, fontsize=10)
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'$\Theta-\Theta(t=0)$ ($\degree$C) with $\Delta z$ ='+deltaz,fontsize=16);
plt.xlabel('Time (days)',fontsize=14);
In [12]:
# save figures to a file
figure(1)
fig = plt.figure(figsize=(16,10), dpi=dpi)
plt.pcolormesh(time, -zl, temp.T, vmin=14, vmax=20)
plt.colorbar()
#C = plt.contour(time, -zl, temp.T, linewidth=.5, colors='black',levels=numpy.arange(14,18,.25))
plt.clabel(C, inline=1, fontsize=10)
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.title(r'$\Theta$ ($\degree$C) with $\Delta z$ ='+deltaz,fontsize=16)
plt.xlabel('Time (days)',fontsize=14)
fname = 'temp'+fname_deltaz+'.png'
fig.savefig(fname,dpi=dpi);
figure(2)
fig = plt.figure(figsize=(16,10), dpi=dpi)
difftemp = temp[:,:] - temp[0,:]
data = difftemp
field = np.ma.masked_array(data, mask=[data==0.])
CS = plt.pcolormesh(time, -zl, field.T, vmin=0, vmax=5)
plt.colorbar()
plt.clabel(C, inline=1, fontsize=10)
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.xlabel('Time (days)',fontsize=14)
plt.title(r'$\Theta-\Theta(t=0)$ ($\degree$C) with $\Delta z$ ='+deltaz,fontsize=16);
plt.xlabel('Time (days)',fontsize=14)
fname = 'dtemp'+fname_deltaz+'.png'
fig.savefig(fname,dpi=dpi);
figure(3)
fig = plt.figure(figsize=(16,10), dpi=dpi)
data = Kt
field = np.ma.masked_array(data, mask=[data==0.])
CS = plt.pcolormesh(time, -zi, field.T, vmin=0, vmax=0.01)
plt.colorbar()
plt.ylim((-50,0))
plt.ylabel('z (m)',fontsize=14)
plt.xlabel('Time (days)',fontsize=14)
plt.title(r'$\kappa_{\Theta}$ ($m^2/s$) with $\Delta z$ ='+deltaz,fontsize=16);
plt.xlabel('Time (days)',fontsize=14)
fname = 'KPP_diffusivity'+fname_deltaz+'.png'
fig.savefig(fname,dpi=dpi);
figure(4)
fig, ax = plt.subplots(figsize=(16, 10), dpi=dpi)
CS = plt.plot(time, -h,'-',linewidth=3)
yticks = [-30, -20, -10, 0]
ax.set_yticks(yticks)
xticks = [0, 3, 6, 9, 12, 15]
ax.set_xticks(xticks)
plt.grid()
plt.xlabel('Time (days)',fontsize=14)
plt.ylabel('z (m)',fontsize=14)
plt.title(r'KPP boundary layer depth for WSwPSBF.C with $\Delta z$ ='+deltaz,fontsize=16)
ax.set_yticklabels(["$%.1f$" % y for y in yticks], fontsize=18)
ax.set_xticklabels(["$%.1f$" % x for x in xticks], fontsize=18)
fname = 'KPP_bldepth'+fname_deltaz+'.png'
fig.savefig(fname,dpi=dpi);
figure(5)
fig, ax = plt.subplots(figsize=(16, 10), dpi=dpi)
CS = plt.plot(time, temp[:,0],'-',linewidth=3)
yticks = [14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5]
ax.set_yticks(yticks)
xticks = [0, 3, 6, 9, 12, 15]
ax.set_xticks(xticks)
plt.grid()
plt.xlabel('Time (days)',fontsize=14)
plt.ylabel('z (m)',fontsize=14)
plt.title(r'SST for WSwPSBF.C with $\Delta z$ ='+deltaz,fontsize=16)
ax.set_yticklabels(["$%.1f$" % y for y in yticks], fontsize=18)
ax.set_xticklabels(["$%.1f$" % x for x in xticks], fontsize=18)
fname = 'SST'+fname_deltaz+'.png'
fig.savefig(fname,dpi=dpi);
In [ ]: