Пример #1
0
    if plotseacycmag: # only for CanESM2 SST
        maxfld = np.max(plotflds,axis=0)
        maxidx = np.argmax(plotflds,axis=0)
        minfld = np.min(plotflds,axis=0)
        minfld2 = np.min(ma.masked_where(gctsoneyr==1,plotflds),axis=0)
        minidx = np.argmin(plotflds,axis=0)

        janfld = plotflds[0,:,:]
        julfld = plotflds[6,:,:]
        seacycmon = julfld - janfld

        seacycmag = maxfld - minfld
        # PLOT SEASONAL CYCLE MAG as a map
        figa,axs = plt.subplots(1,2)
        bm,pc = cplt.kemmap(seacycmon,lat,lon,cmin=cminscm,cmax=cmaxscm,cmap=cmap,
                                type=mtype,axis=axs[0],suppcb=1,lmask=1,flipmask=flipmask)
        axs[0].set_title('Jul - Jan')

        bm,pc = cplt.kemmap(seacycmag,lat,lon,cmin=cminscm,cmax=cmaxscm,cmap=cmap,
                                type=mtype,axis=axs[1],suppcb=1,lmask=1,flipmask=flipmask)
        axs[1].set_title('Max - Min')
        
        cbar_ax = figa.add_axes([.91,.25,.02,.5])
        figa.colorbar(pc,cax=cbar_ax)

        lons, lats = np.meshgrid(lon,lat)
        ## # PLOT MINIMUM GT: shouldn't get below freezing in the sea (GC=0)
        ## figb,axs = plt.subplots(1,1)
        ## bm,pc = cplt.kemmap(minfld2,lat,lon,cmin=238,cmax=308,cmap='blue2red_20',
        ##                         type=mtype,axis=axs,lmask=1,flipmask=flipmask)
        ## bm.contour(lons,lats,minfld2,levels=[273, 273],colors='k',linewidths='2',latlon=True)
Пример #2
0
#     pdf
#     standard dev


# # # ################## Make Figures #########################

#   Maps

# control ANN climo (whole timeseries)
#    GLOBE

plotfld = np.mean(anntsc, axis=0)

plt.figure()
cplt.kemmap(
    plotfld, lat, lon, type="sq", cmap=cmapclimo, cmin=cminclimo, cmax=cmaxclimo, title=field + " ANN mean " + casename
)
if printtofile:
    plt.savefig(field + "_ANNclimo_" + casename + ".pdf")
    plt.savefig(field + "_ANNclimo_" + casename + ".png")

#    POLE
plt.figure()
cplt.kemmap(
    plotfld, lat, lon, type="nh", cmap=cmapclimo, cmin=cminclimo, cmax=cmaxclimo, title=field + " ANN mean " + casename
)
if printtofile:
    plt.savefig(field + "_ANNclimo_" + casename + "_nh.pdf")
    plt.savefig(field + "_ANNclimo_" + casename + "_nh.png")

#   annual mean diffs, all sims
print fldcgclim.shape


lons, lats = np.meshgrid(lon, lat)


plotfldg = fldcgclim[2, :, :]  # test Jan sst
plotflds = fldcsclim[2, :, :]  # test Jan sicn
plotflds = ma.masked_where(plotflds <= 0, plotflds)

# fig = plt.figure()
# cplt.kemmap(plotfldg,lat,lon,cmin=cmincg,cmax=cmaxcg,cmap=cmapg)

fig2 = plt.figure()
bm, pc = cplt.kemmap(plotfldg, lat, lon, cmin=cmincnhg, cmax=cmaxcnhg, cmap=cmapg, type="nh")
# cf = bm.contour(lons,lats,plotflds,colors='k',latlon=True)
cplt.kemmap(plotflds, lat, lon, cmin=cmincs, cmax=cmaxcs, cmap=cmaps, type="nh", suppcb=1)
cf2 = bm.contour(lons, lats, plotflds, colors="k", latlon=True, linewidths="2", levels=[15, 15])


# fig3 = plt.figure()
# cplt.kemmap(plotflds,lat,lon,cmin=cmincs,cmax=cmaxcs,cmap=cmaps,type='nh')


months = con.get_mon()
title = casename + " " + fields + " and " + fieldg

