Exemplo n.º 1
0

                        else:
                            print 'NO sample FILE AVAILABLE for ' + dset2 + '_' + name2
                            print 'Moving to next model....'
                            cnt += 1

                print "Finalising plot..."
                plt.subplots_adjust(left=0.05,right=0.9,top=0.95,bottom=0.02,wspace=0.2,hspace=0.2)
#                plt.subplots_adjust(left=0.05,right=0.9,top=0.95,bottom=0.02,wspace=0.1,hspace=0.2)


                # Plot cbar
                axcl = g.add_axes([0.94, 0.15, 0.01, 0.6])
                cbar = plt.colorbar(cs, cax=axcl)
                my.ytickfonts(fontsize=10.)

                # Save
                if ctyp == 'anom_mon' or ctyp=='anom_seas':
                    if agtest:
                        cstr=ctyp+'_agtest_'+str(perc_ag)
                    else:
                        cstr = ctyp
                else:
                    cstr=ctyp

                if manntest:
                    cstr=cstr+'manntest_'+str(alphaFDR)

                compname = figdir + 'multi_comp_' + cstr + '.' + sample + '.' + type + '.' + globv + \
                           '.' + choosel + '.' + sub + '.day_'+str(edays[lo])+'.'+thname+'.png'
Exemplo n.º 2
0
                            print 'NO sample FILE AVAILABLE for ' + dset2 + '_' + name2
                            print 'Moving to next model....'
                            cnt += 1

                print "Finalising plot..."
                plt.subplots_adjust(left=0.05,
                                    right=0.9,
                                    top=0.95,
                                    bottom=0.02,
                                    wspace=0.1,
                                    hspace=0.2)

                # Plot cbar
                axcl = g.add_axes([0.91, 0.15, 0.01, 0.6])
                cbar = plt.colorbar(cs, cax=axcl)
                my.ytickfonts(fontsize=12.)

                # Save
                if ctyp == 'anom_mon':
                    if agtest:
                        cstr = ctyp + '_agtest_' + str(perc_ag)
                    else:
                        cstr = ctyp
                else:
                    cstr = ctyp
                if lag:
                    compname = compdir + 'multi_comp_' + cstr + '.' + sample + '.' + type + '.' + globv + \
                               '.' + choosel[l] + '.' + sub + '.from_event' + from_event + '.lag_'+str(edays[lo])+'.png'
                else:
                    compname = compdir + 'multi_comp_'+cstr+'.'+sample+'.' + type + '.' + globv + \
                          '.'+choosel[l]+'.'+sub+'.from_event'+from_event+'.png'
                        top=0.95,
                        bottom=0.1,
                        wspace=0.2,
                        hspace=0.2)

    # Plot labels a to d
    for lab in range(len(labels)):
        xloc = labpos[lab, 0]
        yloc = labpos[lab, 1]
        thislab = labels[lab]
        plt.figtext(xloc, yloc, thislab, fontsize=14, fontweight='bold')

    # Add cbar for cv
    axcol2 = g.add_axes([0.58, 0.06, 0.38, 0.015])
    plt.colorbar(cs, cax=axcol2, orientation='horizontal')
    my.ytickfonts(fontsize=12., fontweight='normal')

    # Add cbar for spatio freq
    axcol1 = g.add_axes([0.07, 0.53, 0.38, 0.015])
    clim = nos4cbar[:]
    bounds = np.arange(clim[0], clim[1] + clim[2], clim[2])
    plt.colorbar(img,
                 cax=axcol1,
                 orientation='horizontal',
                 boundaries=bounds,
                 extend='both')
    my.ytickfonts(fontsize=12., fontweight='normal')

    figname = figdir + '/CBvar_4panelfig.' + seas + '.' + res + '.' + sub + '.per_' + rate + '.' + \
              thnames[t] + '.png'
    print 'saving figure as ' + figname
