allru = ['pi', 'b025', 'b050', 'b100'] allnams = ['piControl', 'stabilization-ssp585-2025', 'stabilization-ssp585-2050', 'stabilization-ssp585-2100'] colors = ['black', 'forestgreen', 'orange', 'violet'] allnams2 = allnams + ['ssp585', 'historical'] allru2 = allru + ['ssp585', 'hist'] colors2 = colors + ['indianred', 'steelblue'] #################################################################################################### glomeans, pimean, yeamean, mapmean = pickle.load(open(cart_in + 'bottino_seasmean_2D.p', 'rb')) var = 'tas' latbins = np.arange(-90, 91, 20) lacol = ctl.color_set(9, use_seaborn=False) for var in ['tas', 'pr']: fig, axs = plt.subplots(2, 3, figsize = (16,9)) for ru, ax in zip(allru2, axs.flatten()): coso = yeamean[(ru, var)] coso1 = coso[:10].mean(axis = 0) cosoanom = coso-coso1 ax.set_title(ru) smut = 50 if ru in ['ssp585', 'hist']: smut = 20 for la1, la2, col in zip(latbins[:-1], latbins[1:], lacol): print(la1,la2) cosolat = cosoanom.sel(lat = slice(la1, la2)).mean(['lat','lon'])
ps_low = ctl.butter_filter(ps, 50) #ps_low = ctl.running_mean(ps, 50) ax.plot(freqs[idx], ps_low[idx], linewidth = 2) ax.set_title(ru) if ax in axs[1, :]: ax.set_xlabel('freq (yr-1)') #ax.set_ylabel('amplitude') #ax.set_xlim(2, 10) #ctl.adjust_ax_scale(axs.flatten()) fig.savefig(cart_out + 'enso_spectra_all500.pdf') nchu = 5 nye = 100 colzz = ctl.color_set(5, cmap = 'viridis', use_seaborn=False) ps_max = dict() ps_ext = dict() fig, axs = plt.subplots(2, 2, figsize = (16,12)) for ru, ax in zip(allru, axs.flatten()): piuz = enso[ru]['tos'].groupby('time.year').mean() data_all = piuz.values.flatten() for ich, col in zip(range(nchu), colzz): data = data_all[ich*nye:(ich+1)*nye] ps = np.abs(np.fft.fft(data))**2 freqs = np.fft.fftfreq(data.size, 1)
ttests[(area, season, 'pos')] = np.stack(testyp) ttests[(area, season, 'neg')] = np.stack(testyn) deltapos = (pcpos - pcref) / koze_ref['pcs'].std(axis=0) deltaneg = (pcneg - pcref) / koze_ref['pcs'].std(axis=0) deltadist_all[(area, season, 'pos')] = deltapos deltadist_all[(area, season, 'neg')] = deltaneg ofidpc.write('------- {} - {} ----------\n'.format(area, season)) ofidpc.write(('pcs deltapos: ' + '{:10.2e}' * len(deltapos) + '\n').format(*deltapos)) ofidpc.write(('pcs deltaneg: ' + '{:10.2e}' * len(deltaneg) + '\n').format(*deltaneg)) ofidpc.write('---------------------------\n') colors = ctl.color_set(4) for ii, col in enumerate(colors): # eventi positivi okpo = coso_pos['labels'] == ii plt.scatter(coso_pos['pcs'][okpo, 0], coso_pos['pcs'][okpo, 1], color=col, s=10, marker='o') # eventi negativi okpo = coso_neg['labels'] == ii plt.scatter(coso_neg['pcs'][okpo, 0], coso_neg['pcs'][okpo, 1], color=col, s=10,
gen_file_ssp = cart_data + 'out_NEW_cmip6_{}_NDJFM_{}_4clus_4pcs_2015-2100_refCLUS_dtr_histrebase.p' yr10 = 10 # length of running mean numclus = 4 reg_names_area = dict() reg_names_area['EAT'] = ['NAO+', 'SBL', 'AR', 'NAO-'] reg_names_area['PNA'] = ['PT', 'PNA+', 'PNA-', 'BR'] #okmods = ['ACCESS-CM2_r1i1p1f1', 'BCC-CSM2-MR_r1i1p1f1', 'CanESM5_r1i1p1f1', 'CESM2-WACCM_r1i1p1f1','CNRM-CM6-1-HR_r1i1p1f2', 'CNRM-CM6-1_r1i1p1f2','CNRM-ESM2-1_r1i1p1f2', 'EC-Earth3_r1i1p1f1', 'FGOALS-g3_r1i1p1f1','INM-CM4-8_r1i1p1f1', 'INM-CM5-0_r1i1p1f1', 'IPSL-CM6A-LR_r1i1p1f1','MIROC6_r1i1p1f1', 'MPI-ESM1-2-HR_r1i1p1f1','MPI-ESM1-2-LR_r1i1p1f1', 'MRI-ESM2-0_r1i1p1f1','NorESM2-LM_r1i1p1f1', 'NorESM2-MM_r1i1p1f1', 'UKESM1-0-LL_r1i1p1f2'] # mancano = ['BCC-ESM1_r1i1p1f1', 'CESM2_r1i1p1f1', 'GFDL-CM4_r1i1p1f1', 'HadGEM3-GC31-LL_r1i1p1f3', 'KACE-1-0-G_r1i1p1f1', 'MPI-ESM-1-2-HAM_r1i1p1f1'] allssps = 'ssp126 ssp245 ssp370 ssp585'.split() allsimcol = [ 'hist', 'ssp126', 'ssp245', 'bau', 'ssp370', 'ssp585', 'rcp85_cmip5' ] coldic = dict(zip(allsimcol, ctl.color_set(7))) colssp = [coldic[ssp] for ssp in allssps] # tas_anom = dict() # tas_trends = dict() # for ssp in ['ssp585']: # print('SSP '+ssp) # # area = 'EAT' # cart_lui = cart_in + 'Results_v5_rebase/{}_NDJFM/'.format(area) # freqs, residtimes, patterns = pickle.load(open(cart_lui + 'allresults_dicts_{}_v3.p'.format(area), 'rb')) # # okmods = [ke[1] for ke in freqs if ssp in ke and 'tot50' in ke and 'all' not in ke and 'rel' not in ke] # if ssp == 'ssp126': # okmods = [mod for mod in okmods if mod != 'FGOALS-g3_r1i1p1f1'] # print(okmods)
all_years_ref = np.array([dat[0].year for dat in dates_climate_mean]) allnums = [1, 5, 10, 15, 20] clm_fullperiod = dict() for num in [1, 5, 10, 15, 20]: clm, dtclm, _ = ctl.daily_climatology(var, dates, num) clmarea, _, _ = ctl.sel_area(lat, lon, clm, 'EAT') clm_fullperiod[num] = clmarea dtclmpd = pd.to_datetime(dtclm) lat_sect = [(16, None), (8, 16), (0, 8)] lon_sect = [(0, 16), (16, 32), (32, None)] colors = ctl.color_set(len(allnums)) fig = plt.figure(figsize=(16, 12)) i = 0 for lla1, lla2 in lat_sect: axes = [] for llo1, llo2 in lon_sect: i += 1 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
cart_out_ERA = '/home/fabiano/Research/lavori/WeatherRegimes/phasespace_ERA/' # cart = '/home/fabiano/Research/lavori/WeatherRegimes/primavera_coupled_1957-2014/' # filo = cart + 'out_primavera_coupled_1957-2014_DJF_EAT_4clus_4pcs_1957-2014_dtr.p' tag = 'v4' cart = '/home/fabiano/Research/lavori/WeatherRegimes/prima_coup_v4/' filo = cart + 'out_prima_coup_v4_DJF_EAT_4clus_4pcs_1957-2014_refEOF.p' model_names = ['CMCC-CM2-HR4', 'CMCC-CM2-VHR4', 'CNRM-CM6-1', 'CNRM-CM6-1-HR', 'EC-Earth3P', 'EC-Earth3P-HR', 'ECMWF-IFS-LR', 'ECMWF-IFS-HR', 'MPI-ESM1-2-HR', 'MPI-ESM1-2-XR', 'HadGEM3-GC31-MM', 'HadGEM3-GC31-HM', 'HadGEM3-GC31-LL-det', 'HadGEM3-GC31-LL-stoc', 'EC-Earth3P-det', 'EC-Earth3P-stoc'] model_coups = ['CMCC-CM2', 'CNRM-CM6-1', 'EC-Earth3P', 'ECMWF-IFS', 'MPI-ESM1-2', 'HadGEM3-GC31', 'HadGEM3-GC31 (det vs stoc)', 'EC-Earth3P (det vs stoc)'] model_names_all = model_names + ['ERA'] model_coups = ['CMCC-CM2', 'CNRM-CM6-1', 'EC-Earth3P', 'ECMWF-IFS', 'MPI-ESM1-2', 'HadGEM3-GC31', 'HadGEM3-GC31 (det vs stoc)', 'EC-Earth3P (det vs stoc)'] colors = ctl.color_set(len(model_names), sns_palette = 'Paired') colors_wERA = colors + ['black'] # # Ora tutte le statistiche resolution = np.array([100, 25, 250, 50, 100, 50, 50, 25, 100, 50, 100, 50, 250, 250, 250, 100, 100]) sym_all = ['o', 'P','o', 'P','o', 'P','o', 'P','o', 'P','o', 'P', 's', '*', 's', '*'] wi = 0.6 # # Ora tutte le statistiche stat_nams = ['KS 1D', 'Clus radius', 'Clus std', 'KS dist refcentroid', 'dist centocen'] titles = ['1D Kolmogorov-Smirnov statistics on regime pdfs', 'Cluster radius', 'Cluster internal std dev', '1D KS on distance to reference centroid', 'Distance of centroid to reference centroid'] allfigs = [] eof_axis_lim = (-3000., 3000.)
fil_jet = 'JetLatDist_850hPa_{}_hist-1950_DJF.npy' file_ERA = '/home/fabiano/Research/lavori/Jet_latitude/jli_ERA_1957_2014.npy' cart_bloc = '/data-hobbes/fabiano/PRIMAVERA/Reinhard_blocking/all_hist-1950/' fil_bloc = 'bf.5day.daily.daily_mean.{}.{}.hist-1950.r1i1p1f1.v20170915.{}-{}.nc' # model_names = ['AWI-CM-1-1-LR', 'AWI-CM-1-1-HR', 'CMCC-CM2-HR4', 'CMCC-CM2-VHR4', 'CNRM-CM6-1', 'CNRM-CM6-1-HR', 'EC-Earth3P', 'EC-Earth3P-HR', 'ECMWF-IFS-LR', 'ECMWF-IFS-HR', 'MPI-ESM1-2-HR', 'MPI-ESM1-2-XR', 'HadGEM3-GC31-LL', 'HadGEM3-GC31-MM']#'HadGEM3-GC31-HM'] model_names = ['CMCC-CM2-HR4', 'CMCC-CM2-VHR4', 'CNRM-CM6-1', 'CNRM-CM6-1-HR', 'EC-Earth3P', 'EC-Earth3P-HR', 'ECMWF-IFS-LR', 'ECMWF-IFS-HR', 'MPI-ESM1-2-HR', 'MPI-ESM1-2-XR', 'HadGEM3-GC31-LL', 'HadGEM3-GC31-MM'] model_mems = ['r1i1p1f1', 'r1i1p1f1', 'r1i1p1f2', 'r1i1p1f2', 'r3i1p2f1', 'r1i1p2f1', 'r1i1p1f1', 'r1i1p1f1', 'r1i1p1f1', 'r1i1p1f1', 'r1i1p1f1', 'r1i1p1f1', ''] vers = 6*['LR', 'HR'] + ['OBS'] # model_coups = ['AWI-CM-1-1', 'CMCC-CM2', 'CNRM-CM6-1', 'EC-Earth3P', 'ECMWF-IFS', 'MPI-ESM1-2', 'HadGEM3-GC31'] model_coups = ['CMCC-CM2', 'CNRM-CM6-1', 'EC-Earth3P', 'ECMWF-IFS', 'MPI-ESM1-2', 'HadGEM3-GC31'] model_names_all = model_names + ['ERA'] colors2 = ctl.color_set(len(model_coups)) col22 = list(np.concatenate([[co, co] for co in colors2])) colors_wERA2 = col22 + ['black'] # styall = np.empty(len(colors_wERA2), dtype = str) # styall[0::2] = ':' # styall[1::2] = '-' # styall[-1] = '-' colors = ctl.color_set(len(model_names), sns_palette = 'Paired') colors_wERA = colors + ['black'] # colors_wERA2 = np.array(colors_wERA) # colors_wERA2[0:-1:2] = colors_wERA2[1::2] colors = ctl.color_set((len(model_coups)+1)*2, sns_palette = 'Paired') colorscoup = [np.mean([col1, col2], axis = 0) for col1, col2 in zip(colors[:-1:2], colors[1::2])] color_main = []
file_hist = cart_in + 'out_NEW_cmip6_hist_NDJFM_{}_4clus_4pcs_{}-{}_refCLUS_dtr.p' file_hist_refEOF_cmip5 = '/home/fabiano/Research/lavori/CMIP6/cmip5_hist_reb/out_cmip5_hist_reb_NDJFM_{}_4clus_4pcs_{}-{}_refEOF_dtr.p' file_hist_cmip5 = '/home/fabiano/Research/lavori/CMIP6/cmip5_hist_reb/out_cmip5_hist_reb_NDJFM_{}_4clus_4pcs_{}-{}_refCLUS_dtr.p' numclus = 4 reg_names_area = dict() reg_names_area['EAT'] = ['NAO+', 'SBL', 'AR', 'NAO-'] reg_names_area['PNA'] = ['PT', 'PNA+', 'PNA-', 'BR'] clatlo = dict() clatlo['EAT'] = (70., -20.) clatlo['PNA'] = (70., -120.) colormip = dict() colormip[('cmip5', 'EAT')] = ctl.color_set(7)[4] colormip[('cmip6', 'EAT')] = ctl.color_set(7)[0] colormip[('cmip5', 'PNA')] = ctl.color_set(7)[3] colormip[('cmip6', 'PNA')] = ctl.color_set(7)[6] area = 'EAT' plocos = dict() res_short = dict() for area in ['EAT', 'PNA']: print(area) cart_out = cart_out_orig + '{}_NDJFM/'.format(area) ctl.mkdir(cart_out) results_hist, results_ref = ctl.load_wrtool( file_hist.format(area, ye1, ye2)) results_hist_refEOF, _ = ctl.load_wrtool(
bauda = np.arange(1965, 2015) gigi = results_ssp[mod]['var_dtr'] gigida = np.arange(2015, 2100) fig = plt.figure() plt.plot(bauda, bau) plt.plot(bauda, np.polyval(results_hist[mod]['coeffs_dtr'], bauda), linestyle='--') plt.plot(gigida, gigi) plt.plot(gigida, np.polyval(results_ssp[mod]['coeffs_dtr'], gigida), linestyle='--') fig.savefig(cart_out_orig + 'vardtr_check.pdf') fig = plt.figure() cols = ctl.color_set(len(results_ssp.keys())) for mod, co in zip(results_ssp.keys(), cols): try: bau = results_hist[mod]['var_dtr'] bauda = np.arange(1965, 2015) gigi = results_ssp[mod]['var_dtr'] gigida = np.arange(2015, 2100) plt.scatter(bauda, bau, color=co, s=2) plt.plot(bauda, np.polyval(results_hist[mod]['coeffs_dtr'], bauda), color=co, linewidth=0.5) plt.scatter(gigida, gigi, color=co, s=2) plt.plot(gigida, np.polyval(results_ssp[mod]['coeffs_dtr'], gigida), color=co,
mem = allmems[0] fils_HR = np.concatenate([glob.glob(fir_HR.format(mod, tip, mem, var, var)) for var in allvars]) flux_hr = xr.open_mfdataset(fils_HR, use_cftime = True) flux_hr = flux_hr.assign(net_sfc = flux_hr.rsds + flux_hr.rlds - flux_hr.rsus - flux_hr.rlus - flux_hr.hfss - flux_hr.hfls) # net downward energy flux at surface flux_hr = flux_hr.assign(net_toa = flux_hr.rsdt - flux_hr.rlut - flux_hr.rsut) # net downward energy flux at TOA flux_hr = flux_hr.assign(in_atm = flux_hr.net_toa - flux_hr.net_sfc) flux_hr = flux_hr.drop_vars('time_bnds') resuu[na+'_'+tipna] = flux_hr allvars = allvars + ['net_sfc', 'net_toa', 'in_atm'] colors = ctl.color_set(len(resuu)) ### Add global mean timeseries figs_global = [] 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)
filename = cart_out_orig + 'zontrend_ssp585.pdf' oklats = lat >= 30 fig = plt.figure(figsize=(16, 12)) ax = fig.add_subplot(111) for modmem, co in zip(okmods, zontrend): ax.plot(co[oklats], lat[oklats], label=modmem) ax.plot(np.mean(zontrend, axis=0)[oklats], lat[oklats], label='MMM', color='black', linewidth=3) ax.axvline(0., color='lightslategray', linewidth=0.2) plt.legend() fig.savefig(filename) cols = np.array(ctl.color_set(7))[1::2] filename = cart_out_orig + 'zontrend_ssp585_MMM.pdf' fig = plt.figure(figsize=(16, 12)) ax = fig.add_subplot(111) coso = np.mean(zontrend, axis=0)[oklats] coserr = np.std(zontrend, axis=0)[oklats] / np.sqrt(len(zontrend) - 1) ax.fill_betweenx(lat[oklats], coso - coserr, coso + coserr, color=cols[0], alpha=0.2) ax.plot(coso, lat[oklats], color=cols[0], linewidth=2, label='NML') coso = np.mean(zontrend_PNA, axis=0)
cyea = [np.mean(ran) for ran in yr_ranges] histran = (1850, 2005) futran = (2006, 2100) cartsig = cart + 'sig/' sigs_EAT = [] sigs_PNA = [] for ens in ensmem: sig_a = np.array([results[(ens,'EAT',ran)]['significance'] for ran in yr_ranges]) sig_p = np.array([results[(ens,'PNA',ran)]['significance'] for ran in yr_ranges]) sigs_EAT.append(sig_a) sigs_PNA.append(sig_p) colors = ctl.color_set(6, bright_thres = 0.2) for area in ['EAT', 'PNA']: fig = plt.figure() for ens in base_ens: sig = np.array([results[(ens,area,ran)]['significance'] for ran in yr_ranges]) plt.plot(cyea, sig, label = ens) # plt.scatter(cyea, sig, color = col, marker = sym, label = ens) plt.legend() plt.ylabel('Significance') plt.xlabel('central year of 30yr period') plt.title(area+' - base runs') fig.savefig(cartsig+'Sig_{}_base_5yr.pdf'.format(area)) fig = plt.figure() for ens in stoc_ens:
for flun in fluxnames: for seas in seasons+['year']: for taw in ['zonal', 'maps', 'cross']: fluxes_model[(ens, flun, seas, taw, am)] = np.mean([coso[flun][taw][seas] for coso in results_year], axis = 0) pickle.dump(fluxes_model, open(cart_out+'out_hfc_NEW_lcb0vslcs0.p', 'wb')) seasonsall = ['year']+seasons figure_file = cart_out + 'hfc_lcb0_vs_lcs0_NEW.pdf' figures = [] for flun in fluxnames: for ann in annme: fig = plt.figure() plt.title('{} fluxes - {}'.format(flun, ann)) cset = ctl.color_set(len(seasonsall), bright_thres = 1) for seas, col in zip(seasonsall, cset): plt.plot(lat, fluxes_model[('lcb0', flun, seas, 'zonal', ann)], label = 'base '+seas, color = col, linewidth = 2.) plt.plot(lat, fluxes_model[('lcs0', flun, seas, 'zonal', ann)], label = 'stoc '+seas, color = col, linewidth = 2., linestyle = '--') plt.plot(lat, era_fluxes_zonal[(flun, seas)], label = 'ref '+seas, color = col, linewidth = 0.7, linestyle = ':') plt.legend() plt.grid() plt.ylim(limits[('zonal', flun)]) plt.xlabel('Latitude') plt.ylabel('Integrated Net Heat Flux (W)') figures.append(fig) ctl.plot_pdfpages(figure_file, figures) figure_file = cart_out + 'maps_hfc_lcb0_vs_lcs0_NEW.pdf'
global_anom_b = np.mean(global_anom_ens[:3, ...], axis=0) global_anom_s = np.mean(global_anom_ens[3:, ...], axis=0) # med_anom_b = np.mean(med_anom_ens[:3, ...], axis = 0) # med_anom_s = np.mean(med_anom_ens[3:, ...], axis = 0) # med_anom_sum_b = np.mean(med_anom_sum_ens[:3, ...], axis = 0) # med_anom_sum_s = np.mean(med_anom_sum_ens[3:, ...], axis = 0) yearly_anom_b = np.mean(yearly_anom_ens[:3, ...], axis=0) yearly_anom_s = np.mean(yearly_anom_ens[3:, ...], axis=0) #monthly_climat_b = np.mean(month_climat_ens[:3, ...], axis = 0) #monthly_climat_s = np.mean(month_climat_ens[3:, ...], axis = 0) #plt.ion() fig = plt.figure() years_pdh = pd.to_datetime(years) cset = ctl.color_set(len(years), bright_thres=0., full_cb_range=True) for year, col in zip(years_pdh.year, cset): plt.plot(lat, zonal_anom_b[years_pdh.year == year].squeeze(), color=col) plt.xlabel('Latitude') plt.ylabel('Temperature anomaly [K]') fig.subplots_adjust(right=0.8) plt.grid() plt.xlim(-90, 90) plt.ylim(-3., 18.) plt.title('Zonal temperature anomaly (base)') cbar_ax = fig.add_axes([0.83, 0.12, 0.05, 0.7]) norm = mpl_colors.Normalize(vmin=years_pdh.year[0], vmax=years_pdh.year[-1])
trend_ssp[(ssp, 'all', 'errtrend', 'seafreq', reg)] = np.array([ trend_ssp[(ssp, mem, 'errtrend', 'seafreq', reg)] for mem in okmods ]) trend_ssp[(ssp, 'all', 'trend', 'freq10', reg)] = np.array( [trend_ssp[(ssp, mem, 'trend', 'freq10', reg)] for mem in okmods]) trend_ssp[(ssp, 'all', 'errtrend', 'freq10', reg)] = np.array([ trend_ssp[(ssp, mem, 'errtrend', 'freq10', reg)] for mem in okmods ]) pickle.dump([freqs, trend_ssp, residtimes, num_event], open(cart_out + 'freqs_cmip5_{}.p'.format(area), 'wb')) pickle.dump([seasfreq, runfreq], open(cart_out + 'seasfreqs_cmip5_{}.p'.format(area), 'wb')) allsims = ['hist_cmip5', 'rcp85_cmip5'] colsim = ctl.color_set(2) figall = plt.figure(figsize=(16, 12)) axes = [] cos = 'tot50' for reg in range(4): ax = figall.add_subplot(2, 2, reg + 1) 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 ]
results = dict() for ex in exps: fiok = finam.format(ex, ex) gigi = pickle.load(open(fiok, 'rb')) modnam = list(gigi['models'].keys())[0] results[ex] = gigi['models'][modnam] results_ref = gigi['reference'] gigi = pickle.load( open( '/home/fedefab/Scrivania/Research/Post-doc/lavori/ecmwf_seasonal/ERA_test/out_ERA_test_DJF_EAT_4clus_4pcs_1981-2010_refEOF.p', 'rb')) results['ERA'] = gigi['models']['ERA'] colors = ctl.color_set(len(exps)) colors_all = colors + ['black'] exps_all = exps + ['ERA'] patnames = ['NAO+', 'SBL', 'AR', 'NAO-'] ## Diagnostics ## Plots: variance ratio, patcor & phase space, persistence, frequency ## Two versions: simple and with ensemble member spread # Variance ratio figs = [] fig = plt.figure(figsize=(16, 12)) #ax = fig.add_subplot(111)
rescoso[(tip, 'ssp585')][mem]['dates'] ]) pcs = np.concatenate([ rescoso[(tip, 'hist')][mem]['pcs'], rescoso[(tip, 'ssp585')][mem]['pcs'] ], axis=0) cosone[mem]['labels'] = labs cosone[mem]['dates'] = dats cosone[mem]['pcs'] = pcs resdict[tip] = cosone alltips = tuple(resdict.keys()) colorz = ctl.color_set(len(alltips)) runfreq = dict() seasfreq = dict() figs = [] for tip, col in zip(alltips, colorz): okmods = resdict[tip].keys() fig = plt.figure(figsize=(16, 12)) for reg in range(4): ax = fig.add_subplot(2, 2, reg + 1) cosi = [] for mem in okmods: seasfr, yr = ctl.calc_seasonal_clus_freq( resdict[tip][mem]['labels'], resdict[tip][mem]['dates'], numclus)
plt.rcParams['axes.titlesize'] = 28 plt.rcParams['axes.labelsize'] = 18 plt.rcParams['axes.axisbelow'] = True ############################################################################# # leggi cose cart_in = '/home/fedef/Research/lavori/paolitos_LWA/LWA_timeseries/' cart_out = '/home/fedef/Research/lavori/paolitos_LWA/' filin = cart_in + 'timeseries_{}_{}.p' areas = ['NH', 'EAT'] #, 'PNA'] versions = ['LR', 'MR', 'HR'] colors = ctl.color_set(12, sns_palette='Paired') cose = dict() for area in areas: cose[area] = dict() for vers in versions: print(area, vers) gigi = pickle.load(open(filin.format(area, vers), 'rb')) print(gigi['domain'], gigi['resolution']) #cose[(area, vers)] = gigi['timeseries'] mod_names = gigi['labels'] if 'ERA5' in mod_names: cose[area]['obs'] = gigi['timeseries'][0] mod_names = mod_names[1:] ts = gigi['timeseries'][1:] for mod, tise in zip(mod_names, ts):
ctl.mkdir(cart_out_gen.format(ensmod)) figscores = dict() rsq_old = dict() xssdi = dict() for reg in regtip: fig_score, axs = plt.subplots(figsize=(12, 8)) figscores[(reg, 0)] = (fig_score, axs) fig_score, axs = plt.subplots(figsize=(12, 8)) figscores[(reg, 1)] = (fig_score, axs) rsq_old[reg] = None for nu, colnu in zip(np.arange(2, 8), ctl.color_set(6)): print('Finding best {} drivers'.format(nu)) allcombs = list(itt.combinations(range(len(drilis)), nu)) okcombs = dict() allscores = dict() #faccio cose for reg in regtip: print(reg) allscores[reg] = [] okcombs[reg] = [] # pesca i drivers, uno per tipo, e fai il model for ii, comb in enumerate(allcombs): # print(ii, comb)
]) trend_ssp[(ssp, 'all', 'errtrend', 'freq10', reg)] = np.array([ trend_ssp[(ssp, mem, 'errtrend', 'freq10', reg)] for mem in okmods ]) residtime_ssp[(ssp, 'all', 'trend', reg)] = np.array( [residtime_ssp[(ssp, mem, 'trend', reg)] for mem in okmods]) residtime_ssp[(ssp, 'all', 'errtrend', reg)] = np.array( [residtime_ssp[(ssp, mem, 'errtrend', reg)] for mem in okmods]) pickle.dump([trend_ssp, residtime_ssp], open(cart_out + 'trends_wrfreq_e_restime_{}.p'.format(area), 'wb')) allsims = ['hist', 'ssp126', 'ssp245', 'ssp370', 'ssp585'] colsim = ctl.color_set(5) reg_names = reg_names_area[area] kess = [ke for ke in trend_ssp.keys() if 'all' in ke] print(kess) for pio in ['trend', 'errtrend']: for cos in ['seafreq', 'freq10']: 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()
for loe, erol in enumerate(era_lon): total_eragrid[lae, loe] = pinotot(eral, erol) diff = total_eragrid - era_fluxes_maps[(seas, 'tot')] fig = ctl.plot_map_contour( diff, era_lat, era_lon, title='Difference vs ERA flux - {} {} {}'.format( exp, year, seas), plot_anomalies=True) figures_exp_maps.append(fig) for flun in fluxnames: fig = plt.figure() plt.title('{} fluxes - {}'.format(shortnam[flun], year)) cset = ctl.color_set(3, bright_thres=1) for seas, col in zip(press0.keys(), cset): plt.plot(lat, fluxes_zonal[(seas, flun)], label=seas, color=col, linewidth=2.) plt.plot(lat, era_fluxes_zonal_itrp[(seas, flun)], label='ERA ' + seas, color=col, linewidth=0.7, linestyle='--') plt.legend() plt.grid() plt.ylim(zonal_margins[flun])
for mod in all_res: print(mod, all_res[mod][17].keys()) all_figures = [] # ellipse plot nsqr = np.sqrt(results_ref['cluspattern_area'].size) pattnames = ['NAO +', 'Sc. Blocking', 'Atl. Ridge', 'NAO -'] fig = plt.figure(figsize=(16, 12)) for i in range(4): ax = fig.add_subplot(2, 2, i + 1) ax.set_title(pattnames[i], fontsize=18, fontweight='bold') ax.grid() colors = ctl.color_set(len(all_res.keys())) ctl.ellipse_plot( [ens_mean[(mod, 'patcor')][i] for mod in all_res.keys()], [ens_mean[(mod, 'RMS')][i] / nsqr for mod in all_res.keys()], [ens_std[(mod, 'patcor')][i] for mod in all_res.keys()], [ens_std[(mod, 'RMS')][i] / nsqr for mod in all_res.keys()], alpha=0.7, ax=ax, colors=colors) for mod, col in zip(all_res.keys(), colors): pats = [coso['patcor'][i] for coso in all_res[mod]] rmss = [coso['RMS'][i] / nsqr for coso in all_res[mod]] ax.scatter(pats, rmss, color=col, s=5) ax.set_xlim(0.4, 1.0)
all_stats = pickle.load(open(cart_out + 'KS_stat_1000.p')) all_stats += [all_centtocent_dist] stat_nams = ['KS 1D', 'Clus radius', 'Clus std', 'KS dist refcentroid', 'dist centocen'] titles = ['1D Kolmogorov-Smirnov statistics on regime pdfs', 'Cluster radius', 'Cluster internal std dev', '1D KS on distance to reference centroid', 'Distance of centroid to reference centroid'] ERA_ref_thresholds = dict() for stat, nam, tit in zip(all_stats, stat_nams, titles): 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(stat[(n_choice, reg)]) for perc in [1, 5, 10, 100/3., 50, 200/3., 90, 95, 99]: ERA_ref_thresholds[(nam, n_choice, reg, perc)] = np.percentile(allvals, perc) kpdf = ctl.calc_pdf(allvals) #xvec = np.linspace(0., 0.4, 500) if 'KS' in nam:
seasfreq.update(seasfreq_cmip5) runfreq.update(runfreq_cmip5) num_event.update(num_event_cmip5) allssps = ['ssp126', 'ssp245', 'ssp370', 'ssp585', 'rcp85_cmip5'] allsims = ['hist', 'ssp126', 'ssp245', 'ssp370', 'ssp585', 'rcp85_cmip5'] allsims_wcmip5 = [ 'hist', 'ssp126', 'ssp245', 'ssp370', 'ssp585', 'hist_cmip5', 'rcp85_cmip5' ] allsimcol = [ 'hist', 'ssp126', 'ssp245', 'hist_cmip5', 'ssp370', 'ssp585', 'rcp85_cmip5' ] colorzi = ctl.color_set(7) allsimcol = [ 'ssp370', 'ssp245', 'ssp126', 'bau', 'rcp85_cmip5', 'ssp585', 'bau2' ] coldic = dict(zip(allsimcol, colorzi)) coldic['hist'] = 'darkslategray' coldic['hist_cmip5'] = 'saddlebrown' colsim = [coldic[ssp] for ssp in allsims] colssp = [coldic[ssp] for ssp in allssps] colsim_wcmip5 = [coldic[ssp] for ssp in allsims_wcmip5] yr = np.arange(1965, 2100) fig = plt.figure(figsize=(16, 12)) axes = [] for reg in range(4):
'MPI-ESM1-2-XR', 'HadGEM3-GC31-LL', 'HadGEM3-GC31-MM', 'HadGEM3-GC31-HM', 'HadGEM3-GC31-HH' ] vers = [ 'LR', 'HR', 'LR', 'HR', 'LR', 'HR', 'LR', 'HR', 'LR', 'MR', 'HR', 'LR', 'HR', 'LR', 'MR', 'MR', 'HR' ] + ['OBS'] model_coups = [ 'AWI-CM-1-1', 'CMCC-CM2', 'CNRM-CM6-1', 'EC-Earth3P', 'ECMWF-IFS', 'MPI-ESM1-2', 'HadGEM3-GC31' ] model_names_all = model_names + ['ERA'] colors = ctl.color_set(len(model_coups) * 2, sns_palette='Paired') colorscoup = [ np.mean([col1, col2], axis=0) for col1, col2 in zip(colors[:-1:2], colors[1::2]) ] mr_cos = np.where(np.array(vers) == 'MR')[0] for gi in mr_cos: colors.insert(gi, np.mean(colors[gi - 1:gi + 1], axis=0)) colors_wERA = colors + ['black'] # # Ora tutte le statistiche # atm_resolution = np.array([250, 100, 100, 25, 250, 50, 100, 50, 50, 50, 25, 100, 50, 250, 100, 50, 50]) # oce_resolution = np.array([50, 25, 25, 25, 100, 25, 100, 25, 100, 25, 25, 40, 40, 100, 25, 25, 8]) atm_resolution = np.array(
for ssp in allssps: for reg in range(4): trend_ssp[(ssp, 'all', 'trend', 'seafreq', reg)] = np.array([trend_ssp[(ssp, mem, 'trend', 'seafreq', reg)] for mem in okmods_ssp]) trend_ssp[(ssp, 'all', 'errtrend', 'seafreq', reg)] = np.array([trend_ssp[(ssp, mem, 'errtrend', 'seafreq', reg)] for mem in okmods_ssp]) trend_ssp[(ssp, 'all', 'trend', 'freq10', reg)] = np.array([trend_ssp[(ssp, mem, 'trend', 'freq10', reg)] for mem in okmods_ssp]) trend_ssp[(ssp, 'all', 'errtrend', 'freq10', reg)] = np.array([trend_ssp[(ssp, mem, 'errtrend', 'freq10', reg)] for mem in okmods_ssp]) residtime_ssp[(ssp, 'all', 'trend', reg)] = np.array([residtime_ssp[(ssp, mem, 'trend', reg)] for mem in okmods_ssp]) residtime_ssp[(ssp, 'all', 'errtrend', reg)] = np.array([residtime_ssp[(ssp, mem, 'errtrend', reg)] for mem in okmods_ssp]) pickle.dump([trend_ssp, residtime_ssp], open(cart_out + 'trends_wrfreq_e_restime_{}.p'.format(area), 'wb')) #allsims = ['hist', 'ssp126', 'ssp245', 'ssp370', 'ssp585'] allsims = ['hist', 'ssp585'] colsim = [ctl.color_set(5)[0], ctl.color_set(5)[-1]] reg_names = reg_names_area[area] kess = [ke for ke in trend_ssp.keys() if 'all' in ke] print(kess) for pio in ['trend', 'errtrend']: for cos in ['seafreq', 'freq10']: 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()
cart_out = cart_in + 'FutWR_{}_{}_{}_{}/'.format(*ke) ctl.mkdir(cart_out) results_hist, results_ref = pickle.load(open(file_hist, 'rb')) results_ssp585, results_ref = pickle.load(open(file_ssp585, 'rb')) if tip == 'refCLUS': res_hist_refEOF, _ = pickle.load( open(gen_file_hist.format(season, area, 'refEOF'), 'rb')) ### plot 0: WR freq difference tra ssp e hist, per ogni WR reg_names = reg_names_area[area] modoks = [ mod for mod in results_ssp585.keys() if mod in results_hist.keys() ] coloks = ctl.color_set(len(modoks)) fig = plt.figure(figsize=(16, 12)) axes = [] for reg in range(4): ax = fig.add_subplot(2, 2, reg + 1) axes.append(ax) i = 0 allfreqs[(ssp, area, season, tip, reg)] = [] 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] -
lat=slice(-20., 20.)).mean(['lon', 'lat']) coso_hr = flux_hr[var].sel(time=slice('1999-01-01', '1999-01-30'), lat=slice(-20., 20.)).mean(['lon', 'lat']) # guplo3 = coso_lr.plot(y = 'plev', col = 'time', col_wrap = 6, ylim = (1.e5, 1.e3), yscale = 'log', color = 'forestgreen') # guplo2 = coso_hr.plot(ylim = (1.e5, 1.e3), yscale = 'log', color = 'indianred') # plt.title(var) # plt.savefig(cart + '{}_profs_1mo_799-cntrl.pdf'.format(var)) # figs_prof.append(fig) lrko = coso_lr.data.compute() lrko_diff = np.diff(lrko, axis=0) hrko = coso_hr.data.compute() hrko_diff = np.diff(hrko, axis=0) levs = coso_hr.plev.data cols = ctl.color_set(29, sns_palette='crest') # plt.figure() # for ii, co in zip(range(29), cols): # plt.plot(hrko_diff[ii, :], levs, linestyle = '-', color = co) # plt.plot(lrko_diff[ii, :], levs, linestyle = '--', color = co) # plt.yscale('log') # plt.ylim(1.e5, 1.e3) hrko1 = np.mean(hrko_diff[:10, :], axis=0) hrko2 = np.mean(hrko_diff[10:20, :], axis=0) hrko3 = np.mean(hrko_diff[20:, :], axis=0) lrko1 = np.mean(lrko_diff[:10, :], axis=0) lrko2 = np.mean(lrko_diff[10:20, :], axis=0) lrko3 = np.mean(lrko_diff[20:, :], axis=0) colok = [cols[0], cols[15], cols[-1]] fig = plt.figure() plt.plot(hrko1, levs, linestyle='-', color=colok[0], label='days 1-10')
cmappa = heatmap cosoanom = cosolow - presme.values[np.newaxis, ...] #cbar_range = ctl.get_cbar_range(cosoanom, symmetrical = True) cbar_range = (-10, 10) elif var == 'pr': cmappa = cm.get_cmap('BrBG') #cosoanom = 100*(cosolow-presme.values[np.newaxis, ...])/presme.values[np.newaxis, ...] cosoanom = 86400. * (cosolow - presme.values[np.newaxis, ...] ) * 365 # this should be mm per year # cbar_range = ctl.get_cbar_range(cosoanom, symmetrical = True) # cbar_range = (cbar_range[0]/10., cbar_range[1]/10.) cbar_range = (-250, 250) #cbar_range = (-30, 30) clevels = np.linspace(cbar_range[0], cbar_range[1], 21) cset = ctl.color_set(len(anni), bright_thres=0., full_cb_range=True) cosdue[var] = cosoanom ##### print('flat global {} {}'.format(var, ssp)) fig, ax = ctl.get_cartopy_fig_ax(visualization='standard', central_lat_lon=(0, 0), bounding_lat=None, figsize=(16, 9), coast_lw=1) #tit = plt.title('1850') # Plotting figure proj = ccrs.PlateCarree()
plt.legend(fontsize='small', loc=1) plt.title('Significance of regime structure - ECMWF ensemble') keytot = key_LR + key_HR plt.xticks(list(range(len(keytot))), keytot, size='small') plt.ylabel('Significance') fig.savefig(cart + 'Significance_ECMWF.pdf') # print('\n \n \n SOSTITUISCO LA MEDIAAA DI ECMWFFFFFFF\n \n \n') # sig['ECMWF_LR'] = mean_LR # sig['ECMWF_HR'] = mean_HR syms = ['$H$'] * len(models) + ['$L$'] * len(models) + ['D'] labels = ['ECE', 'HadGEM', 'CMCC', 'CNRM', 'MPI', 'ECMWF' ] + 6 * [None] + ['NCEP'] colors = ctl.color_set(len(models) + 1) wi = 0.3 #plt.ion() fig = plt.figure() lab1 = 'LR' lab2 = 'HR' for i, mod in enumerate(models): # plt.scatter(i, sig[mod+'_LR'], color = 'green', s=20, marker = '$L$') # plt.scatter(i, sig[mod+'_HR'], color = 'orange', s=20, marker = '$H$') if i > 0: lab1 = None lab2 = None plt.bar(i - wi / 2, sig[mod + '_LR'], width=wi, color='green', label=lab1) plt.bar(i + wi / 2, sig[mod + '_HR'], width=wi, color='orange', label=lab2) plt.bar(i + 1 - wi / 2, sig['ERA'], width=wi, color='black', label='ERA')