axes.append(ax) allpercs = dict() for nu in [10, 25, 50, 75, 90]: allpercs['p{}'.format(nu)] = [ np.percentile(freqs[(ssp, 'all', cos)][:, reg], nu) for ssp in allsims ] ax.axhline(allpercs['p50'][0], color='gray', linewidth=0.5) ctl.boxplot_on_ax(ax, allpercs, allsims, colsim, plot_mean=False, plot_ensmeans=False, plot_minmax=False) ax.set_xticks([]) ax.set_title(reg_names[reg]) if reg == 0: ax.set_ylabel('Regime frequency') ax.scatter(0, results_ref['freq_clus'][reg], color='black', marker='*', s=5) ctl.custom_legend(figall, colsim, allsims, ncol=4) figall.savefig(cart_out + 'WRfreq_cmip5_{}.pdf'.format(area))
cosi = [runfreq[(tip, mem, reg)] for mem in okmods] coso = np.mean(cosi, axis=0) runfreq[(tip, reg)] = coso coserr = np.std(cosi, axis=0) / np.sqrt(len(okmods) - 1) ax.fill_between(yr, coso - coserr, coso + coserr, color=col, alpha=0.3) ax.plot(yr, coso, label=tip, color=col) ax.set_title(reg_names_area[area][reg]) #ax.legend() ctl.custom_legend(fig, colorz, ['MPI-ESM1-2-LR', 'UKESM1-0-LL'], ncol=2, add_space_below=0.12) fig.savefig(cart_out + 'check_ece_vs_mpi_{}.pdf'.format(area)) trend_ssp = dict() for tip in alltips: okmods = resdict[tip].keys() for reg in range(4): for mem in okmods: seasfr = seasfreq[(tip, mem, reg)] seas10 = np.array(ctl.running_mean(seasfr, 10)) okcose = ~(np.isnan(seas10)) & (yr >= 2015) m, c, err_m, err_c = ctl.linear_regre_witherr( np.array(yr[okcose]), np.array(seas10[okcose]))
ax.scatter(res, val, color=col, marker=mark, s=100, linewidth=lw) ax.errorbar(res, val, yerr=errval, color=col, linewidth=lw, capsize=4) allvals_mods.append(val) allerr_mods.append(errval) ax.axhline(results['ERA_0'][cos], color='grey', alpha=0.6) ax.set_ylabel(tit) ax.set_xlabel('Eff. atm. resolution (km)') fig = ctl.custom_legend(fig, colors, model_names, ncol=6) fig.savefig(cart_out + cos + '_{}_atmresolution.pdf'.format(vtag)) figures.append(fig) # WITH OCEAN RESOLUTION fig = plt.figure(figsize=(16, 12)) ax = plt.subplot(111) for mod, res, col, mark in zip(model_names, oce_resolution, colors, sym_all): allvals = [] for ke in results.keys(): if mod == ke.split('_')[0]: allvals.append(results[ke][cos]) if len(allvals) == 1:
i += 0.7 ax.scatter(i, ref_corrs[(ind, reg, seas)], marker='D', color='black', s=25) i += 1 ax.scatter(i, np.mean(LRs), marker='D', color=col_LR, s=25) i += 1 ax.scatter(i, np.mean(HRs), marker='D', color=col_HR, s=25) ax.set_xticks([]) ax.set_title(reg_names[reg]) ctl.adjust_ax_scale(axes) ctl.custom_legend(fig, coloks + ['black', col_LR, col_HR], modoks + ['ERA', 'LR', 'HR']) fig.suptitle('Correlation of WR freq. with {} index - {}'.format( ind, seas)) fig.savefig(cou + 'corr_models_WRfreq_vs_{}_{}.pdf'.format(ind, seas)) # PLOT 2: freq diff per ogni regime pos/neg fig = plt.figure(figsize=(16, 12)) axes = [] for reg in range(4): modoks = [] coloks = [] ax = fig.add_subplot(2, 2, reg + 1) axes.append(ax)
ax = plt.subplot(5, 4, ind) allvals = np.array([all_stats_choices[(n_choice, 'multi_cramer',reg)][i][0][0] for i in range(6)]) ax.scatter(allks_ok, allvals, marker = 'D', color = colors[4]) all_cramer_compare.append(allvals) allvalspval = np.array([all_stats_choices[(n_choice, 'multi_cramer',reg)][i][1][0] for i in range(6)]) all_cramer_pvals.append(allvalspval) #ax.scatter(allks_ok_max, allvals, marker = 'D', color = colors[4]) ax.set_xlabel('1D KolmogSmir') ax.set_ylabel('2D cramer') axes.append(ax) ctl.adjust_ax_scale(axes) fig.tight_layout() fig = ctl.custom_legend(fig, colors, labels = ['KolmogSmir', 'MannWhit', 'Anderson', 'peacock2', 'cramer']) fig.savefig(cart_out + 'all_stats_ERA_pdfs_{}yr.pdf'.format(n_choice)) # Only KolmogSmir 1D fig = plt.figure(figsize = (16, 12)) #yrcho = [5, 10, 15, 20, 25, 30, 40, 50, 60] yrcho = [5, 10, 20, 30, 40, 50, 60] colors = ctl.color_set(len(yrcho)) ind = 0 axes = [] for reg in range(4): ind += 1 ax = plt.subplot(2, 2, ind) for n_choice, col in zip(yrcho, colors): allvals = np.array([np.mean([cos[0] for cos in all_stats_choices[(n_choice, 'KolmogSmir', reg)][i]]) for i in range(100)])
#xvec = np.linspace(0., 0.4, 500) if 'KS' in nam: xvec = np.linspace(0., 0.5, 500) ax.axvline(0.06, color = 'grey', alpha = 0.6) elif nam == 'Clus radius': xvec = np.linspace(1000, 2200, 500) ax.axvline(ref_cent_dist[reg], color = 'grey', alpha = 0.6) elif nam == 'Clus std': xvec = np.linspace(300, 800, 500) ax.axvline(ref_cent_std[reg], color = 'grey', alpha = 0.6) elif nam == 'dist centocen': xvec = np.linspace(0, 2300, 500) else: xvec = np.linspace(0., 1.2*allvals.max(), 500) pdfxvec = kpdf(xvec) ax.plot(xvec, pdfxvec, color = col) ax.set_title('Reg {}'.format(reg)) axes.append(ax) ctl.adjust_ax_scale(axes) fig.suptitle(tit) plt.subplots_adjust(top = 0.9) fig = ctl.custom_legend(fig, colors, ['{} yr'.format(yr) for yr in yrcho]) fig.savefig(cart_out + '_'.join(nam.split())+'_ERA_allyears.pdf') pickle.dump(ERA_ref_thresholds, open(cart_out + 'ERA_ref_thresholds_allstats.p', 'wb'))
ax.bar(i, okrms, width = wi, color = col, yerr = yerr, capsize = 5) i += 0.7 if vv == 'HR': i += 0.2 all_LR = np.mean([allrms[mod] for mod, vv in zip(model_names, vers) if vv == 'LR']) all_HR = np.mean([allrms[mod] for mod, vv in zip(model_names, vers) if vv == 'HR']) i+=0.2 col_LR = 'grey' col_HR = 'black' ax.bar(i, all_LR, width = wi, color = col_LR) i += 0.7 ax.bar(i, all_HR, width = wi, color = col_HR) ctl.custom_legend(fig, colors, model_names, ncol = 6) fig.savefig(cart_out + 'sst_bias_RMS_DJF_EAT.pdf') fig = plt.figure(figsize = (16, 12)) ax = plt.subplot() ax.set_ylabel('(1-patcor)') ax.set_title('Pattern correlation with observed SSTs in the North Atlantic') ax.set_xticks([]) i = 0 wi = 0.6 #for mod, col, vv, mem in zip(model_names, colors, vers, ens_mems): #ax.bar(i, allrms[(mod, mem)], width = wi, color = col) for mod, col, vv in zip(model_names, colors, vers): rmsall = []
all_LR_std = np.std([ allrms[(mod, reg)] for mod, vv in zip(model_names_all, vers) if vv == 'LR' ]) all_HR_std = np.std([ allrms[(mod, reg)] for mod, vv in zip(model_names_all, vers) if vv == 'HR' ]) i += 0.4 ax.bar(i, all_LR, width=wi, color=col_LR, yerr=all_LR_std, capsize=5) i += 0.7 ax.bar(i, all_HR, width=wi, color=col_HR, yerr=all_HR_std, capsize=5) ctl.custom_legend(fig, colors + ens_colors, model_names + ens_names) #fig.suptitle('RMS of blocking anomalies') fig.savefig(cart_out + 'block_allregs_rms{}.pdf'.format(tag)) fig = plt.figure(figsize=(16, 12)) axes = [] for reg in range(4): ax = plt.subplot(2, 2, reg + 1) axes.append(ax) #ax.set_xlabel('Latitude') ax.set_ylabel('patcor') ax.set_title(patnames[reg]) ax.set_xticks([]) i = 0
ctl.boxplot_on_ax(ax, allpercs, alltips, colorz, plot_mean=False, plot_ensmeans=False, plot_minmax=False) ax.axhline(0, color='gray', linewidth=0.5) ax.set_xticks([]) ax.set_title(reg_names[reg]) if reg == 0 or reg == 2: ax.set_ylabel('Regime frequency anomaly') ctl.adjust_ax_scale(axes) ctl.custom_legend(figall, colorz, alltips, ncol=2) figall.savefig(cart_out + 'check_WRfreq_alltips_{}.pdf'.format(area)) figall = plt.figure(figsize=(16, 12)) axes = [] for reg in range(4): ax = figall.add_subplot(2, 2, reg + 1) axes.append(ax) histmean = dict() for tip in alltips: histmean[tip] = np.mean(freqs[('hist', tip)][:, reg]) allpercs = dict() for nu in [10, 25, 50, 75, 90]: allpercs['p{}'.format(nu)] = [
np.mean(clm_fullperiod[(name, num)][:, lla1:lla2, llo1:llo2], axis=(1, 2)), color=col, linewidth=lw) if lla2 is None: lla2 = -1 if llo2 is None: llo2 = -1 ax.set_title('lat {:2.0f}/{:2.0f}, lon {:3.0f}/{:3.0f}'.format( lat_area[lla1], lat_area[lla2], lon_area[llo1], lon_area[llo2])) axes.append(ax) ctl.adjust_ax_scale(axes) fig.tight_layout() fig = ctl.custom_legend(fig, colors, model_names) fig.savefig(cart_out + 'mean_climatology_zg_models_{}days.pdf'.format(num)) fig = plt.figure(figsize=(16, 12)) i = 0 for lla1, lla2 in lat_sect: axes = [] for llo1, llo2 in lon_sect: lw = 0.7 i += 1 ax = plt.subplot(3, 3, i) for name, col in zip(model_names, colors): if name == 'ERA': lw = 2.0 ax.plot(datesall[name].dayofyear, np.mean(climate_mean_dict[name][:, lla1:lla2, llo1:llo2], axis=(1, 2)),
rotation='horizontal', transform=ax.transAxes, fontsize=20) ax1.scatter(0.35, plocos[('var_ratio', 'ref', 'EAT')], color='black', marker='*', s=100) ax1.scatter(2.15, plocos[('var_ratio', 'ref', 'PNA')], color='black', marker='*', s=100) ctl.custom_legend(fig, colorzi, nomi, ncol=2, add_space_below=0.1) ax1.set_ylabel('Variance ratio') ax2.set_ylabel('Frequency bias') #plt.title('cmip6 vs cmip6 var_fr '+tip) fig.savefig(cart_out + 'var_fr_boxes_{}.pdf'.format(tip)) # taylor with clouds for tip in ['', '_refEOF']: fig = plt.figure(figsize=(24, 12)) for i, area in enumerate(['EAT', 'PNA']): patnames = reg_names_area[area] for num, patt in enumerate(patnames): ax = plt.subplot(2, 4, num + 1 + 4 * i, polar=True) obs = plocos[('patterns', 'ref', area, num)] meapats = dict()
for var in allvars: print(var) fig = plt.figure(figsize = (16,12)) for col, nam in zip(colors, resuu.keys()): coso = resuu[nam][var].mean('lon').groupby("time.year").mean() glomean = np.average(coso, weights = abs(np.cos(np.deg2rad(coso.lat))), axis = -1) if var == 'evspsbl': plt.plot(coso.year.data, np.abs(glomean), label = nam, color = col, linewidth = 2) else: plt.plot(coso.year.data, glomean, label = nam, color = col, linewidth = 2) plt.grid() plt.title(var) #plt.legend() ctl.custom_legend(fig, colors, resuu.keys(), ncol = 4, add_space_below = 0.03) figs_global.append(fig) ctl.plot_pdfpages(cart + 'global_timeseries_allmems.pdf', figs_global) sys.exit() #srf_net = ssr + str + sshf + slhf surf_fluxs = ['rsds', 'rlds', 'rsus', 'rlus', 'hfss', 'hfls'] toa_fluxs = ['rlut', 'rsut', 'rsdt'] allvars = surf_fluxs + toa_fluxs + ['clt', 'clwvi', 'evspsbl'] fir_HR = '/home/paolo/work/data/REFORGE/EC-Earth3-TL799/rfrg-orog255-noparam/r2i1p1f1/mon/{}/{}_Amon_EC-Earth3-TL799_rfrg-orog255-noparam_r2i1p1f1_r144x73_*nc' fir_LR = '/home/paolo/work/data/REFORGE/EC-Earth3/rfrg-ctrl-noparam/r1i1p1f1/mon/{}/{}_Amon_EC-Earth3_rfrg-ctrl-noparam_r1i1p1f1_r144x73_*nc' fils_HR = np.concatenate([glob.glob(fir_HR.format(var, var)) for var in allvars]) fils_LR = np.concatenate([glob.glob(fir_LR.format(var, var)) for var in allvars])
rucaz = np.concatenate(rugi) rumin, rumax = (np.min(rucaz), np.max(rucaz)) ruvec = np.linspace(rumin-0.2*abs(rumin), rumax+0.2*abs(rumax), 100) for ru, gi, col in zip(allru, rugi, colors): pdf = ctl.calc_pdf(gi) pdfvec = pdf(ruvec) pdfvec = pdfvec/np.sum(pdfvec) ax.plot(ruvec, pdfvec, color = col) ax.grid() ax.set_title('{} - {}'.format(anam, cos)) fig.suptitle('{} - {}'.format(varna, seas)) ctl.custom_legend(fig, colors, allru, ncol = 4, add_space_below = 0.06) fig.savefig(cart_out + '{}_{}_{}dist_{}.pdf'.format(varna, seas, pio, typet)) #### Now with smaller regions for varna in allvars_2D: for seas in seasons: for pio, gipio in zip(['mon', 'sea'], [800, 200]): if pio == 'mon' and seas == 'year': continue fig, axs = plt.subplots(3, 5, figsize = (24,12)) for ia, anam in enumerate(areas_ls_names[:-3]): ax = axs.T.flatten()[ia] rugi = [] for na, ru, col in zip(allnams, allru, colors): if typet == 'rel':
ax.axhline(ERA_ref_thresholds[(nam, 60, reg, 50)], color = 'grey', alpha = 0.6) ax.axhline(ERA_ref_thresholds[(nam, 60, reg, 10)], color = 'grey', alpha = 0.6, linestyle = '--') ax.axhline(ERA_ref_thresholds[(nam, 60, reg, 90)], color = 'grey', alpha = 0.6, linestyle = '--') ax.axhline(ERA_ref_thresholds[(nam, 60, reg, 1)], color = 'grey', alpha = 0.6, linestyle = ':') ax.axhline(ERA_ref_thresholds[(nam, 60, reg, 99)], color = 'grey', alpha = 0.6, linestyle = ':') #ax.set_xticklabels(model_names, size='small', rotation = 60) ax.set_xticklabels([]) ax.set_title('Reg {}'.format(reg)) axes.append(ax) ctl.adjust_ax_scale(axes) fig.suptitle(tit) plt.subplots_adjust(top = 0.9) fig = ctl.custom_legend(fig, colors, model_names) fig.savefig(cart_out + '_'.join(nam.split())+'_models_primacoup_{}.pdf'.format(tag)) allfigs.append(fig) fig = plt.figure(figsize = (16, 12)) ind = 0 axes = [] for reg in range(4): ind += 1 ax = plt.subplot(2, 2, ind) eraval = ERA_ref_thresholds[(nam, 60, reg, 50)] allvals = np.array([all_mod_stats[(nam, mod, reg)]-eraval for mod in model_names]) allvalsdiff = np.array([abs(cu)-abs(ci) for cu, ci in zip(allvals[::2], allvals[1::2])])
modskill.append(ctl.Rcorr(obserie, modserie)) modskill_p50.append(ctl.Rcorr(obserie, modserie_p50)) xs = np.arange(len(modskill)) ax.scatter(xs, modskill, c=colors, s=100) ax.scatter(xs, modskill_p50, c=colors, s=100, marker='x') ax.grid() ax.set_xticks([]) ax.set_title(patnames[reg]) axes.append(ax) ctl.adjust_ax_scale(axes) fig.suptitle('Seasonal skill') ctl.custom_legend(fig, colors, exps) fig.savefig(cart_out + 'seas_skill.pdf') figs.append(fig) fig = plt.figure(figsize=(16, 12)) ax = fig.add_subplot(111) allye = results['ERA']['freq_clus_seasonal_years'] obsfr = results['ERA']['freq_clus_seasonal'].T modskill = [] modskill_p50 = [] modskill_p75 = [] modskill_p25 = [] for mod in exps: modserie = []
regnames = ['NAO+', 'SBL', 'NAO-', 'AR'] freq_ref = results_ref['freq_clus'] fig = plt.figure(figsize=(16,12)) axes = [] for reg in range(4): ax = plt.subplot(2,2,reg+1) frqall = np.array([freqs[cos][reg] for cos in keall]) ax.bar(np.arange(4), frqall-freq_ref[reg], color = colors) ax.set_title(regnames[reg]) ax.set_xticks([]) axes.append(ax) ctl.adjust_ax_scale(axes) ctl.custom_legend(fig, colors, laball, ncol = 2) fig.savefig(cart_out+'Regime_frequency.pdf') # Hist composite difference (HR, LR) compdiffs = dict() for varnam in ['tas', 'pr']: comps = [] for mod in okmods_hist_L: comps.append(composites[('present', mod, varnam, 'mean')]-composites[('present', 'ref', varnam, 'mean')]) print('CHECK', mod, np.mean(composites[('present', mod, varnam, 'mean')])) compdiffs[(varnam, 'LR')] = np.mean(comps, axis = 0) comps = [] for mod in okmods_hist_H: comps.append(composites[('present', mod, varnam, 'mean')]-composites[('present', 'ref', varnam, 'mean')]) print('CHECK', mod, np.mean(composites[('present', mod, varnam, 'mean')]))
ctl.primavera_boxplot_on_ax(ax, allpercs, model_names_all, colors_wERA, color_main, vers, ens_names, ens_colors, plot_mean=plot_mean) ax.set_ylabel(allylabels[nam]) #plt.title(alltits[nam]) #fig.suptitle(alltits[nam], fontsize = titlefont) ctl.custom_legend(fig, colors_wERA + ens_colors, model_names_all + ens_names, ncol=6) fig.savefig(cart_out + '{}_bootstraps_v7_k{}.pdf'.format(nam, numclus)) allfigs.append(fig) for nam in [ 'freq', 'dist_cen', 'resid_times_av', 'resid_times_90', 'patcor' ]: #, 'filt_dist_cen', 'filt_relative_entropy', 'filt_patcor']: fig = plt.figure(figsize=(20, 12)) axes = [] for ii, reg in enumerate(regnam): ax = plt.subplot(2, 3, ii + 1) allpercs = dict() for cos in ['mean', 'std', 'p10', 'p25', 'p50', 'p75', 'p90']:
#### Figurez # only stab fig, ax = ctl.get_cartopy_fig_ax(coast_lw=0.1) proj = ccrs.PlateCarree() for ru, col in zip(allru, colors): coso = monreg[(ru, 'stab')] ctl.plot_mapc_on_ax(ax, coso.values, coso.lat.values, coso.lon.values, proj, None, (0, 1), plot_type='binary_contour', lw_contour=2., line_color=col) ctl.custom_legend(fig, colors, allru, ncol=4) fig.savefig(cart_out + 'monsoon_stab.pdf') cosi = [mpi[(ru, 'stab')] for ru in allru] for co in cosi: co.values[co < 0.5] = np.nan ctl.plot_multimap_contour(cosi, filename=cart_out + 'monsoon_all.pdf', cbar_range=(0.5, 1.), subtitles=allru, cmap='viridis')
ax=ax, colors=cols, markers=marks, only_first_quarter=True, plot_ellipse=False, ellipse_color=colors[0], max_val_sd=1.6, title=patt, alpha_markers=0.8) #ax.text(0.95, 0.95, patt, horizontalalignment='center', verticalalignment='center', rotation='horizontal',transform=ax.transAxes, fontsize = 18) ctl.custom_legend(fig, cols, mods_all, markers=marks, ncol=4, add_space_below=0.05, loc='right', fontsize=14) fig.savefig(cart_out + 'taylor_{}_{}.pdf'.format(tip.split()[0], aaa)) # Taylor con ellipse for tip in ['tot LWA', 'trans LWA', 'Montg streamf']: patt_ref = resu['ERA5'][tip] fig = plt.figure(figsize=(16, 12)) for num, patt in enumerate(patnames): ax = plt.subplot(2, 2, num + 1, polar=True) obs = patt_ref[num] obs, lat_area, lon_area = ctl.sel_area(olat, olon, obs, areas[aaa])
pdf = ctl.calc_pdf(okjet) if vv in ['LR', 'OBS']: axes[reg].plot(latgri, pdf(latgri), color = col, label = mod, linewidth = linewidth, linestyle = sty) if vv in ['HR', 'OBS']: axes_HR[reg].plot(latgri, pdf(latgri), color = col, label = mod, linewidth = linewidth, linestyle = sty) pdf = ctl.calc_pdf(jetind) if vv in ['LR', 'OBS']: ax_all.plot(latgri, pdf(latgri), color = col, label = mod, linewidth = linewidth, linestyle = sty) if vv in ['HR', 'OBS']: ax_all_HR.plot(latgri, pdf(latgri), color = col, label = mod, linewidth = linewidth, linestyle = sty) ctl.adjust_ax_scale(axes+axes_HR) # ctl.custom_legend(fig, colors_wERA, model_names_all) ctl.custom_legend(fig, colors_wERA2[0::2], model_coups + ['OBS']) ctl.custom_legend(fig_HR, colors_wERA2[0::2], model_coups + ['OBS']) #fig.suptitle('Jet Latitude and Weather Regimes (SR)') fig.savefig(cart_out + 'jetlat_compos_LR{}.pdf'.format(tag)) #fig_HR.suptitle('Jet Latitude and Weather Regimes (HR)') fig_HR.savefig(cart_out + 'jetlat_compos_HR{}.pdf'.format(tag)) # fig.savefig(cart_out + 'jetlat_compos_wECEstream2.pdf') ctl.adjust_ax_scale([ax_all, ax_all_HR]) ctl.custom_legend(fig_all, colors_wERA2[0::2], model_coups + ['OBS']) #ctl.custom_legend(fig_all, colors_wERA, model_names_all) fig_all.savefig(cart_out + 'jetlat_allregs_LR{}.pdf'.format(tag)) ctl.custom_legend(fig_all_HR, colors_wERA2[0::2], model_coups + ['OBS']) fig_all_HR.savefig(cart_out + 'jetlat_allregs_HR{}.pdf'.format(tag)) pickle.dump(jetlat_comp, open(cart_out + 'jetlat_compos_all{}.p'.format(tag), 'wb'))
coso = runfreq[(ssp, 'run20', reg)] - np.mean( freqs[('hist', 'all', 'tot50')][:, reg]) coserr = runfreq[(ssp, 'run20err', reg)] ax.fill_between(yr, coso - coserr, coso + coserr, color=col, alpha=0.15) ax.plot(yr, coso, label=ssp, color=col, linewidth=2) ax.set_title(reg_names_area[area][reg]) ax.axvline(2015, color='lightslategray', linewidth=0.2, linestyle='--') ax.axhline(0., color='lightslategray', linewidth=0.2) axes.append(ax) ctl.adjust_ax_scale(axes) ctl.custom_legend(fig, colssp, allssps, ncol=3) fig.savefig(cart_out + 'allssps_freq20_{}_anom_wcmip5.pdf'.format(area)) fig = plt.figure(figsize=(27, 6)) axes = [] for reg in range(4): ax = fig.add_subplot(1, 4, reg + 1) for ssp in allssps: col = coldic[ssp] coso = runfreq[(ssp, 'run20', reg)] - np.mean( freqs[('hist', 'all', 'tot50')][:, reg]) coserr = runfreq[(ssp, 'run20err', reg)] ax.fill_between(yr, coso - coserr, coso + coserr, color=col,
ax = plt.subplot(3, 3, i) for num, col in zip(allnums, colors): ax.plot(dtclmpd.dayofyear, np.mean(clm_fullperiod[num][:, lla1:lla2, llo1:llo2], axis=(1, 2)), color=col) if lla2 is None: lla2 = -1 if llo2 is None: llo2 = -1 ax.set_title('lat {:2.0f}/{:2.0f}, lon {:3.0f}/{:3.0f}'.format( lat_area[lla1], lat_area[lla2], lon_area[llo1], lon_area[llo2])) axes.append(ax) ctl.adjust_ax_scale(axes) fig.tight_layout() fig = ctl.custom_legend(fig, colors, ['{}'.format(i) for i in allnums]) fig.savefig(cart_out + 'mean_climatology_zg.pdf') figs = [] axaxes = [[], [], []] colors = ctl.color_set(len(climate_mean_area)) for num in allnums: cosone = climate_mean_dict[num] ref = clm_fullperiod[num] fig = plt.figure(figsize=(16, 12)) i = 0 for uu, (lla1, lla2) in enumerate(lat_sect): for llo1, llo2 in lon_sect: i += 1
for nu in [10, 25, 50, 75, 90]: allpercs['p{}'.format(nu)] = [np.percentile(trend_ssp[(ssp, 'all', pio, cos, reg)], nu) for ssp in allsims[1:]] allpercs['ens_min'] = [np.min(trend_ssp[(ssp, 'all', pio, cos, reg)]) for ssp in allsims[1:]] allpercs['ens_max'] = [np.max(trend_ssp[(ssp, 'all', pio, cos, reg)]) for ssp in allsims[1:]] ctl.boxplot_on_ax(ax, allpercs, allsims[1:], colsim[1:], plot_mean = False, plot_ensmeans = False, plot_minmax = True) ax.axhline(0, color = 'gray', linewidth = 0.5) ax.set_xticks([]) ax.set_title(reg_names[reg]) ctl.adjust_ax_scale(axes) ctl.custom_legend(fig, colsim[1:], allsims[1:], ncol = 4) #fig.suptitle('30yr bsp of WR freq. in 2050-2100 wrt 1964-2014') fig.savefig(cart_out + '{}_WRfreq_allssp_{}_{}.pdf'.format(pio, area, cos)) fig = plt.figure(figsize = (16,12)) axes = [] for reg in range(4): ax = fig.add_subplot(2, 2, reg + 1) axes.append(ax) allpercs = dict() allpercs['mean'] = [np.mean(residtime_ssp[(ssp, 'all', pio, reg)]) for ssp in allsims[1:]] for nu in [10, 25, 50, 75, 90]: allpercs['p{}'.format(nu)] = [np.percentile(residtime_ssp[(ssp, 'all', pio, reg)], nu) for ssp in allsims[1:]]
for mod, col in zip(modoks, coloks): frdiff = results_ssp585[mod]['freq_clus'][reg] - results_hist[mod][ 'freq_clus'][reg] ax.scatter(i, frdiff, marker='D', color=col, s=25) allfreqs[(ssp, area, season, tip, reg)].append(results_ssp585[mod]['freq_clus'][reg] - results_hist[mod]['freq_clus'][reg]) # allfreqs[('hist', tip, reg)].append(results_hist[mod]['freq_clus'][reg]) i += 1 ax.axhline(0, color='gray', linewidth=0.5) ax.set_xticks([]) ax.set_title(reg_names[reg]) ctl.adjust_ax_scale(axes) ctl.custom_legend(fig, coloks, modoks, ncol=4) fig.suptitle('Change of WR freq. in 2050-2100 wrt 1964-2014') fig.savefig(cart_out + 'WR_freq_change_dtr_{}_{}_{}_{}.pdf'.format(*ke)) # Same but only for long-lasting (> 5 days) regimes for mod in modoks: results_ssp585[mod]['av_res'] = np.array([ np.mean(results_ssp585[mod]['resid_times'][reg]) for reg in range(4) ]) results_hist[mod]['av_res'] = np.array([ np.mean(results_hist[mod]['resid_times'][reg]) for reg in range(4) ]) labs = ctl.regime_filter_long(results_ssp585[mod]['labels'],
# ok200 = np.array([da.year > dates[-1].year-200 for da in dates]) # varok = var[ok200] # dateok = dates[ok200] # else: # varok = var # dateok = dates # # resdict[(ru, varnam, 'mean', 'mar')], resdict[(ru, varnam, 'std', 'mar')] = ctl.seasonal_climatology(varok, dateok, 'Mar') # resdict[(ru, varnam, 'mean', 'sep')], resdict[(ru, varnam, 'std', 'sep')] = ctl.seasonal_climatology(varok, dateok, 'Sep') axs[0, 0].set_title('March') axs[0, 1].set_title('September') axs[0, 0].set_ylabel(r'Sea ice extent (m$^2$)') axs[1, 0].set_ylabel(r'Sea ice extent (m$^2$)') #axs[1,1].legend() ctl.custom_legend(fig, colors2, allru2, ncol=3) fig.savefig(cart_out + 'bottseaice.pdf') sys.exit() # # miptab = 'SImon_r1' # var_map_200 = ['siconc', 'sithick'] # # mapmean = dict() # for na, ru, col in zip(allnams, allru, colors): # mem = 'r1' # filist = np.concatenate([glob.glob(filna.format(na, mem, miptab, varnam)) for varnam in var_map_200]) # gigi = xr.open_mfdataset(filist, use_cftime=True) # # if ru != 'pi':