예제 #1
0
 for i in range(nclusters):
     cid = i+1
     ax.axvline([-100],lw=5,color=regioncolors[i],label="Cluster %i, s = %.3f"%(cid,new_sbyclust[i]))
 ax.legend(fontsize=10)
 ax.set_xticks(np.arange(-.2,.6,.1))
 ax.set_xlim([-.25,.6])
 plt.savefig("%sCESM1PIC_%s_SilhouettePlot_k%s%i_%s.png"%(outfigpath,expname,kmode,ii,yearstr),dpi=200,bbox_inches='tight')
 
 # Plot 2: the silhoutte value map
 cmap="RdBu_r"
 silmap = np.zeros(nlat5*nlon5)*np.nan
 silmap[okpts] = s_in
 silmap = silmap.reshape(nlat5,nlon5)
 proj = ccrs.PlateCarree(central_longitude=180)
 fig,ax = plt.subplots(1,1,subplot_kw={'projection':proj})
 ax     = viz.add_coast_grid(ax)
 pcm=ax.pcolormesh(lon5,lat5,silmap,vmin=-.5,vmax=.5,cmap=cmap,transform=ccrs.PlateCarree())
 ax.contour(lon5,lat5,silmap,levels=[0],colors='k',linewidths=0.75,linestyles=":",transform=ccrs.PlateCarree())
 #ax.pcolormesh(lon5,lat5,silmap,vmin=-.5,vmax=.5,cmap=cmocean.cm.balance,transform=ccrs.PlateCarree())
 fig.colorbar(pcm,ax=ax,fraction=0.025)
 ax.set_title("Silhouette Values for CESM-PiC Clusters (Year %s) \n $s_{avg}$ = %.3f" % (yearstr,s_in.mean()))
 plt.savefig("%sCESM1PIC_%s_SilhouetteMap_k%s%i_%s.png"%(outfigpath,expname,kmode,ii,yearstr),dpi=200,bbox_inches='tight')
 
 # Plot 3: the clustering result
 fig,ax = plt.subplots(1,1,subplot_kw={'projection':proj})
 ax     = viz.add_coast_grid(ax)
 pcm=ax.pcolormesh(lon5,lat5,clusternew,cmap=cmapn,transform=ccrs.PlateCarree())
 fig.colorbar(pcm,ax=ax,fraction=0.025)
 ax.set_title("CESM-PiC Clusters (Year %s)" % (yearstr))
 plt.savefig("%sCESM1PIC_%s_ClustersMap_k%s%i_%s.png"%(outfigpath,expname,kmode,ii,yearstr),dpi=200,bbox_inches='tight')
 
예제 #2
0
    constrained_layout=True,
    subplot_kw={'projection': ccrs.PlateCarree(central_longitude=0)})