fig3, spax = plt.subplots(2, 6)
fig3.set_size_inches(12, 6)
fig3.subplots_adjust(hspace=0, wspace=0)
Пример #4
0
lons, lats = np.meshgrid(lon,lat)
cmlen=15.
incr = (cmaxsp2-cminsp2) / (cmlen)
conts = np.arange(cminsp2,cmaxsp2+incr,incr)

ttl1=seasp + ' regress on ' + sear + ' BKS Z500'
ttl2=seasp + ' regress on ' + sear + ' Eur SAT' 

#ttl1=ttl2=''

fig,axs=plt.subplots(1,2)
fig.set_size_inches(10,5)
fig.subplots_adjust(wspace=0.05)
ax=axs[0]
bm,pc=cplt.kemmap(fldsponfldr,lat,lon,ptype='nheur',axis=ax,cmin=cminsp,cmax=cmaxsp,
                  title=ttl1,suppcb=True,
                  panellab='a',lcol='0.2')
bm.contour(lons,lats,fldsp2onfldr,levels=conts,
           colors='0.5',linewidths=1,latlon=True)

ax=axs[1]
bm,pc=cplt.kemmap(fldsponfldr2,lat,lon,ptype='nheur',axis=ax,cmin=cminsp,cmax=cmaxsp,
                  title=ttl2,suppcb=True,
                  panellab='b',lcol='0.2')

bm.contour(lons,lats,fldsp2onfldr2,levels=conts,
           colors='0.5',linewidths=1,latlon=True)

cplt.add_colorbar(fig,pc,orientation='horizontal')

if printtofile:
Пример #5
0
def plot_nc_agreement_map(ncdt, ax, lin='one',magtype='abs',cmin='',cmax='',cmind='',cmaxd='',cmin2='',cmax2='',
                           conv=1, ptype='nh',suppcb=False,cmap='blue2red_w20',subtime=None,
                           screen=False,vert=False,levlim=None,suppttl=False,addsig=False,sigtype='cont',
                           latlim=None,vertptype=None, fsz=None,plab=None):
    """ 
        cmin/cmax:  for ice
        
        lin = 'one' is ice and co2 (ICEcold, CO2hi)
            = 'two' is ice2 and co22 (ICEwarm, CO2lo)
            = 'sub' subtract lin 'one' from lin 'two' (shows how warm clim/low ice different from cold/high)
                    
        fsz: fontsize for title
                    
        returns: plot handle (ph) 
    """
    
    
    mag,magsign = calc_nc_agreement_map(ncdt, axs, lin=lin,magtype=magtype,
                           conv=1, subtime=None)
    
    
    # @@ subtime not implemented yet. assume average over full time 
    #tmplen = ncdt['2xco2preiice'].shape[0]-1
    fmt='%2.1f' # clabel format
    #if ctlconts!=None:
    #    if (ctlconts < 1.).any() and (ctlconts > -1.).any():
    #    #if np.logical_and((ctlconts<1).any(),(ctlconts>-1).any()):
    #        print ctlconts
    #        fmt='%2.1f'
    
    if lin=='one':
        suff=''
        suff1='cold'; suff2='hi'
    elif lin=='two':
        suff='2'
        suff1='warm'; suff2='lo'
    
        # pparams for ice!
    # pparams2 for co2![sum|full]
    if vert:
        pparams = {'cmin': cmin, 'cmax': cmax,
                   'suppcb': suppcb, 'screen': screen, 'cmap':cmap,'levlim':levlim,
                   'latlim':latlim,'ptype':vertptype}
    else:
        pparams = {'ptype': ptype, 'cmin': cmin, 'cmax': cmax,
                   'suppcb': suppcb, 'cmap':cmap}
    

    if suppttl: ttl=''
    else: ttl='ICE'+suff1 +' & CO2'+suff2
    if vert:
        ph = cplt.vert_plot(magsign,lev,lat,axis=ax,title=ttl,**pparams)
        #if addsig:
        #    cplt.addtsig(ax,icepv,lat,lev/100.,sigtype=sigtype,reverse=sigreverse)
        #if addclimcont:
        #    cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
    else:
        bm,ph = cplt.kemmap(magsign,lat,lon,axis=ax,title=ttl,**pparams)
        #if addsig:
        #    cplt.addtsigm(bm,icepv,lat,lon,sigtype=sigtype,reverse=sigreverse)
    if fsz!=None:
        ax.set_title(ttl,fontsize=fsz)
        if plab!=None:
            ax.annotate(plab, xy=(0.02,1.02),xycoords='axes fraction',
                       fontsize=fsz-1,fontweight='bold')

    
    
    return ph
