thre_str = str(thisthresh) # Find TTT data print 'Opening MetBot files...' botpath = botdir + dset + '/' + name + '/' outsuf = botpath + name + '_' mbsfile = outsuf + thre_str + '_' + dset + "-olr-0-0.mbs" syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' s = sy.SynopticEvents((), [syfile], COL=False) ks = s.events.keys() ks.sort() # all refkey = s.mbskeys[0] refmbs, refmbt, refch = blb.mbopen(mbsfile) # First do the processing that is going to apply to the whole figure # first day of event or all days? i.e. number of events or number of CBs # remove duplicate dates? # Get lots of info about event set print 'Getting more info about each cloud band...' dates, cXs, cYs, degs, chs, keys, daynos, tworecdt = sset.evset_info( s, refmbs, refmbt) # If wanting first day of event only, subset print 'Subset by first day?...' if from_event == 'first': print 'Selecting first day of event only' dates_d, cXs_d, cYs_d, degs_d, chs_d, keys_d, daynos_d, tworecdt_d = \
thisthresh = threshs[t] thre_str = str(int(thisthresh)) thname=thnames[t] print 'opening metbot files...' outsuf = botpath + name + '_' if future: outsuf=outsuf+'fut_rcp85_' syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' s = sy.SynopticEvents((), [syfile], COL=False) ks = s.events.keys(); ks.sort() # all refkey = s.mbskeys[0] mbsfile = outsuf + thre_str + '_' + dset + "-olr-0-0.mbs" refmbs, refmbt, refch = blb.mbopen(mbsfile) # Get lots of info about event set print 'Getting more info about each cloud band...' dates, cXs, cYs, degs, chs, keys, daynos, tworecdt = sset.evset_info(s,refmbs,refmbt) # Loop sample domain for o in range(len(sample_dom)): smp_dom = sample_dom[o] print "Running for sample " + smp_dom # Get sample dates_d,cXs_d, cYs_d, degs_d, chs_d, keys_d, daynos_d, tworecdt_d = \ sset.sample_arche_cbs(sample,smp_dom, dates,cXs, cYs, degs, chs, keys, daynos, tworecdt) # Find indices from var file
# Count ndays in composite with same sign as mean mask_zeros=np.zeros((nlat,nlon),dtype=np.float32) for i in range(nlat): for j in range(nlon): count=len(np.where(anoms_signs[:,i,j]==comp_signs[i,j])[0]) perc=(float(count)/float(nsamp))*100 if perc>=perc_ag: mask_zeros[i,j]=1 else: mask_zeros[i,j]=0 # Plot print "Plotting for model "+name2 plt.subplot(yplots,xplots,cnt) if wplotdraw=='all': m = blb.AfrBasemap2(lat, lon, latsp,lonsp, drawstuff=True, prj='cyl', rsltn='l',\ fontdict={'fontsize':8,'fontweight':'normal'}) elif wplotdraw=='first': if cnt==1: m = blb.AfrBasemap2(lat, lon, latsp, lonsp, drawstuff=True, prj='cyl', rsltn='l', \ fontdict={'fontsize': 8, 'fontweight': 'demibold'}) else: m = blb.AfrBasemap2(lat, lon, latsp, lonsp, drawstuff=False, prj='cyl', rsltn='l', \ fontdict={'fontsize': 8, 'fontweight': 'demibold'}) elif wplotdraw=='edges': x_remain= cnt % xplots if x_remain==1: m = blb.AfrBasemap2(lat, lon, latsp, lonsp, drawstuff=True, prj='cyl', rsltn='l', \ fontdict={'fontsize': 8, 'fontweight': 'normal'}) else: m = blb.AfrBasemap2(lat, lon, latsp, lonsp, drawstuff=True, prj='cyl', rsltn='l', \ fontdict={'fontsize': 8, 'fontweight': 'normal'},onlyedge='lon')
# Check if file exists for this model if onlynew: chfile = outsuf + thre_str + '_' + dset + '-OLR.synop' if os.path.isfile(chfile): print "MetBot already run on this model: " + name continue # goes back to the beginning of the for loop else: print "Running for the first time on: " + name plt.ion() ### Get mbs 0-0 if getmbs: v = dset + "-olr-0-0" daset, globv, lev, drv = v.split('-') mbs, mbt, chull = blb.MetBlobs_th(olr,dtime,time,lat,lon,v,thisthresh,\ sub=sub,showblobs=showblb,interact=intract,debugplots=debugplots) blb.mbsave(outsuf + thre_str + '_' + v + ".mbs", mbs, mbt, chull) del mbs, mbt, chull ### Get mbs 0-all if olrall: refmbsstr = dset + "-olr-0-0" refmbs, refmbt, refch = blb.mbopen(outsuf + thre_str + '_' + refmbsstr + ".mbs") reftime = refmbs[:, 0] v = dset + "-olr-0-all" daset, varstr, lev, drv = v.split('-') # Get data subset for days before and after CBs
print 'Plotting part (a): spatiofreq' plt.subplot(yplots, xplots, 1) if res == 'native': lon4sf = lon lat4sf = lat elif res == 'make': lt1 = lat[0] lt2 = lat[-1] ln1 = lon[0] ln2 = lon[-1] lat4sf = np.arange(lt2, lt1 + extent, gsize) lat4sf = lat4sf[:: -1] # latitude has to be made the other way because of the negative numbers lon4sf = np.arange(ln1, ln2 + extent, gsize) m = blb.AfrBasemap2(lat4sf, lon4sf, drawstuff=True, prj='cyl', rsltn='l') allmask, img = stats.spatiofreq5(m, s, name, lat4sf, lon4sf, yrs, thesekeys, per=rate, clim=nos4cbar, \ savefig=False, flagonly=True, \ col='bw', frm_event=from_event,cbar='none',title='') m.drawcountries(color='k') m.drawcoastlines(color='k') if testingoutput: plt.savefig('tmpfig_a.png', dpi=150) print 'Plotting part (b): CB outlines' plt.subplot(yplots, xplots, 2) m = blb.AfrBasemap2(lat, lon, drawstuff=True, prj='cyl', rsltn='l') if plotshow == 'col5': nch = 5 cols = ['r', 'b', 'c', 'm', 'g'] if choose_cb == 'random':
# OPENING FILES # Liebmann & Smith Interpolated OLR if noaaolr: v = "noaa-olr-0-0" dset, varstr, lev, drv = v.split('-') dsrc = picdir # CHANGE ACCORDINGLY IF ALREADY HAVE THIS DATA olr, time, lat, lon, dtime = mync.openolr(dsrc + 'olr.day.mean.nc', 'olr', subs=sub) olr = olr[1675:, :, :] time = time[1675:] dtime = dtime[1675:] if testyear: olr, dtime, time = olr[:365, :, :], dtime[:365], time[:365] if getdistr: showme = blb.gethists(olr, time, lat, lon, v, sub=sub, figd=figdir) # CALLS TO METBLOBS plt.ion() if getmbs: mbs, mbt, chull = blb.MetBlobs(olr,dtime,time,lat,lon,v,\ sub=sub,showblobs=showblb,interact=False) blb.mbsave(picdir + v + ".mbs", mbs, mbt, chull) del mbs, mbt, chull if noaaolrall: refmbsstr = "noaa-olr-0-0" refmbs, refmbt, refch = blb.mbopen(picdir + refmbsstr + ".mbs") reftime = refmbs[:, 0] v = "noaa-olr-0-all" dset, varstr, lev, drv = v.split('-') exec("ixt,[time,%s,dtime]=\ my.ixtwindow(reftime,time,hrwindow,time,%s,dtime)"\
this_c = cents[cent] this_thresh = ths[cent] th_thr_str = str(this_thresh) print 'opening metbot files...' outsuf = botpath + name + '_' if this_c == 'fut': outsuf = outsuf + 'fut_rcp85_' syfile = outsuf + th_thr_str + '_' + dset + '-OLR.synop' s = sy.SynopticEvents((), [syfile], COL=False) ks = s.events.keys() ks.sort() # all mbsfile = outsuf + th_thr_str + '_' + dset + "-olr-0-0.mbs" refmbs, refmbt, refch = blb.mbopen(mbsfile) # Get lots of info about event set print 'Getting more info about each cloud band...' dates, cXs, cYs, degs, chs, keys, daynos, tworecdt = sset.evset_info( s, refmbs, refmbt) numleft = len(dates) print 'Now with ' + str(numleft) + ' dates' # If wanting first day of event only, subset print 'Subset by first day?...' if from_event == 'first': print 'Selecting first day of event only' dates_d, cXs_d, cYs_d, degs_d, chs_d, keys_d, daynos_d, tworecdt_d = \ sset.sel_firstday(dates, cXs, cYs, degs, chs, keys, daynos, tworecdt)
if bwcen_plot: plt.figure(num='bw', figsize=[10, 7]) cnt = 1 # Get the map if cnt == 1: noaadct = dsetdict.dset_deets['noaa']['noaa'] yr_noaa = noaadct['yrfname'] f_noaa = botdir + \ "noaa/noaa.olr.day.mean." + yr_noaa + ".nc" olrdump, timedump, noaalat, noaalon, dtimedump = mync.openolr( f_noaa, 'olr', subs=sub) m = blb.SAfrBasemap2(noaalat, noaalon, drawstuff=True, prj='cyl', rsltn='l') ### Dsets dsets = 'all' ndset = len(dset_mp.dset_deets) # dsetnames=list(dset_mp.dset_deets) dsetnames = ['noaa', 'cmip5'] # dsets='spec' # ndset=1 # dsetnames=['noaa'] ndstr = str(ndset) print "Looping datasets" for d in range(ndset):
nthresh = len(threshs) for t in range(nthresh): thisthresh = threshs[t] thre_str = str(int(thisthresh)) thname = thnames[t] print 'opening metbot files...' outsuf = botpath + name + '_' syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' s = sy.SynopticEvents((), [syfile], COL=False) ks = s.events.keys() ks.sort() # all refkey = s.mbskeys[0] mbsfile = outsuf + thre_str + '_' + dset + "-olr-0-0.mbs" refmbs, refmbt, refch = blb.mbopen(mbsfile) # Get lots of info about event set print 'Getting more info about each cloud band...' dates, cXs, cYs, degs, chs, keys, daynos, tworecdt = sset.evset_info( s, refmbs, refmbt) # If wanting first day of event only, subset print 'Subset by first day?...' if from_event == 'first': print 'Selecting first day of event only' dates_d, cXs_d, cYs_d, degs_d, chs_d, keys_d, daynos_d, tworecdt_d =\ sset.sel_firstday(dates, cXs, cYs, degs, chs, keys, daynos, tworecdt) else: print 'Retaining all days from each event' dates_d, cXs_d, cYs_d, degs_d, chs_d, keys_d, daynos_d, tworecdt_d = \
lat = np.arange(-70.0, 20.0, 10.0) lon = np.arange(-2.5, 120.0, 10.0) latsp = 20. # lat spacing lonsp = 25. # lon spacing ### Get directories bkdir = cwd + "/../../../../CTdata/" botdir = bkdir + "metbot_multi_dset/" figdir = botdir + "/histpaper_v2_figs/outlines_map/" my.mkdir_p(figdir) # Set up plot print "Setting up plot..." g, ax = plt.subplots(figsize=figdim) m = blb.AfrBasemap2(lat, lon, latsp, lonsp, drawstuff=True, prj='cyl', rsltn='l', \ fontdict={'fontsize': 12, 'fontweight': 'normal'}) # Redraw map m.drawcountries() m.drawcoastlines() # Plot MetBot full domain fulldom_lats = [0, 0, -60, -60] fulldom_lons = [7.5, 100.0, 100.0, 7.5] draw_screen_poly(fulldom_lats, fulldom_lons, m, ls='--', lw=3, edgecol='dodgerblue', zord=10)