Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mom6_tools/aaiw_pv.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def plot_aaiw_pv(y, zl, pv, volume, levels, colors, args):
if args.savefigs:
fname = args.outdir + str(args.casename)+'_AAIW_PV.png'
plt.savefig(fname, bbox_inches='tight')
plt.close(fig)

if __name__ == '__main__':
main()
Expand Down
6 changes: 4 additions & 2 deletions mom6_tools/equatorial_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def preprocess(ds):
ax2.set_ylim(-400,0)
plt.suptitle('Temperature [C] @ '+str(l)+ ', averaged between '+str(args.start_date)+' and '+str(args.end_date))
plt.savefig(figname+'temperature_'+str(l)+'.png')
plt.close(fig)

# Salt
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(17,7), sharey=True)
Expand All @@ -237,6 +238,7 @@ def preprocess(ds):
ax2.set_ylim(-400,0)
plt.suptitle('Salinity [psu] @ '+str(l)+ ', averaged between '+str(args.start_date)+' and '+str(args.end_date))
plt.savefig(figname+'salinity_'+str(l)+'.png')
plt.close(fig)

# uo
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(17,7), sharey=True)
Expand All @@ -250,6 +252,7 @@ def preprocess(ds):
ax2.set_ylim(-400,0)
plt.suptitle('Eastward velocity [m/s] @ '+str(l)+ ', averaged between '+str(args.start_date)+' and '+str(args.end_date))
plt.savefig(figname+'uo_'+str(l)+'.png')
plt.close(fig)

# Eastward velocity [m/s] along the Equatorial Pacific
x_obs = johnson.XLON.values
Expand All @@ -273,8 +276,7 @@ def preprocess(ds):
ax2.set_xlim(143,265); ax2.set_ylim(-400,0); ax2.set_ylabel('')
plt.suptitle('Eastward velocity [m/s] along the Equatorial Pacific, averaged between '+str(args.start_date)+' and '+str(args.end_date))
plt.savefig(figname+'Equatorial_Pacific_uo.png')

plt.close('all')
plt.close(fig)

print('{} was run successfully!'.format(os.path.basename(__file__)))

