def calc_SNR(): SNRs = [] N = 20 for endyear in range(2021, 2096): print(endyear) members = [] for i in range(1, N + 1): ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + ".cam.h0." + varcode + ".202001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2020, tim2=endyear, varcode=varcode) trend = vartimeobj.trend_lat_lon(season) members.append(trend) ensmean, ensstd = ensemble_functions.stats(members) SNR = abs(ensmean) / (ensstd / np.sqrt(N - 1)) SNRs.append(SNR) dim = 'endyear' new_coord = range(2021, 2096) func = lambda *x: np.stack(x, axis=-1) xSNR = xr.apply_ufunc(func, *SNRs, output_core_dims=[[dim]], join='outer', dataset_fill_value=np.nan) xSNR[dim] = new_coord xSNR.to_netcdf('SNR_' + varcode + '_trend.nc') return
new_coord = range(len(members_control)) func = lambda *x: np.stack(x, axis=-1) stack = xr.apply_ufunc(func, *members_control, output_core_dims=[[dim]], join='outer', dataset_fill_value=np.nan) stack[dim] = new_coord # Interannual sigma from residuals of annual means from member average gives similar results ensmean_control = stack.mean(dim=('time','member')) ensstd_control = stack.std(dim=('time','member')) plot_functions.plot_ToE(ensstd_control, ensstd_control['lat'], ensstd_control['lon'], '(b) Interannual $\sigma$', outdir+'stdcontrol.png', 0.4, 3.6, 0.4, '$\circ$C') #******************************************************************************************************** # 2) Signal: end of century Feedback response members = clim_defs.clim_lat_lon('feedback',season,varcode) ensmean, ensstd = ensemble_functions.stats(members) ensdiff = ensmean - ensmean_control plot_functions.plot_single_lat_lon(ensdiff, ensmean['lat'], ensmean['lon'], '(a) GEO8.5$_{2075-2095}$ - Base$_{2010-2030}$', outdir+varcode+'_clim_feedback-control_'+season+'.png', 3.6, 0.4, 3.6, 0.4, '$^{\circ}$C') #******************************************************************************************************** # 3) Signal-to-noise ratio SNR = abs(ensdiff)/ensstd_control plot_functions.plot_ToE(SNR, ensmean['lat'], ensmean['lon'], '(a) End-of-century\nSNR', outdir+'SNR.png', 0.2, 2.2, 0.2, '') #********************************************************************************************************
def clim_lat_hgt(run, season, varcode): members = [] # Control Climatology if run == 'control': print("Calculating climatology for control") for i in range(1, 21): ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/p.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0zm." + varcode + ".201001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2010, tim2=2030, varcode=varcode, zm=True) clim = vartimeobj.clim_mean(season) members.append(clim) # RCP8.5 if run == 'rcp85': print("Calculating trend for RCP8.5") for i in [1, 2, 3]: ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/p.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0zm." + varcode + ".201001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2075, tim2=2095, varcode=varcode, zm=True) clim = vartimeobj.clim_mean(season) members.append(clim) # Feedback elif run == 'feedback': print("Calculating trend for Feedback") for i in range(1, 21): ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/p.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + ".cam.h0zm." + varcode + ".202001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2075, tim2=2095, varcode=varcode, zm=True) clim = vartimeobj.clim_mean(season) members.append(clim) # GEOHEAT_S elif run == 'geoheats': print("Calculating trend for GEOHEAT_S") for i in range(1, 5): yrvals = [] for yr in range(2011, 2031): ncpath = glob.glob( "/Volumes/CESM-GLENS/SUE/" + str(i).zfill(3) + "/b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + "/Combined/" + varcode + ".b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + ".zm.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=yr, tim2=yr + 1, varcode=varcode, zm=True) clim = vartimeobj.clim_mean(season) yrvals.append(clim) yrvals_mean, yrvals_std = ensemble_functions.stats(yrvals) members.append(yrvals_mean) return members
def clim_lat_lon(run, season, varcode): members = [] # Control climatology if run == 'control': print("Calculating climatology for Control") for i in range(1, 21): if varcode == 'precip': ncpath1 = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0.PRECC.201001-*.nc")[0] ncpath2 = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0.PRECL.201001-*.nc")[0] vartimeobj = vartimeproc.PrecipTimeProc(ncpath1, ncpath2, tim1=2010, tim2=2030, ppt1='PRECC', ppt2='PRECL') else: ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0." + varcode + ".201001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2010, tim2=2030, varcode=varcode) clim = vartimeobj.clim_mean(season) members.append(clim) # RCP8.5 if run == 'rcp85': print("Calculating climatology for RCP8.5") for i in [1, 2, 3]: # Precip if varcode == 'precip': ncpath1 = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0.PRECC.201001-*.nc")[0] ncpath2 = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0.PRECL.201001-*.nc")[0] vartimeobj = vartimeproc.PrecipTimeProc(ncpath1, ncpath2, tim1=2075, tim2=2095, ppt1='PRECC', ppt2='PRECL') # All other variables else: ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0." + varcode + ".201001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2075, tim2=2095, varcode=varcode) clim = vartimeobj.clim_mean(season) members.append(clim) # Feedback elif run == 'feedback': print("Calculating climatology for Feedback") for i in range(1, 21): # Precip if varcode == 'precip': ncpath1 = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + ".cam.h0.PRECC.202001-*.nc")[0] ncpath2 = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + ".cam.h0.PRECL.202001-*.nc")[0] vartimeobj = vartimeproc.PrecipTimeProc(ncpath1, ncpath2, tim1=2075, tim2=2095, ppt1='PRECC', ppt2='PRECL') # All other variables else: ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.feedback.0" + str(i).zfill(2) + ".cam.h0." + varcode + ".202001-*.nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=2075, tim2=2095, varcode=varcode) clim = vartimeobj.clim_mean(season) members.append(clim) # GEOHEAT_S elif run == 'geoheats': print("Calculating climatology for GEOHEAT_S") for i in range(1, 5): yrvals = [] for yr in range(2011, 2031): # Precip if varcode == 'precip': ncpath1 = glob.glob( "/Volumes/CESM-GLENS/SUE/" + str(i).zfill(3) + "/b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + "/Combined/PRECC.b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + ".nc")[0] ncpath2 = glob.glob( "/Volumes/CESM-GLENS/SUE/" + str(i).zfill(3) + "/b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + "/Combined/PRECL.b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + ".nc")[0] vartimeobj = vartimeproc.PrecipTimeProc(ncpath1, ncpath2, tim1=yr, tim2=yr + 1, ppt1='PRECC', ppt2='PRECL') # All other variables else: ncpath = glob.glob( "/Volumes/CESM-GLENS/SUE/" + str(i).zfill(3) + "/b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + "/Combined/" + varcode + ".b.e15.B5505C5WCCML45BGCR.f09_g16.GEOHEATSUE." + str(i).zfill(3) + "_" + str(yr) + ".nc")[0] vartimeobj = vartimeproc.VarTimeProc(ncpath, tim1=yr, tim2=yr + 1, varcode=varcode) clim = vartimeobj.clim_mean(season) yrvals.append(clim) yrvals_mean, yrvals_std = ensemble_functions.stats(yrvals) members.append(yrvals_mean) # Convert to hPa for PSL if varcode == 'PSL': members = [x * 0.01 for x in members] return members
# control print("Calculating climatology for CONTROL") members_control = [] for i in range(1,21): print(i) ncpath = glob.glob("/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0"+str(i).zfill(2)+"/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0"+str(i).zfill(2)+".cam.h0."+var+".201001-*.nc")[0] Ts_inst = surface_temp.Ts(ncpath, tim1=2010, tim2=2030, var=var) clim_lon_lat = Ts_inst.climatology_lon_lat(season) * pressure_conversion members_control.append(clim_lon_lat) print("...done") ncontrol = len(members_control) ensmean_control, ensstd_control = ensemble_functions.stats(members_control) #******************************************************************************************************** ''' # RCP8.5 # only 3 members here! print("Calculating climatology for RCP8.5") members_rcp85 = [] for i in [1,2,3,21]: ncpath = glob.glob("/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0"+str(i).zfill(2)+"/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0"+str(i).zfill(2)+".cam.h0."+var+".201001-*.nc")[0] Ts_inst = surface_temp.Ts(ncpath, time0=2010, tim1=2075, tim2=2095) clim_lon_lat = Ts_inst.climatology_lon_lat(season) members_rcp85.append(clim_lon_lat)
shading = {'U': {'rcp85': (5, 0.5), 'feedback': (5, 0.5)}} cbar = {'U': {'rcp85': (5, 1), 'feedback': (5, 1)}} contours = {'U': {'rcp85': (60, 10), 'feedback': (60, 10)}} cdp = {'U': {'rcp85': 0, 'feedback': 0}} clabel = {'U': 'Zonal mean zonal wind (ms$^{-1}$ per 30 yrs)'} #******************************************************************************************************** # Control climatology members_control = clim_defs.clim_lat_hgt('control', season, varcode) nmembers_control = len(members_control) ensmean_control, ensstd_control = ensemble_functions.stats(members_control) # Perturbation climatology members = trend_defs.trend_lat_hgt(run, season, varcode) nmembers = len(members) ensmean, ensstd = ensemble_functions.stats(members) ttest = ensemble_functions.t_test_onesample(alpha, ensmean, ensstd, nmembers) # Plot ensemble mean plot_functions.plot_single_lat_hgt(ensmean, ensmean_control,\ plotlett[varcode][run][season]+' '+runname[run],\ outdir+varcode+'_trend_'+run+'_'+season+'.png',\ shading[varcode][run][0], shading[varcode][run][1],\ cbar[varcode][run][0], cbar[varcode][run][1],\ contours[varcode][run][0], contours[varcode][run][1],\ cdp[varcode][run],\
+ str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0." + var2 + ".201001-*.nc")[0] Ts_inst = surface_temp.ppt(ncpath1, ncpath2, tim1=2020, tim2=2095, ppt1='PRECC', ppt2='PRECL') trend_lon_lat = Ts_inst.trend_lon_lat(season) members_rcp85.append(trend_lon_lat) print("...done") nrcp85 = len(members_rcp85) ensmean_rcp85, ensstd_rcp85 = ensemble_functions.stats(members_rcp85) ttest_rcp85 = ensemble_functions.t_test_onesample(alpha, ensmean_rcp85, ensstd_rcp85, nrcp85) plot_functions.plot_single_lat_lon(ensmean_rcp85, ensmean_rcp85['lat'], ensmean_rcp85['lon'], '', outdir + 'ppt_trend_rcp85_' + season + '.png', 0.4, 0.05, 0.4, 0.1, 'Precipitation (mm/day per 30 yrs)', zsig=ttest_rcp85)
#******************************************************************************************************** # control print("Calculating climatology for CONTROL") members_control = [] for i in range(1, 22): ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0." + var + ".201001-*.nc")[0] Ts_inst = surface_temp.Ts(ncpath, time0=2010, tim1=2010, tim2=2030) clim_lon_lat = Ts_inst.climatology_lon_lat(season) members_control.append(clim_lon_lat) ensmean_control, ensstd_control = ensemble_functions.stats(members_control) #******************************************************************************************************** # RCP8.5 # only 3 members here! print("Calculating climatology for RCP8.5") members_rcp85 = [] for i in [1, 2, 3, 21]: ncpath = glob.glob( "/Volumes/CESM-GLENS/GLENS/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + "/atm/proc/tseries/month_1/Combined/b.e15.B5505C5WCCML45BGCR.f09_g16.control.0" + str(i).zfill(2) + ".cam.h0." + var + ".201001-*.nc")[0] Ts_inst = surface_temp.Ts(ncpath, time0=2010, tim1=2075, tim2=2095) clim_lon_lat = Ts_inst.climatology_lon_lat(season)
'precip' :{'rcp85':(0.4,0.1), 'feedback':(1,0.4), 'geoheats':(0.4,0.1)},\ 'PSL' :{'rcp85':(1.6,0.4), 'feedback':(1.6,0.4), 'geoheats':(1.6,0.4)}} colorscale= {'TREFHT' :'BlueRed',\ 'precip' :'BrownGreen',\ 'PSL' :'BlueRed'} clabel = {'TREFHT' :'$^{\circ}$C per 30 yrs',\ 'precip' :'mm/day per 30 yrs',\ 'PSL' :'hPa per 30 yrs'} #******************************************************************************************************** # Base climatology members_base = clim_defs.clim_lat_lon('control', season, varcode) nmembers_base = len(members_base) ensmean_base, ensstd_base = ensemble_functions.stats(members_base) # Perturbation climatology members = clim_defs.clim_lat_lon(run, season, varcode) nmembers = len(members) ensmean, ensstd = ensemble_functions.stats(members) # Difference to Base ensdiff = ensmean - ensmean_base ttest = ensemble_functions.t_test_twosample(alpha, ensdiff, ensstd_base, ensstd, nmembers_base, nmembers) # Convert to trend ensdiff = ensdiff / 65. * 30. # Plot ensemble mean