Esempio n. 1
0
# Make some strings
print("Data Loaded in %.2fs" % (time.time() - loadstart))

bbm = [-100, 40, -20, 90]  # Mapping bbox
#%% Plot Bounding Box

fig, ax = plt.subplots(1,
                       1,
                       subplot_kw={'projection': ccrs.PlateCarree()},
                       figsize=(4, 4))
ax = viz.init_map([-100, 40, -20, 90], ax=ax)
lwb = 1.5

ax, l1 = viz.plot_box(bbox_SP,
                      ax=ax,
                      color='b',
                      return_line=True,
                      leglab='SPG',
                      linewidth=lwb)
ax, l2 = viz.plot_box(bbox_ST,
                      ax=ax,
                      color='r',
                      return_line=True,
                      leglab='STG',
                      linewidth=lwb)
ax, l4 = viz.plot_box(bbox_TR,
                      ax=ax,
                      color=[0, 1, 0],
                      return_line=True,
                      leglab='TRO',
                      linewidth=lwb)
ax, l4 = viz.plot_box(bbox_NA,
    [73, 161, 68],
    [154, 219, 232],
    [251, 237, 79],
    [81, 135, 195],
    [138, 39, 113],
]) / 255
cmapn = (mpl.colors.ListedColormap(regioncolors))

cmap = cm.get_cmap("jet", nclusters)

testmap = np.array(test[0])[0, :, :]

fig, ax = plt.subplots(1, 1, subplot_kw={'projection': ccrs.PlateCarree()})
ax = viz.add_coast_grid(ax)
pcm = ax.pcolormesh(lon5, lat5, testmap[:, :], cmap=cmap)
ax = viz.plot_box([150, 179, 5, 50], ax=ax, leglab="1: Northwest Pacific")
ax = viz.plot_box([280 - 360, 350 - 360, 20, 45], ax=ax, leglab="2: ST N. Atl")
ax = viz.plot_box([300 - 360, 360 - 360, 50, 75], ax=ax, leglab="3: SP N. Atl")
ax = viz.plot_box([200 - 360, 250 - 360, 0, 35],
                  ax=ax,
                  leglab="4: East Pacific")
ax = viz.plot_box([50, 105, -30, 15],
                  ax=ax,
                  leglab="5: Indian-South Pacific Ocean")
ax = viz.plot_box([280 - 330, 360 - 360, -50, -20],
                  ax=ax,
                  leglab="6: South Atlantic")
fig.colorbar(pcm, ax=ax)

#ax.legend()
# Dictionary of Bounding Boxes to search thru
fig, axs = plt.subplots(2, 1, subplot_kw={'projection': proj}, figsize=(4, 5))

tests = [test, test1]
names = ['Before', 'After']
for a, t in enumerate(tests):

    ax = axs.flatten()[a]

    ax = viz.add_coast_grid(ax)
    clusterPIC = tests[a]
    pcm = ax.pcolormesh(lon5,
                        lat5,
                        t,
                        cmap=cmapn,
                        transform=ccrs.PlateCarree())
    ax = viz.plot_box(bbtest, ax=ax)
    ax = viz.plot_box(bbtest2, ax=ax, color='r')

    fig.colorbar(pcm, ax=ax, fraction=0.025)
    ax.set_title("CESM-PiC Clusters (TEST)")

plt.suptitle("Shifting Pattern Downwards \n Pattern Correlation = %.3f" % R)
#plt.tight_layout()
plt.savefig("%sTEST_%s_Clusters_Shift.png" % (outfigpath, expname),
            dpi=200,
            bbox_inches='tight')

#plt.savefig("%sTEST2_%s_Clusters.png"%(outfigpath,expname),dpi=200,bbox_inches='tight')

#%% Try Multiplying all boxes by some value
Esempio n. 4
0
        # Restrict to Ensemble,PC,month
        varplot = varin[e,:,:,N]
        
        varexp1  = np.nanmean(varexp[e,...,N])
       
        # Decide on Row or Column
        if e%6 == 0:
            colid = 0
        else:
            colid += 1
        rowid = int(np.fix(e/6))
        
        # Create Plot
        ax = axs[rowid,colid]
        ax = plot_regression(varplot,lon,lat,ax=ax,cint=cint,cbar=False)
        ax = viz.plot_box(eapbox,ax=ax)
        
        # Sum values to check for sign (transpose to lon x lat for format)
        #rsum = proc.sel_region(varplot.T,lon,lat,ebx,reg_sum=1)
        
        #asum,lor,lar = proc.sel_region(varplot.T,lon,lat,ebx,reg_sum=0)
        #chk  = rsum > 0 # set to 1 if it needs to be flipped
        
        #print("row %i col %i e%i"%(rowid,colid,e+1)) d

        ax.set_title("Ens%02d %.2f"%(e+1,varexp1*100) + r"%")
        #ax.set_title("Ens%02d %i"%(e+1,chk))
    plt.tight_layout()
    plt.savefig("%s%sPattern_PC%i_%sAvg_naotype%i.png" % (outpath,patname,N+1,meanname,naotype),dpi=200)
    print("Finished PC %i" % (N+1))
        
Esempio n. 5
0
fig, ax = plt.subplots(1,
                       1,
                       subplot_kw={'projection': ccrs.PlateCarree()},
                       figsize=(4, 3))
ax = viz.init_map(bbox, ax=ax)
pcm = ax.contourf(lonr, latr, invar.T, cint, cmap=cmap)
cl = ax.contour(lonr, latr, invar.T, cint, colors="k", linewidths=0.5)
#ax.clabel(cl,fmt="%i",fontsize=8)
ax.add_feature(cfeature.LAND, color='w')
#Add Natl Plot
lwb = 1.5
bbox_NA = [-80, 0, 0, 65]
ax, l4 = viz.plot_box(bbox_NA,
                      ax=ax,
                      color='k',
                      return_line=True,
                      leglab='NAT',
                      linewidth=lwb,
                      linestyle="solid")

ax.set_title("$MLD_{max}$", fontsize=12)
plt.colorbar(pcm, ax=ax, orientation='horizontal', fraction=0.040, pad=0.05)
plt.savefig(outpath + "MLD_Max.png", dpi=200)

#%% Make plot for EAP + NAO Forcing

bbox = [-80, 0, 0, 90]
cint = np.arange(-50, 55, 5)
cmap = cmocean.cm.balance

fig, ax = plt.subplots(1,
Esempio n. 6
0
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)
#ax.legend([l1,l2,l3,l4],labels=regions,ncol=4,bbox_to_anchor=(-0.1, 1.1),loc='upper left')

outname = '%sHadISST_AMVpattern_%s-%s_dtmethod%i.png' % (outpath,startyr,hyr[0,-1],method)
plt.savefig(outname, bbox_inches="tight",dpi=200)

#%% Mini HadiSST AMV Plot NAT