Expand Down
1 change: 1 addition & 0 deletions mom6_tools/latlon_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def plot_area_ave_stats(ds, var, args, aspect=[16,9], resolution=576, debug=Fals
plt.savefig('PNG/%s_stats.png'%(var))
else:
plt.show()
plt.close(f)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: open issue ticket to rename f -> fig for consistency with other scripts


return

Expand Down
22 changes: 20 additions & 2 deletions mom6_tools/m6plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def add_features(fig, ax, cs, extend, landcolor):
if save is not None: plt.savefig(save,bbox_inches='tight')
if interactive: addInteractiveCallbacks()
if show: plt.show(block=False)

if save is not None and not show: plt.close(fig)

return

Expand Down Expand Up @@ -506,10 +506,12 @@ def polarplot(field, grd, proj='SP', contour=None, circle=True,
else:
cmap, norm, extend = chooseColorLevels(sMin, sMax, colormap, clim=clim, nbins=nbins, extend=extend, logscale=logscale)

close_fig = None
if axis is None:
setFigureSize(aspect, resolution, debug=debug)
#plt.gcf().subplots_adjust(left=.08, right=.99, wspace=0, bottom=.09, top=.9, hspace=0)
axis = plt.gca(projection=proj)
if save is not None and not show: close_fig = plt.gcf()

axis.set_extent(extent, ccrs.PlateCarree())
axis.add_feature(cartopy.feature.LAND)
Expand Down Expand Up @@ -545,6 +547,7 @@ def polarplot(field, grd, proj='SP', contour=None, circle=True,
if save is not None: plt.savefig(save)
if show: plt.show(block=False)
plt.tight_layout()
if close_fig is not None: plt.close(close_fig)

return

Expand Down Expand Up @@ -613,10 +616,12 @@ def xyplot(field, x=None, y=None, area=None,
else:
cmap, norm, extend = chooseColorLevels(sMin, sMax, colormap, clim=clim, nbins=nbins, extend=extend, logscale=logscale)

close_fig = None
if axis is None:
setFigureSize(aspect, resolution, debug=debug)
#plt.gcf().subplots_adjust(left=.08, right=.99, wspace=0, bottom=.09, top=.9, hspace=0)
axis = plt.gca()
if save is not None and not show: close_fig = plt.gcf()
cs = axis.pcolormesh(xCoord, yCoord, maskedField, cmap=cmap, norm=norm)
if interactive: addStatusBar(xCoord, yCoord, maskedField)
if add_cbar: cb = plt.colorbar(cs, ax=axis, fraction=.08, pad=0.02, extend=extend)
Expand All @@ -636,9 +641,10 @@ def xyplot(field, x=None, y=None, area=None,
if len(title)>0: axis.set_title(title)
if len(suptitle)>0: plt.suptitle(suptitle)

if save is not None: plt.savefig(save); plt.close()
if save is not None: plt.savefig(save)
if interactive: addInteractiveCallbacks()
if show: plt.show(block=False)
if close_fig is not None: plt.close(close_fig)
if add_cbar:
return
else:
Expand Down Expand Up @@ -739,8 +745,10 @@ def xycompare(field1, field2, x=None, y=None, area=None,

if addplabel: preTitleA = 'A: '; preTitleB = 'B: '
else: preTitleA = ''; preTitleB = ''
close_fig = None
if axis is None:
setFigureSize(aspect, resolution, npanels=npanels, debug=debug)
if save is not None and not show: close_fig = plt.gcf()

if npanels in [2,3]:
if axis is not None:
Expand Down Expand Up @@ -843,6 +851,7 @@ def xycompare(field1, field2, x=None, y=None, area=None,
if save is not None: plt.savefig(save,bbox_inches='tight')
if interactive: addInteractiveCallbacks()
if show: plt.show(block=False)
if close_fig is not None: plt.close(close_fig)

return

Expand Down Expand Up @@ -924,10 +933,12 @@ def yzplot(field, y=None, z=None,
if colormap is None: colormap = chooseColorMap(sMin, sMax)
cmap, norm, extend = chooseColorLevels(sMin, sMax, colormap, clim=clim, nbins=nbins, extend=extend)

close_fig = None
if axis is None:
setFigureSize(aspect, resolution, debug=debug)
#plt.gcf().subplots_adjust(left=.10, right=.99, wspace=0, bottom=.09, top=.9, hspace=0)
axis = plt.gca()
if save is not None and not show: close_fig = plt.gcf()

cs = axis.pcolormesh(yCoord, zCoord, field2, cmap=cmap, norm=norm)
if interactive: addStatusBar(yCoord, zCoord, field2)
Expand All @@ -953,6 +964,7 @@ def yzplot(field, y=None, z=None,
if save is not None: plt.savefig(save)
if interactive: addInteractiveCallbacks()
if show: plt.show(block=False)
if close_fig is not None: plt.close(close_fig)

def yzcompare(field1, field2, y=None, z=None,
ylabel=None, yunits=None, zlabel=None, zunits=None,
Expand Down Expand Up @@ -1045,9 +1057,11 @@ def yzcompare(field1, field2, y=None, z=None,
if addplabel: preTitleA = 'A: '; preTitleB = 'B: '
else: preTitleA = ''; preTitleB = ''

close_fig = None
if axis is None:
setFigureSize(aspect, resolution, npanels=npanels, debug=debug)
#plt.gcf().subplots_adjust(left=.13, right=.94, wspace=0, bottom=.05, top=.94, hspace=0.15)
if save is not None and not show: close_fig = plt.gcf()

if npanels in [2, 3]:
axis = plt.subplot(npanels,1,1)
Expand Down Expand Up @@ -1120,6 +1134,7 @@ def yzcompare(field1, field2, y=None, z=None,
if save is not None: plt.savefig(save)
if interactive: addInteractiveCallbacks()
if show: plt.show(block=False)
if close_fig is not None: plt.close(close_fig)

def ztplot(field, t=None, z=None,
tlabel=None, tunits=None, zlabel=None, zunits=None,
Expand Down Expand Up @@ -1183,10 +1198,12 @@ def ztplot(field, t=None, z=None,
if colormap is None: colormap = chooseColorMap(sMin, sMax)
cmap, norm, extend = chooseColorLevels(sMin, sMax, colormap, clim=clim, nbins=nbins, extend=extend, autocenter=autocenter)

close_fig = None
if axis is None:
setFigureSize(aspect, resolution, debug=debug)
#plt.gcf().subplots_adjust(left=.10, right=.99, wspace=0, bottom=.09, top=.9, hspace=0)
axis = plt.gca()
if save is not None and not show: close_fig = plt.gcf()

cs = axis.pcolormesh(tCoord, zCoord, field2, cmap=cmap, norm=norm)
if interactive: addStatusBar(tCoord, zCoord, field2)
Expand Down Expand Up @@ -1219,6 +1236,7 @@ def ztplot(field, t=None, z=None,
if save is not None: plt.savefig(save)
if interactive: addInteractiveCallbacks()
if show: plt.show(block=False)
if close_fig is not None: plt.close(close_fig)
if add_cbar:
return
else:
Expand Down
8 changes: 8 additions & 0 deletions mom6_tools/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class C(np.ndarray): pass
plt.gca().invert_yaxis()
objOut = args.outdir+str(casename)+'_MOC_global.png'
plt.savefig(objOut)
plt.close()

if 'zl' in ds:
zl = ds.zl.values
Expand Down Expand Up @@ -188,6 +189,7 @@ class C(np.ndarray): pass
plt.gca().invert_yaxis()
objOut = args.outdir+str(casename)+'_MOC_IndoPacific.png'
plt.savefig(objOut,format='png')
plt.close()
moc['ipmoc'].data = psiPlot

# Atlantic MOC
Expand Down Expand Up @@ -223,6 +225,7 @@ class C(np.ndarray): pass
plt.gca().invert_yaxis()
objOut = args.outdir+str(casename)+'_MOC_Atlantic.png'
plt.savefig(objOut,format='png')
plt.close()
moc['amoc'].data = psiPlot

print('Plotting AMOC profile at 26N...')
Expand All @@ -238,6 +241,7 @@ class C(np.ndarray): pass
ax.set_ylabel('Depth [m]')
objOut = args.outdir+str(casename)+'_MOC_profile_26N.png'
plt.savefig(objOut,format='png')
plt.close(fig)

# --- Vectorized time series computation ---
# Precompute Atlantic vmsk (m is the Atlantic mask from above)
Expand Down Expand Up @@ -312,6 +316,7 @@ class C(np.ndarray): pass
plt.legend(fontsize=13, ncol=2)
objOut = args.outdir+str(casename)+'_MOC_26N_time_series.png'
plt.savefig(objOut, format='png')
plt.close(fig)

# plot AMOC @ 45N
fig = plt.figure(figsize=(12, 6))
Expand All @@ -329,6 +334,7 @@ class C(np.ndarray): pass
plt.legend(fontsize=14)
objOut = args.outdir+str(casename)+'_MOC_45N_time_series.png'
plt.savefig(objOut, format='png')
plt.close(fig)

# Submesoscale-induced Global MOC
varName = 'vhml'
Expand All @@ -351,6 +357,7 @@ class C(np.ndarray): pass
plt.gca().invert_yaxis()
objOut = args.outdir+str(casename)+'_FFH_MOC_global.png'
plt.savefig(objOut)
plt.close()
moc['moc_FFH'].data = psiPlot

# GM-induced Global MOC
Expand All @@ -374,6 +381,7 @@ class C(np.ndarray): pass
findExtrema(yy, z, psiPlot, min_lat=-65., max_lat=-30, mult=-1.)
objOut = args.outdir+str(casename)+'_GM_MOC_global.png'
plt.savefig(objOut)
plt.close()
moc['moc_GM'].data = psiPlot

print('Saving netCDF files...')
Expand Down
10 changes: 10 additions & 0 deletions mom6_tools/moc_sigma2.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def preprocess(ds):
cbar.set_ticks(clevels)
objOut = args.outdir+str(casename)+'_MOC_sigma2_global.png'
plt.savefig(objOut)
plt.close(fig)

# zrho
fig, axis = plt.subplots(1,1, figsize=(15,5))
Expand Down Expand Up @@ -229,6 +230,7 @@ def preprocess(ds):
axis.set_title("Case {}, global meridional-zrho overturning".format(args.label),fontsize=10)
objOut = args.outdir+str(casename)+'_MOC_zrho_global.png'
plt.savefig(objOut)
plt.close(fig)

# create dataset to store results
moc = xr.Dataset(data_vars={ 'moc' : (('rho2_l','yq'), psi.data),
Expand Down Expand Up @@ -270,6 +272,7 @@ def preprocess(ds):
cbar.set_ticks(clevels)
objOut = args.outdir+str(casename)+'_MOC_sigma2_global_vhml.png'
plt.savefig(objOut)
plt.close(fig)
moc['moc_FFH'].data = psi_vhml.data
# zrho
fig, axis = plt.subplots(1,1, figsize=(15,5))
Expand Down Expand Up @@ -302,6 +305,7 @@ def preprocess(ds):

objOut = args.outdir+str(casename)+'_FFH_MOC_global.png'
plt.savefig(objOut)
plt.close(fig)
moc['moc_FFH'].data = psi.data

# GM-induced Global MOC
Expand All @@ -328,6 +332,7 @@ def preprocess(ds):
cbar.set_ticks(clevels)
objOut = args.outdir+str(casename)+'_MOC_sigma2_global_vhGM.png'
plt.savefig(objOut)
plt.close(fig)
moc['moc_GM'].data = psi_vhGM.data
# zrho
fig, axis = plt.subplots(1,1, figsize=(15,5))
Expand Down Expand Up @@ -357,6 +362,7 @@ def preprocess(ds):
axis.set_title("Case {}, global meridional-zrho overturning (Sv) due to vhGM".format(args.label),fontsize=10)
objOut = args.outdir+str(casename)+'_MOC_zrho_global_vhGM.png'
plt.savefig(objOut)
plt.close(fig)

# Indo-Pacific
atl = basin_code_xr.sel(region='AtlanticOcean') + basin_code_xr.sel(region='Arctic') + \
Expand Down Expand Up @@ -402,6 +408,7 @@ def preprocess(ds):
cbar.set_ticks(clevels)
objOut = args.outdir+str(casename)+'_MOC_sigma2_IndoPacific.png'
plt.savefig(objOut,format='png')
plt.close(fig)

#zrho
fig, axis = plt.subplots(1,1, figsize=(15,5))
Expand Down Expand Up @@ -429,6 +436,7 @@ def preprocess(ds):
axis.set_title("Case {}, Indo-Pacific meridional-zrho overturning".format(args.label),fontsize=10)
objOut = args.outdir+str(casename)+'_MOC_zrho_IndoPacific.png'
plt.savefig(objOut,format='png')
plt.close(fig)
moc['ipmoc'].data = psi.data
moc = moc.assign_coords({"ipmoc_depth": (["rho2_l","yq"], psi['depth'].data)})

Expand Down Expand Up @@ -477,6 +485,7 @@ def preprocess(ds):
cbar.set_ticks(clevels)
objOut = args.outdir+str(casename)+'_MOC_sigma2_Atlantic.png'
plt.savefig(objOut,format='png')
plt.close(fig)

# zrho
fig, axis = plt.subplots(1,1, figsize=(15,5))
Expand Down Expand Up @@ -506,6 +515,7 @@ def preprocess(ds):
axis.set_title("Case {}, Atlantic meridional-zrho overturning".format(args.label),fontsize=10)
objOut = args.outdir+str(casename)+'_MOC_zrho_Atlantic.png'
plt.savefig(objOut,format='png')
plt.close(fig)
moc['amoc'].data = psi.data
moc = moc.assign_coords({"amoc_depth": (["rho2_l","yq"], psi['depth'].data)})

Expand Down
1 change: 1 addition & 0 deletions mom6_tools/section_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def main(stream=False):
os.makedirs(args.outdir, exist_ok=True)
objOut = args.outdir+'/'+args.casename+'_section_transports.png'
plt.savefig(objOut)
plt.close(fig)

print('Total time elasped: ', datetime.now() - start)
print('{} was run successfully!'.format(os.path.basename(__file__)))
Expand Down
6 changes: 6 additions & 0 deletions mom6_tools/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def get_MLD(ds, var, mld_obs, grd, args):
plt.subplots_adjust(top=0.93, bottom=0.26)
fname = 'PNG/MLD/'+str(args.casename)+'_MLD_monthly_clima.png'
plt.savefig(fname)
plt.close(fig)
plt.close(plot.fig)

# MLD monthly bias (model - obs)
# Add a 'month' coordinate to 'reference'
Expand Down Expand Up @@ -322,6 +324,8 @@ def get_MLD(ds, var, mld_obs, grd, args):
plt.subplots_adjust(top=0.93, bottom=0.26)
fname = 'PNG/MLD/'+str(args.casename)+'_MLD_monthly_clima_bias.png'
plt.savefig(fname)
plt.close(fig)
plt.close(plot.fig)

# JFM, starting from 0
months = [0,1,2]
Expand Down Expand Up @@ -484,6 +488,8 @@ def get_BLD(ds, var, grd, args):
plt.subplots_adjust(top=0.93, bottom=0.26)
fname = 'PNG/BLD/'+str(args.casename)+'_BLD_monthly_clima.png'
plt.savefig(fname)
plt.close(fig)
plt.close(plot.fig)

# March and Sep, noticed starting from 0
months = [2,8]
Expand Down
3 changes: 1 addition & 2 deletions mom6_tools/tao_mooring_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ def fmt(x):
ax[2].legend()
pfile = 'u_ann.' + pos + '.png'
plt.savefig(os.path.join(path_plt_out,pfile))

plt.close('all')
plt.close(fig)

print('{} was run successfully!'.format(os.path.basename(__file__)))

Expand Down
Loading