for i in tqdm(range(12)):

    ax = axs.flatten()[i]
    im = loopmon[i]

    blabel = [0, 0, 0, 0]
    if i % 3 == 0:
        blabel[0] = 1
    if i > 8:
        blabel[-1] = 1

    # Add coastline, Month Title
    ax = viz.add_coast_grid(ax, bboxplot, blabels=blabel)
    ax.set_title(mons3[im])

    # Get plotting variable
    plotvar = rhovalues[imsk][plotmcf][plotlag, plotmon, :, :]
    plotmsk = rmasks[plotmon, plotlag, :, :, plotmcf, imsk]

    # Flip Longitude
    lon1, plotvar1 = proc.lon360to180(lon, plotvar.T)
    _, plotmsk1 = proc.lon360to180(lon, plotmsk.T)
    #_,plotmsk1    = proc.lon360to180(lon,limask.T)

    plotvar1 *= limask180
    plotmsk1 *= limask180

    pcm = ax.contourf(lon1,
예제 #3
0
        proj = ccrs.PlateCarree(central_longitude=180)

        fig, axs = plt.subplots(2,
                                1,
                                subplot_kw={'projection': proj},
                                figsize=(12, 6),
                                constrained_layout=True)

        cint = np.arange(-vlm, vlm + cstep, cstep)
        for i in range(2):
            ax = axs[i]
            blabel = [1, 0, 0, 0]
            if i == 1:
                blabel[-1] = 1
            ax = viz.add_coast_grid(ax,
                                    bbox=bboxplot,
                                    fill_color='gray',
                                    blabels=blabel)

            ploteof = eofs[i][:, :, im, n]

            pcm = ax.pcolormesh(lon,
                                lat,
                                ploteof,
                                transform=ccrs.PlateCarree(),
                                cmap='cmo.balance',
                                vmin=-vlm,
                                vmax=vlm)

            cf = ax.contour(lon,
                            lat,
                            ploteof,
예제 #4
0
vlms = [0, 2]
cintsneg = np.arange(0, 1.2, .2)
cintspos = np.arange(1, 2.2, .2)

# Set up plot params
plt.style.use('default')
cmap = cmocean.cm.balance

# Next plot the results
fig, axs = plt.subplots(1,
                        2,
                        subplot_kw={'projection': ccrs.PlateCarree()},
                        figsize=(12, 4.5))

ax = axs[0]
ax = viz.add_coast_grid(ax, bbox=bboxplot)
pcm = ax.pcolormesh(lonr,
                    latr,
                    fullratio.T,
                    vmin=vlms[0],
                    vmax=vlms[-1],
                    cmap=cmap)
#pcm = ax.contourf(lonr,latr,fullratio.T,levels=cints,cmap=cmocean.cm.balance)
clp = ax.contour(lonr,
                 latr,
                 fullratio.T,
                 levels=cintspos,
                 colors="k",
                 linewidths=0.75)
ax.clabel(clp, fmt="%.1f")
cln = ax.contour(lonr,
예제 #5
0
invar = da['ts'].values
lon = da[lonname].values
lat = da[latname].values
times = da[tname].values
print("Data loaded in %.2fs" % (time.time() - st))

# Portion Below is taken from calc_ENSO_PIC.py VV ***********
eofall, pcall, varexpall = scm.calc_enso(invar, lon, lat, pcrem, bbox=bbox)

# Sanity Check
if debug:
    im = 0
    ip = 0
    proj = ccrs.PlateCarree(central_longitude=180)
    fig, ax = plt.subplots(1, 1, subplot_kw={'projection': proj})
    ax = viz.add_coast_grid(ax, bbox=bbox)
    pcm = ax.pcolormesh(lon,
                        lat,
                        eofall[:, :, im, ip],
                        vmin=-1,
                        vmax=1,
                        cmap='cmo.balance',
                        transform=ccrs.PlateCarree())
    cb = fig.colorbar(pcm,
                      ax=ax,
                      orientation='horizontal',
                      fraction=0.055,
                      pad=0.1)
    cb.set_label("SST Anomaly ($\degree C \sigma_{ENSO}^{-1}$)")
    ax.set_title("EOF %i, Month %i\n Variance Explained: %.2f" %
                 (ip + 1, im + 1, varexpall[im, ip] * 100) + "%")
예제 #6
0
        if i == 0:  # Set labels for left
            blabel[0] = 1
            ax.text(-0.28,
                    0.35,
                    '42-member \n Stdev. \n (%s, \n Lag %i)' %
                    (months[imon], ilag + 1),
                    va='bottom',
                    ha='center',
                    rotation='horizontal',
                    rotation_mode='anchor',
                    transform=ax.transAxes,
                    fontsize=14)

        ax = viz.add_coast_grid(ax,
                                bbox=bboxplot,
                                blabels=blabel,
                                fill_color='gray',
                                ignore_error=True)

        lon1, plotvar1 = proc.lon360to180(lon, plotvar.T)

        pcm = ax.contourf(lon1,
                          lat,
                          plotvar1.T,
                          levels=cints_all[i],
                          extend='both',
                          cmap=cmaps[i])
        ax.set_title(plotnames_fancy[i])
        fig.colorbar(pcm,
                     ax=ax,
                     fraction=0.045,
예제 #7
0
def make_figure():
    fig = plt.figure(figsize=figsize)
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax = viz.add_coast_grid(ax)
    return fig, ax
예제 #8
0
latf = 50
klon,klat = proc.find_latlon(lonf,latf,lon180,lat)
klon360,_ = proc.find_latlon(lonf+360,latf,lon,lat)


#%% Make some plots (Annual Heat Flux without the mask)
# -----------------------------------------------------
bboxplot = [-85,0,0,65]
proj = ccrs.PlateCarree()
fig,axs = plt.subplots(1,2,subplot_kw={'projection':proj})

clvls = np.arange(-40,41,1)

for i in range(2):
    ax = axs[i]
    ax = viz.add_coast_grid(ax,bbox=bboxplot)
    
    plotvar = dunmask[i].mean(-1)
    
    cf = ax.contourf(lon180,lat,plotvar.T,
                     levels=clvls,cmap=cmocean.cm.balance,transform=proj,
                     extend='both')
    ax.contour(lon180,lat,plotvar.T,levels=[0,1],colors='k')
    ax.set_title(mconfigs[i])
fig.colorbar(cf,ax=axs.flatten(),orientation='horizontal')

#%% Try to plot the cross and autocorrelation, monthly
# ----------------------------------------------------
model = 1
lagid = 1
proj = ccrs.PlateCarree()
예제 #9
0
lon180, NAO1 = proc.lon360to180(lon360, NAO1)
BOTHDJFM = NAO1[klon[:, None], klat[None, :], :].copy()
#%% Make input plot for Mixed layer Depth Range

invar = hclim.max(2) - hclim.min(2)
bbox = [-80, 0, 0, 80]
#cint = np.concatenate([np.arange(0,100,20),np.arange(100,1800,300)])
cint = [0, 25, 50, 100, 250, 500, 750, 1000, 1250, 1500]
cmap = cmocean.cm.dense

# Old Figsize was 5 x 4
fig, ax = plt.subplots(1,
                       1,
                       subplot_kw={'projection': ccrs.PlateCarree()},
                       figsize=(8, 5))
ax = viz.add_coast_grid(ax, bbox=bbox)
#ax = viz.init_map(bbox,ax=ax)
#pcm = ax.contourf(lonr,latr,invar.T,cint,cmap=cmap)
pcm = ax.pcolormesh(lonr, latr, invar.T, vmin=0, vmax=1500, cmap=cmap)
cl = ax.contour(lonr, latr, invar.T, cint, colors="k", linewidths=.75)
#cl = ax.contour(lonr,latr,invar.T,cint,colors="k",linewidths = 0.5)
ax.clabel(cl, fmt="%i", fontsize=9)
#ax.add_feature(cfeature.LAND,color='k')
#ax.set_title("$MLD_{max} - MLD_{min}$" + "\n 40-member Ensemble Average",fontsize=12)
ax.set_title("$MLD_{max} - MLD_{min}$" + "\n %s" % mconfig, fontsize=12)

plt.colorbar(pcm, ax=ax, orientation='horizontal', fraction=0.040, pad=0.10)
plt.savefig(outpath + "MLD_RangeDiff.png", dpi=200)

#%% MLD Maximum