def plot_AMV_generals(lat,lon,amvpattern,vscale=1): """ Customized AMV Plot for Generals Presentation (for consistent plotting) Parameters ---------- lat : TYPE DESCRIPTION. lon : TYPE DESCRIPTION. amvpattern : [lon x alt] DESCRIPTION. vscale : INT Amt of times to scale AMV pattern by Returns ------- None. """ bbox = [-80,0 ,0,65] # Set up plot params plt.style.use('default') cmap = cmocean.cm.balance cints = np.arange(-.55,.60,.05) cintslb = np.arange(-.50,.6,.1) # Make the plot fig,ax = plt.subplots(1,1,figsize=(5,5),subplot_kw={"projection":ccrs.PlateCarree()}) ax,cb = viz.plot_AMV_spatial(amvpattern.T*vscale,lon,lat,bbox,cmap,cint=cints,ax=ax,fmt="%.2f",returncbar=True, fontsize=8) cb.set_ticks(cintslb) return fig,ax,cb
#% Make AMV Spatial Plots cmap = cmocean.cm.balance cmap.set_bad(color='yellow') #cint = np.arange(-1,1.1,0.1) #clab = cint fig, axs = plt.subplots(1, 4, figsize=(12, 1.5), subplot_kw={'projection': ccrs.PlateCarree()}) for mode in range(4): varin = np.transpose(amvpat[mode], (1, 0)) viz.plot_AMV_spatial(varin, lonr, latr, bbm, cmap, pcolor=0, ax=axs[mode]) axs[mode].set_title("MLD %s" % modelname[mode], fontsize=12) #plt.suptitle("AMV Pattern | Forcing: %s; fscale: %ix" % (forcingname[funiform],fscale),ha='center') #fig.tight_layout(rect=[0, 0.03, .75, .95]) outname = outpath + 'AMVpattern_%s_allmodels.png' % (expid) plt.savefig(outname, bbox_inches="tight", dpi=200) #%Make AMV Time Plots xlm = [24, 240] ylm = [-0.5, 0.5] #xtk = np.arange(xlm[0],xlm[1]+20,20) fig, axs = plt.subplots(1, 4, figsize=(12, 1.5)) for mode in range(4):
amvload = np.load("%sAMV_Region_%s.npz"%(outpathdat,expid),allow_pickle=True) amvsp15 = amvload['amvpat_region'].item()[region][model] # Contains [region][model] amvid15 = amvload['amvidx_region'].item()[region][model] #%% Make the plots i = 6 mult=1 fig,ax = plt.subplots(1,1,figsize=(5,5),subplot_kw={"projection":ccrs.PlateCarree()}) #ax = viz.init_map(bbox_NA,ax=ax) #pcm = ax.contourf(lonr,latr,amvsp[i].T,levels=cints,cmap=cmap) #fig.colorbar(pcm,ax=ax,fraction=0.05) ax,cb = viz.plot_AMV_spatial(amvsp15.T*mult,lonr,latr,bbox_NA,cmap,cint=cints,ax=ax,fmt="%.2f",returncbar=True) cb.set_ticks(cintslb) ax.set_title("AMV Pattern (NHFLXSTD)") plt.savefig(outpathfig+"AMV_Spatial_Pattern_%s_%s_runid%s.png"%(modelfname[model],"NHFLXSTD","203")) for i in range(5): if i == 1: mult= 10 else: mult = 1 fig,ax = plt.subplots(1,1,figsize=(5,5),subplot_kw={"projection":ccrs.PlateCarree()}) #ax = viz.init_map(bbox_NA,ax=ax) #pcm = ax.contourf(lonr,latr,amvsp[i].T,levels=cints,cmap=cmap)
cint = np.arange(-1, 1.1, 0.1) #clab = cint fig, axs = plt.subplots(1, 5, figsize=(15, 1.5), subplot_kw={'projection': ccrs.PlateCarree()}) for rid in range(nruns): print("Plotting for run %s" % runids[rid]) varplot = invar[rid, :, :].T viz.plot_AMV_spatial(varplot, lonr, latr, bbox, cmap, pcolor=0, cint=cint, ax=axs[rid], fmt="%.1f") axs[rid].set_title("run%s" % runids[rid], fontsize=12) outname = outpathfig + 'AMVpattern_runcomparison_%s.png' % (testid) plt.savefig(outname, bbox_inches="tight", dpi=200) # Plot autocorrelation for each forcing xtk = np.arange(0, 39, 3) for r in range(nregions): for modid in range(4): fig, ax = plt.subplots(1, 1, figsize=(6, 4)) accesm = cesmauto[r]
#clab = np.arange(-0.50,0.60,0.10) #cint = np.arange(-1,1.2,0.2) #cint = np.arange(-2,2.5,0.5) #cint = np.arange(-1,) #cint = np.arange(-2,2,0.2) #clab = cint for mode in hvarmode: print(mode) fig,ax = plt.subplots(1,1,figsize=(3,1.5)) plt.style.use("ggplot") varin = np.transpose(regr_meth2[mode],(1,0)) plt.subplot(1,4,mode+1) viz.plot_AMV_spatial(varin,lon,lat,bbox,cmap,pcolor=0) #viz.plot_AMV_spatial(varin,lon,lat,mbbox,cmap,cint,clab) #plt.title("AMV Spatial Pattern \n Model %s" % hvarnames[mode],fontsize=10) plt.title("Model %s" % hvarnames[mode],fontsize=12) outname = outpath+'AMVpattern_funiform%i_hvar%i_run%s.png' % (funiform,mode,runid) plt.savefig(outname, bbox_inches="tight",dpi=200) #%% Plot AMV FFor HADLISST startyr = 1900 # Same plot, but for HadlISST cmap = cmocean.cm.balance #cint = np.arange(-3.5,3.25,0.25) cint = np.arange(-0.8,1.0,0.2)
amvpat = amvsp[funiform] for region in range(4): #% Make AMV Spatial Plots cmap = cmocean.cm.balance cmap.set_bad(color='yellow') fig,axs = plt.subplots(1,4,figsize=(12,1.5),subplot_kw={'projection':ccrs.PlateCarree()}) for mode in range(4): print("Now on mode %i region %i f %i"% (mode,region,f)) varin = np.transpose(amvpat[region][mode],(1,0))*vscale #viz.plot_AMV_spatial(varin,lonr,latr,bbox,cmap,cint=cint,clab=clabs,pcolor=0,ax=axs[mode],fmt="%.1f",) viz.plot_AMV_spatial(varin,lonr,latr,bbox,cmap,cint=cint,labels=False,pcolor=0,ax=axs[mode],fmt="%.1f",) #axs[mode].set_title("MLD %s" % modelname[mode],fontsize=12) axs[mode].set_title("%s" % modelname[mode],fontsize=12) outname = outpathfig+'%s_AMVpattern_%s_allmodels_vscale%i.png' % (regions[region],expid,vscale) plt.savefig(outname, bbox_inches="tight",dpi=200) #%Make AMV Time Plots xlm = [24,240] ylm = [-0.5,0.5] #xtk = np.arange(xlm[0],xlm[1]+20,20) fig,axs = plt.subplots(1,4,figsize=(12,1.5)) for mode in range(4):
#bboxes = (bbox_SP,bbox_ST,bbox_TR,bbox_NA) regions = ("SPG","STG","TRO","NAT") bboxes = (bbox_SP,bbox_ST,bbox_TR,bbox_NA) #% Make AMV Spatial Plots cmap = cmocean.cm.balance cmap.set_bad(color='yellow') cint = np.arange(-.5,.6,0.1) #clab = cint fig,axs = plt.subplots(1,1,figsize=(6,4),subplot_kw={'projection':ccrs.PlateCarree()}) plt.style.use('ggplot') plotbbox = [-100,10,-5,80] varin = h_regr.T viz.plot_AMV_spatial(varin,hlon,hlat,plotbbox,cmap,cint=cint,pcolor=0,ax=axs) axs.set_title("HadISST AMV SST Pattern (%s to %s)" % (startyr,hyr[0,-1]),fontsize=14) scolors = ["black","cornflowerblue","crimson","gold"] # Add region plots ax = axs lwb = 1.5 ax,l4 = viz.plot_box(bbox_NA,ax=ax,color=scolors[0],return_line=True,leglab='NAT',linewidth=lwb,linestyle="solid") ax,l2 = viz.plot_box(bbox_ST,ax=ax,color=scolors[2],return_line=True,leglab='STG',linewidth=lwb) ax,l1 = viz.plot_box(bbox_SP,ax=ax,color=scolors[1],return_line=True,leglab='SPG',linewidth=lwb,linestyle='dashed') ax,l3 = viz.plot_box(bbox_TR,ax=ax,color=scolors[3],return_line=True,leglab='TRO',linewidth=lwb,linestyle='dashed') leg = ax.legend([l1,l2,l3,l4],labels=regions,ncol=4,bbox_to_anchor=(0, -0.1),loc='upper left') #leg(fancybox=True,shadow=True)