def plusminus(num): if num == 0: numstr = '+0' else: numstr = atm.format_num(num, ndecimals=0, plus_sym=True) return numstr # ---------------------------------------------------------------------- # Composite averages print('Computing composites relative to onset day') comp = {} for nm in varnms: comp[nm] = {} for key in data: compdat = utils.composite(sectordata[key][nm], compdays_all, daynm='dayrel', return_avg=True) for dkey in compdat: key2 = key + '_' + dkey comp[nm][key2] = compdat[dkey] # Get max/min values from all composites for setting consistent # ylimits on plots ylimits = {} for nm in varnms: for i, key in enumerate(comp[nm]): val1 = comp[nm][key].min().values val2 = comp[nm][key].max().values if i == 0: ylim1, ylim2 = val1, val2 else: ylim1, ylim2 = min([ylim1, val1]), max([ylim2, val2])
axlims = (-10, 50, 40, 120) with xray.open_dataset(datafile) as ds: data = ds['PRECTOT'].load() # Align daily data relative to onset day ndays = 30 data = daily_rel2onset(data, d_onset, ndays, ndays, yearnm=yearnm, daynm=daynm) years = data[yearnm].values databar = data.mean(dim=yearnm) # Days for pre/onset/post composites compdays = comp_days_centered(5) #compdays = comp_days_centered(1, 9) # Calculate composites comp = composite(data, compdays, daynm=daynm + 'rel') compbar = collections.OrderedDict() for key in comp: compbar[key] = comp[key].mean(dim=yearnm) # Plot pre/onset/post composites - climatology cmin, cmax = 0, 20 plt.figure(figsize=(12,10)) for i, key in enumerate(comp): plt.subplot(2, 2, i+1) atm.pcolor_latlon(compbar[key], axlims=axlims, cmap=cmap) plt.clim(cmin, cmax) plt.title(var + ' ' + key) # Plot pre/onset/post composites - individual years cmin, cmax = 0, 30