Exemplo n.º 4
0
def spatiofreq6(m,chs,modname,lat,lon,yrs,per='year',\
                clim=(4,36,4),savefig=False,\
                col='col',cbar='ind',title=''):
    '''Get grid-cell frequencies for no. of times a grid-cell falls within a
       contour describing a feature from metblobs.
       spatiofreq6 is new version by RJ designed to read in subsets of events
       designed for plotting within a multipanel plot

       Need to first run SubSet_Events.evset_info to get chs

       per is used to determine if it's plotting per year or per CBs in this model

       If a subset of month or season is required, input only those cbs

    USAGE: if cbar='ind' will make it for just this plot
           if cbar='set' will make it at right assuming multipanel
           title can be string or variable e.g. modname '''

    allmask = np.zeros((lat.shape[0], lon.shape[0]), dtype=np.float32)

    nblobs = len(chs)
    print 'Running spatiofreq on ' + str(nblobs) + ' CBs '

    for bl in range(nblobs):
        this_ch = chs[bl]
        mask = my.poly2mask(lon, lat, this_ch)
        allmask = allmask + np.float32(mask)

    if col == 'col':
        cm = plt.cm.magma
    elif col == 'bw':
        cm = plt.cm.gist_gray_r

    if per == 'year':
        std_mask = allmask / len(yrs)
    elif per == 'cbs':
        std_mask = allmask / nblobs * 100
        print 'Dividing by number of blobs'
        print nblobs

    ## NEED TO DO THIS SINCE PCOLOR IS NOT SHADING VALUES OUTSIDE OF THE CLIMS
    cstd_mask = np.where(std_mask > clim[1], clim[1], std_mask)
    cstd_mask = np.where(cstd_mask < clim[0], clim[0], cstd_mask)
    # Plot pcolor
    pcolmap = m.pcolormesh(lon, lat, cstd_mask, cmap=cm, zorder=1)
    img = plt.gci()  # gets a reference for the image

    plt.clim(clim[0], clim[1])  # sets color limits of current image
    bounds = np.arange(clim[0], clim[1] + clim[2], clim[2])
    if savefig:
        f, ax = plt.gcf(), plt.gca()
        axcol = f.add_axes([0.93, 0.2, 0.02, 0.6])
        plt.colorbar(mappable=img, cax=axcol, boundaries=bounds)
        my.ytickfonts()
        plt.ylabel('grid-point count / year', fontdict=fd)
        plt.axes(ax)
        fname = '/FootprintFreqencygray-' + modname + '.png'
        plt.savefig(fname, dpi=150)
    else:
        f, ax = plt.gcf(), plt.gca()  # get reference and set axes
        if cbar == 'set':
            axcol = f.add_axes([0.91, 0.15, 0.01, 0.6])
            plt.colorbar(cax=axcol, boundaries=bounds)
        elif cbar == 'ind':
            plt.colorbar()
        my.ytickfonts(fontsize=10, fontweight='demibold')
        if per == 'year':
            if cbar == 'set':
                plt.ylabel('grid-point count / year', fontsize=10)
        elif per == 'cbs':
            if cbar == 'set':
                plt.ylabel('% of cbs covering gridbox', fontsize=10)
        plt.axes(ax)
        plt.title(title, fontsize=8, fontweight='demibold')

    return std_mask, img
Exemplo n.º 5
0
                    print '...OLR data missing for this model?'

        print "Finalising plot..."
        plt.subplots_adjust(left=0.05,
                            right=0.9,
                            top=0.95,
                            bottom=0.02,
                            wspace=0.1,
                            hspace=0.2)

        # Plot cbar
        axcl = g.add_axes([0.94, 0.15, 0.01, 0.6])
        clim = nos4cbar[:]
        bounds = np.arange(clim[0], clim[1] + clim[2], clim[2])
        cbar = plt.colorbar(img, cax=axcl, boundaries=bounds, extend='both')
        my.ytickfonts(fontsize=8.)

        # Final stuff
        figsuf = ''

        if group:
            figsuf = figsuf + 'grouped.'

        if test_scr:
            figsuf = figsuf + 'testmodels.'

        if res == 'make':
            resnm = res + str(gsize)
        else:
            resnm = res
    cnt += 1

plt.subplots_adjust(left=0.05,
                    right=0.8,
                    top=0.95,
                    bottom=0.02,
                    wspace=0.1,
                    hspace=0.2)

if pluscon:

    # Plot cbar
    axcl = w.add_axes([0.83, 0.15, 0.01, 0.6])
    cbar = plt.colorbar(cs1, cax=axcl)
    my.ytickfonts(fontsize=8., fontweight='demibold')

    if not test_scr:
        axcl = w.add_axes([0.91, 0.15, 0.01, 0.6])
        cbar = plt.colorbar(cs2, cax=axcl)
        my.ytickfonts(fontsize=8., fontweight='demibold')

if pluscon:
    vfname = var + '_' + globv_c
else:
    vfname = var

# Save
cstr = ctyp

figsuf = ''