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_defs.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
示例#2
0
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_defs.stats(yrvals)
            members.append(yrvals_mean)

    return members
示例#3
0
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_defs.stats(yrvals)
            members.append(yrvals_mean)

    # Convert to hPa for PSL
    if varcode == 'PSL':
        members = [x * 0.01 for x in members]

    return members
示例#4
0
            'T'       :{'rcp85':(5,1), 'feedback':(5,1)}}

contours  = {'U'       :{'rcp85':(60,10), 'feedback':(60,10)},\
            'T'       :{'rcp85':(300,10), 'feedback':(300,10)}}

cdp       = {'U'       :{'rcp85':0, 'feedback':0},\
            'T'       :{'rcp85':0, 'feedback':0}}

clabel    = {'U'       :'Zonal mean zonal wind (ms$^{-1}$ per 30 yrs)',\
            'T'       :'Temperature ($^{\circ}$C 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_defs.stats(members_control)

# Perturbation climatology
members = trend_defs.trend_lat_hgt(run, season, varcode)
nmembers = len(members)
ensmean, ensstd = ensemble_defs.stats(members)
ttest = ensemble_defs.t_test_onesample(alpha, ensmean, ensstd, nmembers)

areawgt = np.cos(np.deg2rad(ensmean.lat))
#ensmean_weighted = ensmean.weighted(areawgt)
T50trop = (ensmean.sel(lat=slice(-30, 30), level=50) * areawgt.sel(
    lat=slice(-30, 30))).sum() / areawgt.sel(lat=slice(-30, 30)).sum()
T50pole = (ensmean.sel(lat=slice(60, 90), level=50) * areawgt.sel(
    lat=slice(60, 90))).sum() / areawgt.sel(lat=slice(60, 90)).sum()
print(T50trop.values - T50pole.values)
'''
示例#5
0
             '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_defs.stats(members_base)

# Perturbation climatology
members = clim_defs.clim_lat_lon(run, season, varcode)
nmembers = len(members)
ensmean, ensstd = ensemble_defs.stats(members)

# Difference to Base
ensdiff = ensmean - ensmean_base
ttest = ensemble_defs.t_test_twosample(alpha, ensdiff, ensstd_base, ensstd,
                                       nmembers_base, nmembers)

# Convert to trend
ensdiff = ensdiff / 65. * 30.

# Plot ensemble mean
示例#6
0
                       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_defs.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_defs.stats(members)
ensdiff = ensmean - ensmean_control

plot_defs.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_defs.plot_ToE(SNR, ensmean['lat'], ensmean['lon'],
                   '(a) End-of-century\nSNR', outdir + 'SNR.png', 0.2, 2.2,
                   0.2, '')