# ---------------------------------------------------------------------- # Average values over JJAS and LRS - interannual variability keys = ['PCP', 'EVAP', 'ANA', 'dW', 'P-E+dW-ANA', 'MFC'] fmts = {'PCP' : 'b', 'EVAP' : 'g', 'ANA' : 'r', 'dW' : 'c', 'P-E+dW-ANA' : 'm', 'MFC' : 'k--'} ssn[keys].plot(figsize=(10, 10), style=fmts, legend=False, grid=True) plt.legend(loc='upper left', fontsize=10) plt.ylabel('mm/day') plt.title('JJAS Mean') plt.figure(figsize=(7, 10)) plt.suptitle('JJAS mean standardized timeseries') nrow, ncol = len(keys), 1 for i, col in enumerate(ssn_st[keys].columns): plt.subplot(nrow, ncol, i + 1) plt.plot(years, ssn_st[col], 'k') plt.title(col, loc='left', fontsize=10) plt.autoscale(tight=True) plt.grid(True) if i < nrow - 1: plt.gca().set_xticklabels([]) else: plt.xlabel('Year') atm.scatter_matrix(ssn[keys], figsize=(14, 10), pmax_bold=0.05, incl_p=True, annotation_pos=(0.05, 0.6), incl_line=True, suptitle='JJAS Mean')
handles = [cs.collections[0], cs2.collections[0]] + handles plt.legend(handles, labels, fontsize=12) plt.title('Averaging Regions for Onset Indices') saveclose('map_', isave, exts) # ---------------------------------------------------------------------- # Monsoon strength styles = {'MERRA' : 'r--', 'MERRA_DET' : 'r', 'ERAI' : 'b--', 'ERAI_DET' : 'b', 'AIR' : 'g--', 'AIR_DET' : 'g'} strength.plot(figsize=(10,10), style=styles) plt.title('JJAS Monsoon Strength') plt.xlabel('Year') plt.ylabel('Index (mm/day)') plt.grid() plt.legend(fontsize=12) atm.scatter_matrix(strength) plt.suptitle('JJAS Monsoon Strength') saveclose('strength_', isave, exts) # ---------------------------------------------------------------------- # Histograms of each index 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)
i_detrend = True # ---------------------------------------------------------------------- # Correlations between indices opts = {'figsize' : (12, 9), 'annotation_pos' : (0.05, 0.75), 'incl_p' : True, 'incl_line' : True, 'pmax_bold' : 0.05} for i_detrend in [True, False]: # Correlations between onset/retreat/length if i_detrend: suptitle = onset_nm + ' (Detrended Indices)' atm.scatter_matrix(detrend(index), suptitle=suptitle, **opts) else: atm.scatter_matrix(index, suptitle=onset_nm, **opts) # Cumulative and average rainfall over monsoon season df1 = ssn[['onset', 'retreat', 'length']] nms = ['MFC_JJAS', 'MFC_LRS', 'PCP_JJAS', 'PCP_LRS'] suptitle = 'Season Totals (%s Monsoon Onset/Retreat)' % onset_nm for key in ['_TOT', '_AVG']: keys = [nm + key for nm in nms] df2 = ssn[keys] if i_detrend: atm.scatter_matrix_pairs(detrend(df1), detrend(df2), suptitle=suptitle + ' (Detrended)') else: atm.scatter_matrix_pairs(df1, df2, suptitle=suptitle)
row, col = atm.subplot_index(nrow, ncol, yplot) if row == nrow: plt.xlabel("Day") else: plt.gca().set_xticklabels("") if col > 1: plt.gca().set_yticklabels("") if isavefigs: atm.savefigs("onset_changepoint_merged_" + varnm.upper(), "pdf") plt.close("all") df = pd.DataFrame() for key in ["onset", "retreat"]: for varnm in varnms: df["%s_%s" % (key, varnm.upper())] = chp[varnm][key].to_series() atm.scatter_matrix(df, incl_p=True, incl_line=True, annotation_pos=(0.05, 0.7)) plt.suptitle("Merged Changepoints") plt.figure(figsize=(8, 10)) for i, key in enumerate(["onset", "retreat"]): plt.subplot(2, 1, i + 1) for varnm in varnms: plt.plot(years, df["%s_%s" % (key, varnm.upper())], label=varnm.upper()) plt.legend() plt.xlabel("Year") plt.ylabel("Day of Year") plt.title(key.capitalize() + " from Merged Changepoint Method") plt.grid() plt.autoscale(tight=True) if isave:
if isave: atm.savefigs('onset_changepoint_' + varnm.upper(), 'pdf') plt.close('all') df = pd.DataFrame() for key in ['onset', 'retreat']: for varnm in varnms: df['%s_%s' % (key, varnm.upper())] = chp[varnm][key].to_series() if incl_merged: key2 = '%s_%s_m' % (key, varnm.upper()) df[key2] = chpm[varnm][key].to_series() opts = {'incl_p' : True, 'incl_line' : True, 'annotation_pos' : (0.05, 0.7)} if incl_merged: for nm in ['onset', 'retreat']: keys = [key for key in df.columns if key.startswith(nm)] atm.scatter_matrix(df[keys], **opts) else: atm.scatter_matrix(df, **opts) plt.figure(figsize=(8, 10)) clrs = ['b', 'r'] for i, key in enumerate(['onset', 'retreat']): plt.subplot(2, 1, i + 1) for varnm, clr in zip(varnms, clrs): key1 = '%s_%s' % (key, varnm.upper()) plt.plot(years, df[key1], clr, label=varnm.upper()) if incl_merged: plt.plot(years, df[key1 + '_m'], clr + '--', label=varnm.upper() + '_m') plt.legend(fontsize=10) plt.xlabel('Year') plt.ylabel('Day of Year')