import numpy as np import xray import pandas as pd import matplotlib.pyplot as plt import atmos as atm import merra from indices import onset_SJKE, summarize_indices, plot_index_years # ---------------------------------------------------------------------- # Compute SJ indices (Boos and Emmanuel 2009) datadir = atm.homedir() + 'datastore/merra/daily/' years = np.arange(1979, 2015) filestr = 'merra_uv850_40E-120E_60S-60N_' datafiles = [datadir + filestr + '%d.nc' % y for y in years] # Read daily data from each year ds = atm.combine_daily_years(['U', 'V'], datafiles, years) # Remove extra dimension from data u = atm.squeeze(ds['U']) v = atm.squeeze(ds['V']) # Calculate OCI index sjke = onset_SJKE(u, v) # Summary plot and timeseries in individual years summarize_indices(years, sjke['onset']) plot_index_years(sjke, suptitle='SJ', yearnm='Year', daynm='Day')
keys = index.keys() for key in keys: ind = index[key] if 'retreat' in ind.keys(): retreat = ind.retreat else: retreat = None indices.summarize_indices(ind.year, ind.onset, retreat, ind.title) saveclose('onset_retreat_hist_', isave, exts) # ---------------------------------------------------------------------- # Daily timeseries of each index in each year keys = index.keys() # keys = ['OCI', 'TT'] for key in keys: indices.plot_index_years(index[key], suptitle=key, vertline=True) saveclose('index_tseries_' + key + '_', isave, exts) # ---------------------------------------------------------------------- # Compare indices with each other # keys = ['HOWI_100', 'HOWI_50', 'OCI', 'SJKE', 'TT', 'WLH_CMAP_kmax12', # 'WLH_CMAP_nroll3', 'WLH_MERRA_PRECIP_nroll7'] keys = ['HOWI_100', 'OCI', 'SJKE', 'TT', 'WLH_MERRA_PRECIP_nroll7', 'CHP_MFC', 'CHP_PCP'] shortkeys = [short[key] for key in keys] years = index[keys[0]].year.values onset = np.reshape(index[keys[0]].onset.values, (len(years), 1)) for key in keys[1:]: ind = np.reshape(index[key].onset.values, (len(years), 1))
tt = onset_TT(T, north=north, south=south) # Some weirdness going on in 1991, for now just set to NaN # Troubleshoot later for nm in ['ttn', 'tts', 'tseries']: vals = tt[nm].values vals = np.ma.masked_array(vals, abs(vals) > 1e30).filled(np.nan) tt[nm].values = vals # Plot TTN and TTS plot_tseries_together(tt[['ttn', 'tts']], tt['onset'].values, suptitle=suptitle, standardize=False) # Summary plot and timeseries in individual years summarize_indices(years, tt['onset']) plt.suptitle(suptitle) plot_index_years(tt, suptitle=suptitle, yearnm='year', daynm='day') if save: atm.savefigs(varname + '_', 'png') # Plot contour map of pressure-level data p_plot = 400 T_plot = T_p[p_plot] y, d = 0, 80 lat = atm.get_coord(T_plot, 'lat') lon = atm.get_coord(T_plot, 'lon') axlims = (lat.min(), lat.max(), lon.min(), lon.max()) plt.figure() atm.pcolor_latlon(T_plot[y, d], axlims=axlims)
def index_tseries(days, ind, ind_roll, titlestr): plt.plot(days, ind, label='daily') plt.plot(days, ind_roll, label='%d-day rolling' % nroll) plt.grid() plt.legend(loc='lower right') plt.title(titlestr) plt.figure(figsize=(12, 10)) plt.subplot(221) index_tseries(days, ds.howi_clim_norm, ds.howi_clim_norm_roll, 'HOWI ' + yearstr + ' Climatology') for yr in [0, 1, 2]: plt.subplot(2, 2, yr + 2) index_tseries(days, ds.howi_norm[yr], ds.howi_norm_roll[yr], 'HOWI %d' % years[yr]) # ---------------------------------------------------------------------- # Onset and retreat indices summarize_indices(years, onset, retreat, 'HOWI') # ---------------------------------------------------------------------- # Plot timeseries of each year plot_index_years(howi) # ---------------------------------------------------------------------- # Save figures if isave: for ext in exts: atm.savefigs(namestr, ext)