# Find TTT data outsuf = botdir + dset + "/" + name + "/" + name + "_" mbsfile = outsuf + thre_str + '_' + dset + "-olr-0-0.mbs" syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' # using events if wh_count == 'event': ### Open synop file s = sy.SynopticEvents((), [syfile], COL=False) ### Count number of events ks = s.events.keys() # all events kw, ke = stats.spatialsubset( s, False, cutlon=40.) # splitting tracks west and east of 40E ### Put n events into array if doms[do] == 'All': yvals[cnt] = len(ks) elif doms[do] == 'Cont': yvals[cnt] = len(kw) elif doms[do] == 'Mada': yvals[cnt] = len(ke) elif wh_count == 'blob': refmbs, refmbt, refch = blb.mbopen(mbsfile) blob_edts = []
thesekeys.append(k) edts.append(dt) elif tstep == 'mon': if int(dt[1] == mon1): thesekeys.append(k) edts.append(dt) edts = np.asarray(edts) yrs = np.unique(edts[:, 0]) # Split by domain print 'selecting events for this dom group...' if len(doms) == 1: keys = thesekeys elif len(doms) == 4: k1, ktmp = stats.spatialsubset(s, thesekeys, cutlon=37.5) k2, k3 = stats.spatialsubset(s, ktmp, cutlon=67.5) if dom == 'All': keys = thesekeys elif dom == 'nCont': keys = k1 elif dom == 'nMada': keys = k2 elif dom == 'nOcea': keys = k3 # opening future data print 'opening future metbot files'
for line in f: if dset + '\t' + name in line: thresh = line.split()[2] print 'thresh=' + str(thresh) thisthresh = int(thresh) thre_str = str(thisthresh) ### Open synop file syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' s = sy.SynopticEvents((), [syfile], COL=False) ### Count number of events ks = s.events.keys() ks.sort() # all events kw, ke = stats.spatialsubset( s, False, cutlon=40.) # splitting tracks west and east of 40E ### Calc seasonal cycle scycle, cyclestats, yrs = stats.seasonalcycle(s, False) scyclew, cyclestatsw, yrsw = stats.seasonalcycle(s, kw) scyclee, cyclestatse, yrse = stats.seasonalcycle(s, ke) ### Loop domains doms = ['All', 'Continental', 'Madagascar'] ndoms = len(doms) whichc = [scycle, scyclew, scyclee] for r in range(ndoms): ### Put into data arrays if meanplot:
edts.append(dt) elif seas=='JF': if (int(dt[1]) >= mon1) and (int(dt[1]) <= mon2): thesekeys.append(k) edts.append(dt) elif seas=='all': thesekeys.append(k) edts.append(dt) edts = np.asarray(edts) yrs = np.unique(edts[:, 0]) count_fulldom=len(thesekeys) # Split by domain print 'selecting events for this dom group...' k1, ktmp = stats.spatialsubset(s, thesekeys, cutlon=clon1) k2, k3 = stats.spatialsubset(s, ktmp, cutlon=clon2) count_ttt=len(k2) print "Total CB events in this domain =" + str(count_ttt) keys4rain=k2 elif wh_count=='blob': refmbs, refmbt, refch = blb.mbopen(mbsfile) count_all=len(refmbt) blob_edts = [] blob_edts_regsel =[] for b in range(len(refmbt)): date = refmbt[b] mon = int(date[1])
else: thesekeys.append(k) edts.append(dt) edts = np.asarray(edts) yrs = np.unique(edts[:, 0]) ### PLOT GRIDPOINT COUNT FOR WHOLE SEASON print 'Plotting spatiofrequency for model ' + name # colour plot if col_plot: print 'Plotting spatiofreq plot in colour' plt.figure(num='col') plt.subplot(yplots, xplots, cnt) allmask=stats.spatiofreq4(m,s,name,lat,lon,yrs,thesekeys,per=rate,meanmask=False,clim=nos4cbar,\ month=False,savefig=False,flagonly=True,\ col='col',cens='None',frm_event='all') m.drawcountries(color='k') m.drawcoastlines(color='k') if group: m.drawmapboundary(color=grcl, linewidth=3) if bwcen_plot: print 'Getting sample to plot centroids on b/w spatiofreq' if sample == 'blon': best_lon = [33, 58] ndays = [50, 50] n_cen = [-22, -22] s_cen = [-32, -32]
else: rain, raindates, time = rain[: 365, :, :], raindates[: 365], time[: 365] # Loop seasons for ss in range(len(seasons)): print "Getting seasonal mean for " + seasons[ss] ### Calculate area average # N.B. the "rain" data should now have the right years and domain # I am just doing a straight gridbox average # ...because it's not spanning too many latitudes rainmean = stats.seasmean(rain, raindates, seas=seasons[ss]) rainmean = round(rainmean, 2) raincollect[r, ss] = rainmean ### Write to textfile txtfile_pr = txtdir + "precip_mean." + seasons[ ss] + "." + prdom[r] + ".txt" print "Writing seasonal fldmean to " + txtfile_pr with open(txtfile_pr, "a") as myfile: myfile.write(dset + "\t" + name + "\t" + str(rainmean) + "\n") ### Find location of synop file print "Preparing to get nTTTs" outdir = indir + dset + "/" + name + "/"
thisthresh = threshs[t] print thisthresh thre_str = str(int(thisthresh)) print thre_str mbsfile = outsuf + thre_str + '_' + dset + "-olr-0-0.mbs" syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' ### Open ttt data s = sy.SynopticEvents((), [syfile], COL=False) refmbs, refmbt, refch = blb.mbopen(mbsfile) ### Select events ks = s.events.keys() ks.sort() # all kw, ke = stats.spatialsubset( s, False, cutlon=40.) # events west and east of 40E ### Count number of events count_all = str(int(len(ks))) count_cont = str(int(len(kw))) count_mada = str(int(len(ke))) ### Calc seasonal cycle scycle, cyclestats, yrs = stats.seasonalcycle(s, False) scyclew, cyclestatsw, yrsw = stats.seasonalcycle(s, kw) scyclee, cyclestatse, yrse = stats.seasonalcycle(s, ke) nNF = scycle[:, 3:7].sum( 1) # summing years for months November to March ### PLOT TIMESERIES OF SEASONAL CYCLE print 'Plotting timeseries'
print thre_str mbsfile = outsuf + thre_str + '_' + dset + "-olr-0-0.mbs" syfile = outsuf + thre_str + '_' + dset + '-OLR.synop' ### Open ttt data s = sy.SynopticEvents((), [syfile], COL=False) refmbs, refmbt, refch = blb.mbopen(mbsfile) ### Select events ks = s.events.keys() ks.sort() # all count_all = str(int(len(ks))) print "Total CB events =" + str(count_all) if len(doms) == 3: kw, ke = stats.spatialsubset( s, False, cutlon=40.) # events west and east of 40E keys = [ks, kw, ke] elif len(doms) == 4: k1, ktmp = stats.spatialsubset(s, False, cutlon=37.5) k2, k3 = stats.spatialsubset(s, ktmp, cutlon=67.5) keys = [ks, k1, k2, k3] ### Plot olrmaps olrbase = olrdir + dset + "/" my.mkdir_p(olrbase) mapsuf = seasopt + '_' + sub + '_' + dset + '_' + name + '_' + thre_str + '_key' + refkey + '_4' + monmean if testfile or testyear: testq = True else: testq = freecol
### Open ttt data - past s = sy.SynopticEvents((), [syfile], COL=False) print dset print name print "historical" ### Select events - past ks = s.events.keys() ks.sort() # all keything = '0' refkey = dset + '-olr-0-' + keything if len(doms) == 4: k1, ktmp = stats.spatialsubset(s, ks, cutlon=37.5) k2, k3 = stats.spatialsubset(s, ktmp, cutlon=67.5) if dom == 'All': keys = ks elif dom == 'nCont': keys = k1 elif dom == 'nMada': keys = k2 elif dom == 'nOcea': keys = k3 edts = [] thesekeys = [] for k in keys: e = s.events[k] dts = s.blobs[refkey]['mbt'][e.ixflags]