Beispiel #1
0
def spatiofreq2_season(s,lat,lon,yrs,eventkeys,figno=1,season='coreseason',\
     key='noaa-olr-0-all',flagonly=False,file_suffix='test',savefig=False,\
     fontdict=False):
    '''spatiofreq2_season(s,lat,lon,yrs,figno=1,season='coreseason',\
                          flagonly=False,file_suffix='test')
    Produces subplots of cloud-band gridpoint count by month
    '''
    if not fontdict: fd = {'fontsize': 14, 'fontweight': 'bold'}
    else: fd = fontdict
    mbkl = key.split('-')
    if mbkl[0] == 'noaa': dclim = (1, 9, 1)
    if mbkl[0] == 'hadam3p': dclim = (1, 11, 1)

    if isinstance(season, str):
        if season == 'coreseason': mns = [10, 11, 12, 1, 2, 3]
        elif season == 'fullseason':
            mns = [8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7]
    elif isinstance(season, list):
        mns = season
    m, f = blb.SAfrBasemap(lat[4:-7],lon[3:-2],drawstuff=True,prj='cyl',\
           fno=figno,rsltn='l',fontdict=fd)
    if len(mns) == 12:
        plt.close()
        plt.figure(figsize=[12, 10])
    elif len(mns) == 6:
        plt.close()
        plt.figure(figsize=[13, 8])
    cnt = 1
    msklist = []
    for mn in mns:
        if len(mns) == 12: plt.subplot(4, 3, cnt)
        elif len(mns) == 6: plt.subplot(3, 2, cnt)
        if flagonly:
            allmask=stats.spatiofreq2(m,s,lat,lon,yrs,eventkeys,\
                    clim=(1.,9.,1.),month=mn,flagonly=True,fontdict=fd)
        else:
            allmask=stats.spatiofreq2(m,s,lat,lon,yrs,eventkeys,clim=dclim,\
                                      month=mn,flagonly=False,fontdict=fd)
        if cnt % 2 == 0:
            syp.redrawmap(m,
                          lns=True,
                          resol='verylow',
                          parallel=False,
                          fontdict=fd)
        else:
            syp.redrawmap(m, lns=True, resol='verylow', fontdict=fd)
        cnt += 1
        msklist.append(allmask)
        my.xtickfonts()
        my.ytickfonts()
    plt.subplots_adjust(left=0.05,right=0.92,top=0.97,bottom=0.02,\
                        wspace=0.02,hspace=0.1)
    if savefig:
        if flagonly:
            plt.savefig(stats.figdir + file_suffix + '_flagonly.png', dpi=150)
        else:
            plt.savefig(stats.figdir + file_suffix + '.png', dpi=150)

    return msklist
Beispiel #2
0
def quickplot(m,
              rain,
              rlat,
              rlon,
              reftime,
              maskval=0.0,
              clim=[0, 50],
              wait=1,
              saveto=False):
    plt.ion()
    plt.show()
    if isinstance(rain, np.ma.MaskedArray):
        msk = (rain.data <= maskval) | erainm.mask
        rainm = np.ma.MaskedArray(rain.data, mask=msk, dtype=np.float32)
    else:
        msk = (rain <= maskval) | np.isnan(rain)
        rainm = np.ma.MaskedArray(rain, mask=msk, dtype=np.float32)
    #m, f = blb.SAfrBasemap(np.arange(-38,-18),np.arange(10,40),drawstuff=True,prj='cyl',fno=1,rsltn='l')
    #m, f = blb.SAfrBasemap(rlat,rlon,drawstuff=True,prj='cyl',fno=1,rsltn='l')
    for i in xrange(rainm.shape[1]):
        rdata = rainm[:, i]
        if reftime == 'season': ttl = mndict[season[i]]
        else: ttl = str(reftime[i])
        if not np.any(~rdata.mask):
            print 'NOTHING TO SHOW'
            #m.scatter(rlon,rlat,15,rainm[:,i],cmap=plt.cm.OrRd,edgecolor='none');plt.clim(0,50)
            syp.redrawmap(m, lns=True, resol='hi')
            plt.text(22,
                     -28,
                     'NOTHING TO VALID SHOW',
                     fontsize=20,
                     rotation=25)
            plt.title(ttl)
            plt.draw()
            sleep(wait)
            plt.clf()
            continue
        #rdata=np.where(rdata<1,np.nan,rdata)
        #m.scatter(rlon,rlat,15,rainw[:,i],cmap=plt.cm.OrRd,edgecolor='none');plt.clim(0,50)#;plt.colorbar()
        #print np.any(~np.isnan(rdata.data))
        m.scatter(rlon, rlat, 5, rdata, cmap=my.goodraincm(), edgecolor='none')
        plt.clim(clim)
        plt.colorbar()
        syp.redrawmap(m, lns=True, resol='hi')
        plt.title(ttl)
        plt.draw()
        sleep(wait)
        plt.clf()
        if saveto:
            fname = figdir + saveto + '_' + ttl + '.png'
            plt.savefig(fname, dpi=150)
