def daystr(day): day = round(day) mm, dd = atm.jday_to_mmdd(day) mon = atm.month_str(mm) return '%.0f (%s-%.0f)' % (day, mon, dd)
'U200' : 'U', 'U850' : 'U', 'V200' : 'V', 'V850' : 'V'} data = {} for nm in datafiles: print('Loading ' + datafiles[nm]) with xray.open_dataset(datafiles[nm]) as ds: if 'year' in ds.dims: ds = ds.mean(dim='year') data[nm] = ds[keys_dict[nm]].load() # ENSO indices enso = pd.read_csv(ensofile, index_col=0) enso = enso.loc[years] for key in enso_keys: if key not in enso.columns: months = atm.season_months(key) month_names = [(atm.month_str(m)).capitalize() for m in months] enso[key] = enso[month_names].mean(axis=1) enso = enso[enso_keys] col_names = [enso_nm + ' ' + nm for nm in enso.columns] enso.columns = col_names # ---------------------------------------------------------------------- # Daily timeseries ts = xray.Dataset() for nm in ['GPCP', 'PRECTOT']: ts[nm] = atm.mean_over_geobox(data[nm], lat1, lat2, lon1, lon2) ts['MFC'] = utils.daily_rel2onset(index_all['CHP_MFC']['daily_ts'], index[ind_nm], npre, npost) ts['CMFC'] = utils.daily_rel2onset(index_all['CHP_MFC']['tseries'], index[ind_nm], npre, npost)
return filn lon1, lon2 = 40, 100 lat1, lat2 = -15, 35 varlist = ['T'] pmin, pmax = 200e2, 600e2 years = range(1979, 2015) months = [4, 5, 6, 7, 8, 9] g = atm.constants.g.values nperday = 8 subset_dict = {'lon' : (lon1, lon2), 'lat' : (lat1, lat2)} for year in years: for mon in months: dayvals = atm.season_days(atm.month_str(mon), atm.isleap(year)) T = merra.read_daily(varlist, year, mon, subset_dict=subset_dict) # Daily means of 3-hourly data T = atm.daily_from_subdaily(T, nperday, dayvals=dayvals) # Vertical integral Tbar = atm.int_pres(T, pmin=pmin, pmax=pmax) Tbar = Tbar * g / (pmax - pmin) Tbar.name='Tbar' Tbar.attrs['long_name'] = 'Vertical mean atmospheric temperature' Tbar.attrs['pmin'] = pmin Tbar.attrs['pmax'] = pmax # Save to file atm.save_nc(savefile(year, mon, pmin, pmax), T, Tbar)
# Plots cmap = 'hot_r' axlims = (-30, 30, 40, 120) clim1, clim2 = 0, 80 figsize = (12, 9) months = [4, 5, 6] plt.figure(figsize=figsize) plt.suptitle(suptitle) # Lat-lon maps for i, month in enumerate(months): plt.subplot(2, 2, i + 1) atm.pcolor_latlon(mld[month-1], axlims=axlims, cmap=cmap) plt.clim(clim1, clim2) plt.title(atm.month_str(month)) # Sector mean line plots latmin, latmax = -30, 30 mldplot = atm.subset(mldbar, {'lat' : (latmin, latmax)}) lat = atm.get_coord(mldplot, 'lat') plt.subplot(2, 2, 4) for month in months: plt.plot(lat, mldplot[month-1], label=atm.month_str(month)) plt.legend() plt.grid() plt.title('%d-%d E Mean' % (lon1, lon2)) plt.xlabel('Latitude') plt.ylabel('MLD (m)')