Пример #6
0
def plot_nc_linearity_maps(ncdt, axs, lin='one',cmin='',cmax='',cmind='',cmaxd='',cmin2='',cmax2='',
                           conv=1, ptype='nh',suppcb=False,cmap='blue2red_w20',subtime=None,
                           screen=False,vert=False,levlim=None,suppttl=False,addsig=False,sigtype='cont',
                           latlim=None,vertptype=None,addclimcont=False,ctlconts=None,
                           nosum=False,nofull=False,nolin=False,scaledlin=False,ncicedt=None,sigreverse=False,
                           northof=0,fsz=None):
    """ 
        cmin/cmax:  for ice
        cmin2/cmax2: for co2 & sum & full, if given. otherwise same as ice
        cmind/cmaxd: for lin combo subtraction from full
        
        lin = 'one' is ice and co2 (ICEcold, CO2hi)
            = 'two' is ice2 and co22 (ICEwarm, CO2lo)
            = 'sub' subtract lin 'one' from lin 'two' (shows how warm clim/low ice different from cold/high)
            
        nosum: include ice+co2 panel or not?
        nofull: include Full panel or not?
        nolin: include non-linearity panel or not?
        scaledlin: is the non-linearity panel to be scaled or not?
        ncicedt: must be set if scaledlin=True!
        
        sigreverse: if True, plot hatching/contours where NOT significant on
                    every map but non-lin. (only if addsig=True)
        northof: compute pattern correlation b/w SUM and FULL north of this latitude.
        fsz: fontsize for title
                    
        returns: plot handles (ph,ph2[,phd]) (ice,co2|sum|full[,difference/nonlin])
    """
    
    
    # @@ subtime not implemented yet. assume average over full time 
    #tmplen = ncdt['2xco2preiice'].shape[0]-1
    fmt='%2.1f' # clabel format
    #if ctlconts!=None:
    #    if (ctlconts < 1.).any() and (ctlconts > -1.).any():
    #    #if np.logical_and((ctlconts<1).any(),(ctlconts>-1).any()):
    #        print ctlconts
    #        fmt='%2.1f'
    
    pico = ncdt['prei2xco2iceb']
    pipi = ncdt['preipreiice']
    copi = ncdt['2xco2preiice']
    coco = ncdt['2xco22xco2ice']
    lat = ncdt['lat']
    
    if lin=='one':
        _,icepv = cutl.ttest_ind(pico, pipi,axis=0,effdof=False)        
        ice = (np.mean(pico,axis=0) - np.mean(pipi,axis=0))*conv
        #icep = ncfldzmdt['pi2xco2ipulse'] - ncfldzmdt['preipreiice']    
        _,co2pv = cutl.ttest_ind(copi, pipi,axis=0,effdof=False)   
        co2 = (np.mean(copi,axis=0) - np.mean(pipi,axis=0))*conv
        _,combopv = cutl.ttest_ind(pico-pipi+(copi-pipi),
                                   coco-pipi)
        ctl = np.mean(pipi,axis=0)*conv
        
        suff=''
        suff1='cold'; suff2='hi'
    elif lin=='two':
        _,icepv = cutl.ttest_ind(coco, copi,axis=0,effdof=False)
        ice = (np.mean(coco,axis=0) - np.mean(copi,axis=0))*conv
        _,co2pv = cutl.ttest_ind(coco, pico,axis=0,effdof=False)
        co2 = (np.mean(coco,axis=0) - np.mean(pico,axis=0))*conv
        _,combopv = cutl.ttest_ind(coco-copi+(coco-pico),
                                   coco-pipi)
        ctl = np.mean(coco,axis=0)*conv
        suff='2'
        suff1='warm'; suff2='lo'
    elif lin=='sub':
        #two - one: (coco-copi) - (pico-pipi)
        _,icepv = cutl.ttest_ind(coco-copi, pico-pipi,axis=0,effdof=False)
        ice = (np.mean(coco-copi,axis=0) - np.mean(pico-pipi,axis=0))*conv
        #two - one: (coco-pico) - (copi-pipi)
        _,co2pv = cutl.ttest_ind(coco-pico, copi-pipi,axis=0,effdof=False)
        co2 = (np.mean(coco-pico,axis=0) - np.mean(copi-pipi,axis=0))*conv
        suff='2-1'
        suff1='warm-cold'; suff2='lo-hi'
        
        
    _,fullpv = cutl.ttest_ind(coco, pipi,axis=0,effdof=False)
    full = (np.mean(coco,axis=0) - np.mean(pipi,axis=0))*conv
    
    # compute pattern correlation b/w SUM and FULL
    prval,ppval = calc_linpatterncorr(ncdt,lin=lin,northof=northof,vert=vert)
    pvarexp = (prval**2)*100
    
    # pparams for ice!
    # pparams2 for co2![sum|full]
    if vert:
        lev = ncdt['lev']
        
        pparams = {'cmin': cmin, 'cmax': cmax,
                   'suppcb': suppcb, 'screen': screen, 'cmap':cmap,'levlim':levlim,
                   'latlim':latlim,'ptype':vertptype}
        if cmin2 != '':
            pparams2 = {'cmin': cmin2, 'cmax': cmax2,
                       'suppcb': suppcb, 'screen': screen, 'cmap':cmap,'levlim':levlim,
                       'latlim':latlim,'ptype':vertptype}
        else:
            pparams2 = {'cmin': cmin, 'cmax': cmax,
                       'suppcb': suppcb, 'screen': screen, 'cmap':cmap,'levlim':levlim,
                       'latlim':latlim,'ptype':vertptype}
    else:
        lon = ncdt['lon']
        
        pparams = {'ptype': ptype, 'cmin': cmin, 'cmax': cmax,
                   'suppcb': suppcb, 'cmap':cmap}
        if cmin2 != '':
            pparams2 = {'ptype': ptype, 'cmin': cmin2, 'cmax': cmax2,
                       'suppcb': suppcb, 'cmap':cmap}
        else:
            pparams2 = {'ptype': ptype, 'cmin': cmin, 'cmax': cmax,
                       'suppcb': suppcb, 'cmap':cmap}
    
    aii=0
    ax=axs[aii]
    if suppttl: ttl=''
    else: ttl='ICE'+suff1
    if vert:
        ph = cplt.vert_plot(ice,lev,lat,axis=ax,title=ttl,**pparams)
        if addsig:
            cplt.addtsig(ax,icepv,lat,lev/100.,sigtype=sigtype,reverse=sigreverse)
        if addclimcont:
            cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
    else:
        bm,ph = cplt.kemmap(ice,lat,lon,axis=ax,title=ttl,**pparams)
        if addsig:
            cplt.addtsigm(bm,icepv,lat,lon,sigtype=sigtype,reverse=sigreverse)
    if fsz!=None:
        ax.set_title(ttl,fontsize=fsz)
    aii+=1    
    
    ax=axs[aii]
    if suppttl: ttl=''
    else: ttl='CO2'+suff2
    if vert:
        ph2 = cplt.vert_plot(co2,lev,lat,axis=ax,title=ttl,suppylab=True,**pparams2)
        if addsig:
            cplt.addtsig(ax,co2pv,lat,lev/100.,sigtype=sigtype,reverse=sigreverse)
        if addclimcont:
            cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
    else:
        bm,ph2 = cplt.kemmap(co2,lat,lon,axis=ax,title=ttl,**pparams2)
        if addsig:
            cplt.addtsigm(bm,co2pv,lat,lon,sigtype=sigtype,reverse=sigreverse)
    if fsz!=None:
        ax.set_title(ttl,fontsize=fsz)
    aii+=1
    
    if not nosum:
        ax=axs[aii]
        if suppttl: ttl=''
        else: ttl='Sum' #ice'+suff1+'+co2'+suff2
        if vert:
            ph2 = cplt.vert_plot(ice+co2,lev,lat,axis=ax,title=ttl,suppylab=True,**pparams2)
            if addclimcont:
                cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
        else:
            bm,ph2 = cplt.kemmap(ice+co2,lat,lon,axis=ax,title=ttl,**pparams2)
        if fsz!=None:
            ax.set_title(ttl,fontsize=fsz)            
        aii+=1

    if not nofull:
        ax=axs[aii]
        if suppttl: ttl=''
        else: ttl='Full'
        if vert:
            ph2 = cplt.vert_plot(full,lev,lat,axis=ax,title=ttl,suppylab=True,**pparams2)
            if addsig:
                cplt.addtsig(ax,fullpv,lat,lev/100.,sigtype=sigtype,reverse=sigreverse)
            if addclimcont:
                cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
        else:
            bm,ph2 = cplt.kemmap(full, lat,lon,axis=ax,title=ttl,**pparams2)
            if addsig:
                cplt.addtsigm(bm,fullpv,lat,lon,sigtype=sigtype,reverse=sigreverse)
            ax.annotate('$%.0f$'%(pvarexp) + '%', xy=(0.78,0.98),xycoords='axes fraction',
                       fontsize=16)
        if fsz!=None:
            ax.set_title(ttl,fontsize=fsz)
        aii+=1    
    
    if not nolin:
        ax=axs[aii] # the linearity test
        # @@@ add scaledlin here @@@
        # e.g.  c1*ICEcold + c2*CO2hi - Full
        #       c1*(pico-pipi) + c2*(copi-pipi) - (coco-pipi)
        #       solve c1, c2 with sea ice s.t. above eqn would give 0
        # @@@ Question: how to scale? how to get c1,c2? Use difference from target sea ice?
        if scaledlin:
            # compute target offset
            offs = compute_targoffset(ncicedt,dosia=True)
            # want to be a fraction so div by 100.
            # and for ice comparisons, we don't reach target so we need to bump it up (add 1)
            c1 = offs['ice'+suff1]/100. + 1
            # for co2 comparison, not sure how to scale, b/c want to remove ice effect, which isn't a scaling?
            c2 = offs['co2'+suff2]/100.
    
        if suppttl: ttl=''
        else: ttl='Full-Sum' #ttl='(ice'+suff +'+co2'+suff+')-full'
        if cmind=='': # just divide the other clims by 2
            if vert:
                phd=cplt.vert_plot(full-(ice+co2),lev,lat,axis=ax,title=ttl,
                            cmin=cmin/2,cmax=cmax/2,suppcb=suppcb,screen=screen,cmap=cmap,
                            suppylab=True,levlim=levlim,latlim=latlim,ptype=vertptype)
                if addsig:
                    cplt.addtsig(ax,combopv,lat,lev,sigtype=sigtype)
                if addclimcont: # want in the linearity fig?? @@@@
                    cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
            else:
                bm,phd=cplt.kemmap(full-(ice+co2),lat,lon,axis=ax,title=ttl,ptype=ptype,
                            cmin=cmin/2,cmax=cmax/2,suppcb=suppcb,cmap=cmap)
                if addsig:
                    cplt.addtsigm(bm,combopv,lat,lon,sigtype=sigtype)
        else:
            if vert:
                phd=cplt.vert_plot(full-(ice+co2),lev,lat,axis=ax,title=ttl,
                            cmin=cmind,cmax=cmaxd,suppcb=suppcb,screen=screen,cmap=cmap,
                            suppylab=True,levlim=levlim,latlim=latlim,ptype=vertptype)
                if addsig:
                    cplt.addtsig(ax,combopv,lat,lev,sigtype=sigtype)
                if addclimcont: # want in the linearity fig?? @@@@
                    cplt.add_contoursvert(ax,ctl,lat,lev,verb=True,clab=True,conts=ctlconts,fmt=fmt)
            else:
                bm,phd=cplt.kemmap(full-(ice+co2),lat,lon,axis=ax,title=ttl,ptype=ptype,
                            cmin=cmind,cmax=cmaxd,suppcb=suppcb,cmap=cmap)
                if addsig:
                    cplt.addtsigm(bm,combopv,lat,lon,sigtype=sigtype)
        if fsz!=None:
            ax.set_title(ttl,fontsize=fsz)
    
        return ph,ph2,phd
    else:
        return ph,ph2