Beispiel #3
0
def projectrainmask_in2_rawdata(rainmasks,
                                rawrain,
                                rawhrtime,
                                flagdetail,
                                everywhere=False):
    '''projectrainmask_in2_rawdata(rainmask,rawrain)

    Usage: rainmask would be output from SynopticPlot.multirainmasks
           rawrain is for example WRC time x stations data'''
    erain, etime, ekeys, flagarr = rainmasks['rain']
    # SUBSET DATA FURTHER IF SPECIFY FLAGDETAILS
    ixsub = syp.flagdetailsub(flagarr, ekeys, flagdetail)
    if len(ixsub) > 0:
        erain, etime, ekeys, flagarr = erain[
            ixsub, :], etime[ixsub], ekeys[ixsub], flagarr[ixsub, :]
    # CORE OF THE FUNCTION
    erain = erain.T
    projdata = rawrain.copy()
    projmsk = np.ones(projdata.shape, dtype=np.bool)
    for i in xrange(rawhrtime.shape[0]):
        ix = np.where(etime == rawhrtime[i])[0]
        if len(ix) == 0:  # NO TIME MATCHES
            continue
        elif len(ix) > 4:  # NUMEROUS TIME MATCHES IN MULTIPLE EVENTTRACKS
            iux, ix_iux = np.unique(ekeys[ix], return_index=True)
            #print ekeys[ix[ix_iux]]
            masklist = []
            for index in ix_iux:
                if everywhere and np.any(~erain.mask[:, ix[index]]):
                    erain.mask[:, ix[index]][:] = False
                #print ekeys[ix[index]]
                projmsk[:,
                        i] = ~((~projmsk[:, i]) | (~erain.mask[:, ix[index]]))
        else:  # STANDARD EXPECTED FOR 4 TIME MATCHES (REASON IS HAVE 4 TIME DAILY TIMESTEPPING DUE TO NCEP SO FILL UP THESE STEPS FOR DAILY VARIABLES SUCH AS RAINFALL)
            ixt = ix[0]
            if everywhere and np.any(~erain.mask[:, ixt]):
                erain.mask[:, ixt][:] = False
            projmsk[:, i] = erain.mask[:, ixt]

    projected = np.ma.MaskedArray(projdata, mask=projmsk, dtype=np.float32)

    return projected
Beispiel #4
0
def quicksubplot(m,
                 rain,
                 rlat,
                 rlon,
                 reftime,
                 maskval=0.0,
                 clim=[0, 50, 5],
                 wait=1,
                 saveto=False):
    plt.ion()
    plt.show()
    mycm = my.goodraincm()
    #mycm=plt.cm.gray_r
    mycm = plt.cm.jet
    if isinstance(rain, np.ma.MaskedArray):
        msk = (rain.data <= maskval) | erainm.mask
        rainm = np.ma.MaskedArray(rain.data, mask=msk, dtype=np.float32)
    else:
        msk = (rain <= maskval) | np.isnan(rain)
        rainm = np.ma.MaskedArray(rain, mask=msk, dtype=np.float32)
    #m, f = blb.SAfrBasemap(np.arange(-38,-18),np.arange(10,40),drawstuff=True,prj='cyl',fno=1,rsltn='l')
    #m, f = blb.SAfrBasemap(rlat,rlon,drawstuff=True,prj='cyl',fno=1,rsltn='l')
    for i in xrange(rainm.shape[1]):
        if reftime == 'season':
            ttl = mndict[season[i]]
            exec('plt.subplot(3,4,' + str(i + 1) + ')')
        elif reftime == 'coreseason':
            ttl = mndict[coreseason[i]]
            exec('plt.subplot(2,3,' + str(i + 1) + ')')
        else:
            ttl = str(reftime[i])
            exec('plt.subplot(3,4,' + str(i + 1) + ')')

        rdata = rainm[:, i]
        if not np.any(~rdata.mask):
            print 'NOTHING TO SHOW'
            #m.scatter(rlon,rlat,15,rainm[:,i],cmap=plt.cm.OrRd,edgecolor='none');plt.clim(0,50)
            syp.redrawmap(m)  #,lns=True,resol='hi')
            plt.text(22, -28, 'NOTHING TO VALID SHOW', fontsize=5, rotation=25)
            plt.title(ttl)
            plt.draw()
            sleep(wait)
            continue
        #rdata=np.where(rdata<1,np.nan,rdata)
        #m.scatter(rlon,rlat,15,rainw[:,i],cmap=plt.cm.OrRd,edgecolor='none');plt.clim(0,50)#;plt.colorbar()
        #print np.any(~np.isnan(rdata.data))
        m.scatter(rlon, rlat, 5, rdata, cmap=mycm, edgecolor='none')
        plt.clim(clim[:2])
        syp.redrawmap(m)  #,lns=True)
        plt.title(ttl)
        plt.subplots_adjust(left=0.05,
                            right=0.88,
                            top=0.95,
                            bottom=0.02,
                            wspace=0.02,
                            hspace=0.1)
        if i == 3:
            #f=plt.gcf()
            im_col = plt.gci()
            #bounds = np.arange(clim[0],clim[1],1)
            #axcol = f.add_axes([0.90,0.2,0.015,0.5])
            #plt.colorbar(mappable=im_col,cax=axcol,boundaries=bounds)
    f = plt.gcf()
    bounds = np.arange(clim[0], clim[1] + clim[2], clim[2])
    axcol = f.add_axes([0.90, 0.15, 0.015, 0.6])
    plt.colorbar(mappable=im_col, cax=axcol, boundaries=bounds)
    plt.draw()
    sleep(wait)
    #plt.clf()
    if saveto:
        fname = figdir + saveto + '.png'
        plt.savefig(fname, dpi=150)