toe2read = ftoe.variables[var + 'ToE2'][:]
        nMembers[i] = toe2read.shape[0]
        print('- Computing ToE of',model['name'], 'with', nMembers[i], 'members')

        nruns1 = nruns + nMembers[i]
        toe_a[nruns:nruns1,:,:] = toe2read[:,1,:,:]
        toe_p[nruns:nruns1,:,:] = toe2read[:,2,:,:]
        toe_i[nruns:nruns1,:,:] = toe2read[:,3,:,:]

        # -- Select domain to average for each model
        domain = ToEdomainhistvshistNat(model['name'], domain_name)[0]
        domain_char = ToEdomainhistvshistNat(model['name'], domain_name)[1]

        # -- Average toe and determine median of the model
        if domain['Atlantic'] != None:
            varToEA[nruns:nruns1] = np.ma.around(averageDom(toe_a[nruns:nruns1,:,:], 3, domain['Atlantic'], lat, density)) + iniyear
            medmodelsToEA[i] = np.ma.around(np.ma.median(varToEA[nruns:nruns1]))
            print('Median ToE Atlantic:', medmodelsToEA[i])
        if domain['Pacific'] != None:
            varToEP[nruns:nruns1] = np.ma.around(averageDom(toe_p[nruns:nruns1,:,:], 3, domain['Pacific'], lat, density)) + iniyear
            medmodelsToEP[i] = np.ma.around(np.ma.median(varToEP[nruns:nruns1]))
            print('Median ToE Pacific:', medmodelsToEP[i])
        if domain['Indian'] != None:
            varToEI[nruns:nruns1] = np.ma.around(averageDom(toe_i[nruns:nruns1,:,:], 3, domain['Indian'], lat, density)) + iniyear
            medmodelsToEI[i] = np.ma.around(np.ma.median(varToEI[nruns:nruns1]))
            print('Median ToE Indian:', medmodelsToEI[i])

        nruns = nruns1


# Method 2
Example #2
0
    toe1_i = np.ma.masked_all(len(domains))
    # -- Initialize ouput variable
    varToE1 = np.ma.masked_all((basinN, len(domains)))
    varToE2 = np.ma.masked_all((basinN, len(domains)))

    # -- Loop over domains
    for j, domain_name in enumerate(domains):
        print('- ' + domain_name)

        # Select domain to average
        domain = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[0]

        # Average signal and noise
        if domain['Atlantic'] != None:
            varsignal_a[:, j] = averageDom(
                varCO2[:, 1, :, :] - meanvarpiC[1, :, :], 3,
                domain['Atlantic'], lat, density)
            if method_noise == 'average_std':
                varnoise_a[j] = averageDom(varstd[1, :, :], 2,
                                           domain['Atlantic'], lat, density)
            else:
                varnoise_a[j] = np.ma.std(averageDom(varpiC[:, 1, :, :], 3,
                                                     domain['Atlantic'], lat,
                                                     density),
                                          axis=0)
        if domain['Pacific'] != None:
            varsignal_p[:, j] = averageDom(
                varCO2[:, 2, :, :] - meanvarpiC[2, :, :], 3, domain['Pacific'],
                lat, density)
            if method_noise == 'average_std':
                varnoise_p[j] = averageDom(varstd[2, :, :], 2,
Example #3
0
            varsignal = np.ma.masked_all((timN,nruns))

            if method_noise == 'average_histNat':
                # Here we read the std of the averaged histNat for all runs, then take the max as our noise
                filenoise = 'cmip5.' + model['name'] + '.noise_domains_hist_histNat.std_of_average.nc'
                fnoise = open_ncfile(indir_noise + filenoise,'r')
                varstd = fnoise.variables[var+'stdhn'][:,ibasin,idomain].squeeze()
                varnoise = np.ma.max(varstd)

            # Select domain to average
            domain = ToEdomainhistvshistNat(model['name'], domain_name)[0]

            if method_noise == 'average_std':
                # Average noise
                if domain[basin_name] != None:
                    varnoise = averageDom(varstd, 2, domain[basin_name], lat, density)

            # Average noise over projection period if we want to use PiControl
            if use_piC == True:
                if method_noise == 'average_std':
                    varnoise2 = averageDom(stdvarpiC, 2, domain[basin_name], lat, density)
                else:
                    varnoise2 = np.ma.std(averageDom(varpiC, 3, domain[basin_name], lat, density), axis=0)

            # Loop over number of runs
            for k in range(nruns):
                # Read file
                fhrcp = open_ncfile(listruns[k],'r')
                # Read var hist + rcp85
                varh = fhrcp.variables[var][tstart:tend,ibasin,:,:].squeeze()
                varrcp = fhrcp.variables[var][tend:tend+95,ibasin,:,:].squeeze()
            # Loop over number of histNat runs
            for khn in range(nruns_hn):
                print('      . histNat run number', khn)

                # Read file
                fhn = open_ncfile(listruns_hn[khn], 'r')
                # Read var histNat
                varhn = fhn.variables[var][tstart:tend, :, :, :]
                # Compute std of histNat
                varstdhn = np.ma.std(varhn, axis=0)
                # Average std
                if domain['Atlantic'] != None:
                    if method_noise == 'average_std':
                        varnoise_hna[khn,
                                     j] = averageDom(varstdhn[1, :, :], 2,
                                                     domain['Atlantic'], lat,
                                                     density)
                    else:
                        varnoise_hna[khn, j] = np.ma.std(averageDom(
                            varhn[:, 1, :, :], 3, domain['Atlantic'], lat,
                            density),
                                                         axis=0)
                if domain['Pacific'] != None:
                    if method_noise == 'average_std':
                        varnoise_hnp[khn,
                                     j] = averageDom(varstdhn[2, :, :], 2,
                                                     domain['Pacific'], lat,
                                                     density)
                    else:
                        varnoise_hnp[khn, j] = np.ma.std(averageDom(
                            varhn[:, 2, :, :], 3, domain['Pacific'], lat,
    toe_a = np.ma.masked_all(len(domains))
    toe_p = np.ma.masked_all(len(domains))
    toe_i = np.ma.masked_all(len(domains))
    # -- Initialize ouput variable
    varToE = np.ma.masked_all((basinN, len(domains)))

    # -- Loop over domains
    for j, domain_name in enumerate(domains):
        print('- ' + domain_name)

        # Select domain to average
        domain = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[0]

        # Average signal and noise
        if domain['Atlantic'] != None:
            varsignal_a[:,j] = averageDom(varCO2[:,1,:,:]-varpiC[:,1,:,:], 3, domain['Atlantic'], lat, density)
            if method_noise == 'average_std':
                varnoise_a[j] = averageDom(varstd[1,:,:], 2, domain['Atlantic'], lat, density)
            else:
                varnoise_a[j] = np.ma.std(averageDom(varpiC[:,1,:,:], 3, domain['Atlantic'], lat, density), axis=0)
        if domain['Pacific'] != None:
            varsignal_p[:,j] = averageDom(varCO2[:,2,:,:]-varpiC[:,2,:,:], 3, domain['Pacific'], lat, density)
            if method_noise == 'average_std':
                varnoise_p[j] = averageDom(varstd[2,:,:], 2, domain['Pacific'], lat, density)
            else:
                varnoise_p[j] = np.ma.std(averageDom(varpiC[:,2,:,:], 3, domain['Pacific'], lat, density), axis=0)
        if domain['Indian'] != None:
            varsignal_i[:,j] = averageDom(varCO2[:,3,:,:]-varpiC[:,3,:,:], 3, domain['Indian'], lat, density)
            if method_noise == 'average_std':
                varnoise_i[j] = averageDom(varstd[3,:,:], 2, domain['Indian'], lat, density)
            else:
        toei_a = np.reshape(findToE(varCO2_a-varpiC_a, varams, multStd),(levN,latN))
        toei_p = np.reshape(findToE(varCO2_p-varpiC_p, varpms, multStd),(levN,latN))
        toei_i = np.reshape(findToE(varCO2_i-varpiC_i, varims, multStd),(levN,latN))

        # -- Save
        toe_a[i,:,:] = toei_a
        toe_p[i,:,:] = toei_p
        toe_i[i,:,:] = toei_i

        # -- Select domain to average for each model
        domain = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[0]
        domain_char = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[1]

        # -- Average toe
        if domain['Atlantic'] != None:
            varToEA[i] = np.ma.around(averageDom(toe_a[i,:,:], 2, domain['Atlantic'], lat, density))
            print('ToE Atlantic:',varToEA[i])
        if domain['Pacific'] != None:
            varToEP[i] = np.ma.around(averageDom(toe_p[i,:,:], 2, domain['Pacific'], lat, density))
            print('ToE Pacific:',varToEP[i])
        if domain['Indian'] != None:
            varToEI[i] = np.ma.around(averageDom(toe_i[i,:,:], 2, domain['Indian'], lat, density))
            print('ToE Indian:',varToEI[i])


if method == 'average_signal':
    
    for i, model in enumerate(models):

        print('- Reading', model['name'])
Example #7
0
                    varnoise_i = varstd[3,:]

            # Loop over 5 domains
            for j, domain_name in enumerate(domains):
                print('- ', j, domains[j])

                # Select domain to average
                domain = ToEdomainrcp85vshistNat(model['name'], domain_name)[0]
                domain_char = ToEdomainrcp85vshistNat(model['name'], domain_name)[1]


                if use_piC == False :
                    if method_noise == 'average_std':
                        # Average noise when using histNat
                        if domain['Atlantic'] != None:
                            varnoise_a[j] = averageDom(varstd_a, 2, domain['Atlantic'], lat, density)
                        if domain['Pacific'] != None:
                            varnoise_p[j] = averageDom(varstd_p, 2, domain['Pacific'], lat, density)
                        if domain['Indian'] != None:
                            varnoise_i[j] = averageDom(varstd_i, 2, domain['Indian'], lat, density)
                else :
                # Average noise when using PiControl
                    if domain['Atlantic'] != None:
                        if method_noise == 'average_std':
                            varnoise_a[j] = averageDom(stdvarpiC_a, 2, domain['Atlantic'], lat, density)
#                         else :
#                             varnoise_a[j] = np.ma.std(averageDom(varpiC_a, 3, domain['Atlantic'], lat, density), axis=0)
                    if domain['Pacific'] != None:
                        if method_noise == 'average_std':
                            varnoise_p[j] = averageDom(stdvarpiC_p, 2, domain['Pacific'], lat, density)
#                         else:
Example #8
0
                varnoise_i = np.ma.max(varstd[:, 3, :], axis=0)

            # Loop over 5 domains
            for j, domain_name in enumerate(domains):
                print('- ', j, domains[j])

                # Select domain to average
                domain = ToEdomainhistvshistNat(model['name'], domain_name)[0]
                domain_char = ToEdomainhistvshistNat(model['name'],
                                                     domain_name)[1]

                if method_noise == 'average_std':
                    # Average noise
                    if domain['Atlantic'] != None:
                        varnoise_a[j] = averageDom(varstd_a, 2,
                                                   domain['Atlantic'], lat,
                                                   density)
                    if domain['Pacific'] != None:
                        varnoise_p[j] = averageDom(varstd_p, 2,
                                                   domain['Pacific'], lat,
                                                   density)
                    if domain['Indian'] != None:
                        varnoise_i[j] = averageDom(varstd_i, 2,
                                                   domain['Indian'], lat,
                                                   density)

                # Average noise over projection period if we want to use PiControl
                if use_piC == True:
                    if domain['Atlantic'] != None:
                        if method_noise == 'average_std':
                            varnoise2_a[j] = averageDom(
Example #9
0
# Read main variables
lat = fCO2mme.variables['latitude'][:]
time = fCO2mme.variables['time'][:]
varname = defVarmme('salinity'); v = 'S'
density = fCO2mme.variables['lev'][:]
var = varname['var_zonal_w/bowl']

models = defModelsCO2piC()
var_change = np.ma.masked_all((len(models)+1, len(time)))

domain_name = 'Southern ST'
box = [-38,-18,25,26.4]
varCO2mme = fCO2mme.variables[var][:,2,:,:].squeeze()
varpiCmme = fpiCmme.variables[var][-20:,2,:,:].squeeze()
varpiCmme = np.ma.average(varpiCmme, axis=0)
var_change[-1,:] = averageDom(varCO2mme, 3, box, lat, density) - averageDom(varpiCmme, 2, box, lat, density)


# ----- Individual runs -----
indir = '/data/ericglod/Density_binning/Prod_density_april15/'


for imodel in range(len(models)) :
    model = models[imodel]
    file_CO2 = 'mme_1pctCO2/cmip5.' + model['name'] + '.1pctCO2.ensm.an.ocn.Omon.density.ver-' + model['file_end_CO2'] + '_zon2D.nc'
    file_piC = 'mme_piControl/cmip5.' + model['name'] + '.piControl.ensm.an.ocn.Omon.density.ver-' + model['file_end_piC'] + '_zon2D.nc'
    fCO2 = open_ncfile(indir + file_CO2, 'r')
    fpiC = open_ncfile(indir + file_piC, 'r')

    # ----- Variables -----
    domain = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[0]
        toei_i = np.reshape(findToE(varCO2_i - varpiC_i, varims, multStd),
                            (levN, latN))

        # -- Save
        toe_a[i, :, :] = toei_a
        toe_p[i, :, :] = toei_p
        toe_i[i, :, :] = toei_i

        # -- Select domain to average for each model
        domain = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[0]
        domain_char = ToEdomain1pctCO2vsPiC(model['name'], domain_name)[1]

        # -- Average toe
        if domain['Atlantic'] != None:
            varToEA[i] = np.ma.around(
                averageDom(toe_a[i, :, :], 2, domain['Atlantic'], lat,
                           density))
            print('ToE Atlantic:', varToEA[i])
        if domain['Pacific'] != None:
            varToEP[i] = np.ma.around(
                averageDom(toe_p[i, :, :], 2, domain['Pacific'], lat, density))
            print('ToE Pacific:', varToEP[i])
        if domain['Indian'] != None:
            varToEI[i] = np.ma.around(
                averageDom(toe_i[i, :, :], 2, domain['Indian'], lat, density))
            print('ToE Indian:', varToEI[i])

if method == 'average_signal':

    for i, model in enumerate(models):

        print('- Reading', model['name'])
                varnoise_a = np.ma.max(varstd[:,1,:], axis=0)
                varnoise_p = np.ma.max(varstd[:,2,:], axis=0)
                varnoise_i = np.ma.max(varstd[:,3,:], axis=0)

            # Loop over 5 domains
            for j, domain_name in enumerate(domains):
                print('- ', j, domains[j])

                # Select domain to average
                domain = ToEdomainhistvshistNat(model['name'], domain_name)[0]
                domain_char = ToEdomainhistvshistNat(model['name'], domain_name)[1]

                if method_noise == 'average_std':
                    # Average noise
                    if domain['Atlantic'] != None:
                        varnoise_a[j] = averageDom(varstd_a, 2, domain['Atlantic'], lat, density)
                    if domain['Pacific'] != None:
                        varnoise_p[j] = averageDom(varstd_p, 2, domain['Pacific'], lat, density)
                    if domain['Indian'] != None:
                        varnoise_i[j] = averageDom(varstd_i, 2, domain['Indian'], lat, density)

                # Average noise over projection period if we want to use PiControl
                if use_piC == True:
                    if domain['Atlantic'] != None:
                        if method_noise == 'average_std':
                            varnoise2_a[j] = averageDom(stdvarpiC_a, 2, domain['Atlantic'], lat, density)
                        else:
                            varnoise2_a[j] = np.ma.std(averageDom(varpiC_a, 3, domain['Atlantic'], lat, density), axis=0)
                    if domain['Pacific'] != None:
                        if method_noise == 'average_std':
                            varnoise2_p[j] = averageDom(stdvarpiC_p, 2, domain['Pacific'], lat, density)
        domain_char = ToEdomainhistvshistNat(model['name'], domain_name)[1]

        # Loop over number of histNat runs
        for khn in range(nruns_hn):
            print('      . histNat run number', khn)

            # Read file
            fhn = open_ncfile(listruns_hn[khn],'r')
            # Read var histNat
            varhn = fhn.variables[var][tstart:tend,:,:,:]
            # Compute std of histNat
            varstdhn = np.ma.std(varhn, axis=0)
            # Average std
            if domain['Atlantic'] != None:
                if method_noise == 'average_std':
                    varnoise_hna[khn,j] = averageDom(varstdhn[1,:,:], 2, domain['Atlantic'], lat, density)
                else:
                    varnoise_hna[khn,j] = np.ma.std(averageDom(varhn[:,1,:,:], 3, domain['Atlantic'], lat, density), axis=0)
            if domain['Pacific'] != None:
                if method_noise == 'average_std':
                    varnoise_hnp[khn,j] = averageDom(varstdhn[2,:,:], 2, domain['Pacific'], lat, density)
                else:
                    varnoise_hnp[khn,j] = np.ma.std(averageDom(varhn[:,2,:,:], 3, domain['Pacific'], lat, density), axis=0)
            if domain['Indian'] != None:
                if method_noise == 'average_std':
                    varnoise_hni[khn,j] = averageDom(varstdhn[3,:,:], 2, domain['Indian'], lat, density)
                else:
                    varnoise_hni[khn,j] = np.ma.std(averageDom(varhn[:,3,:,:], 3, domain['Indian'], lat, density), axis=0)

        # Loop over number of hist runs
        for kh in range(nruns_h):
Example #13
0
        varnoise_a = np.ma.max(varstd[:, 1, :], axis=0)
        varnoise_p = np.ma.max(varstd[:, 2, :], axis=0)
        varnoise_i = np.ma.max(varstd[:, 3, :], axis=0)

    # Loop over 5 domains
    for j, domain_name in enumerate(domains):
        print('- ', j, domains[j])

        # Select domain to average
        domain = ToEdomainhistvshistNat(model['name'], domain_name)[0]
        domain_char = ToEdomainhistvshistNat(model['name'], domain_name)[1]

        if method_noise == 'average_std':
            # Average noise
            if domain['Atlantic'] != None:
                varnoise_a[j] = averageDom(varstd_a, 2, domain['Atlantic'],
                                           lat, density)
            if domain['Pacific'] != None:
                varnoise_p[j] = averageDom(varstd_p, 2, domain['Pacific'], lat,
                                           density)
            if domain['Indian'] != None:
                varnoise_i[j] = averageDom(varstd_i, 2, domain['Indian'], lat,
                                           density)

        # Loop over number of runs
        for k in range(nruns):
            run_number = os.path.basename(listruns[k]).split('.')[3]
            run_names[k] = run_number
            print('    . run number', k, run_number)

            # Read file
            fh = open_ncfile(listruns[k], 'r')
Example #14
0
# Read variables
lat = fh.variables['latitude'][:]
density = fh.variables['lev'][:]
time = fh.variables['time'][:]

varh = fh.variables[var][:]
varhn = fhn.variables[var][:]

# Take difference hist - histNat
var_diff = varh - varhn
# Compute std of histNat
varstd = np.ma.std(varhn, axis=0)

# Average in domains
if SouthST['Atlantic'] != None:
    varSouthST = averageDom(var_diff[:, 1, :, :], 3, SouthST['Atlantic'], lat,
                            density)
    noiseSouthST = averageDom(2 * varstd[1, :, :], 2, SouthST['Atlantic'], lat,
                              density)
if SO['Atlantic'] != None:
    varSO = averageDom(var_diff[:, 1, :, :], 3, SO['Atlantic'], lat, density)
    noiseSO = averageDom(2 * varstd[1, :, :], 2, SO['Atlantic'], lat, density)
if NA['Atlantic'] != None:
    varNA = averageDom(var_diff[:, 1, :, :], 3, NA['Atlantic'], lat, density)
    noiseNA = averageDom(2 * varstd[1, :, :], 2, NA['Atlantic'], lat, density)

# ----- Plot ------

fig, ax = plt.subplots(figsize=(10, 5))

ax.set_xlim([tmin + iniyear, tmax + iniyear])
# North Atlantic
Example #15
0
        print('- Computing ToE of', model['name'], 'with', nMembers[i],
              'members')

        nruns1 = nruns + nMembers[i]
        toe_a[nruns:nruns1, :, :] = toe2read[:, 1, :, :]
        toe_p[nruns:nruns1, :, :] = toe2read[:, 2, :, :]
        toe_i[nruns:nruns1, :, :] = toe2read[:, 3, :, :]

        # -- Select domain to average for each model
        domain = ToEdomainhistvshistNat(model['name'], domain_name)[0]
        domain_char = ToEdomainhistvshistNat(model['name'], domain_name)[1]

        # -- Average toe and determine median of the model
        if domain['Atlantic'] != None:
            varToEA[nruns:nruns1] = np.ma.around(
                averageDom(toe_a[nruns:nruns1, :, :], 3, domain['Atlantic'],
                           lat, density)) + iniyear
            medmodelsToEA[i] = np.ma.around(np.ma.median(
                varToEA[nruns:nruns1]))
            print('Median ToE Atlantic:', medmodelsToEA[i])
        if domain['Pacific'] != None:
            varToEP[nruns:nruns1] = np.ma.around(
                averageDom(toe_p[nruns:nruns1, :, :], 3, domain['Pacific'],
                           lat, density)) + iniyear
            medmodelsToEP[i] = np.ma.around(np.ma.median(
                varToEP[nruns:nruns1]))
            print('Median ToE Pacific:', medmodelsToEP[i])
        if domain['Indian'] != None:
            varToEI[nruns:nruns1] = np.ma.around(
                averageDom(toe_i[nruns:nruns1, :, :], 3, domain['Indian'], lat,
                           density)) + iniyear
            medmodelsToEI[i] = np.ma.around(np.ma.median(
Example #16
0
lat = fh.variables['latitude'][:]
density = fh.variables['lev'][:]
time = fh.variables['time'][:]

varh = fh.variables[var][:]
varhn = fhn.variables[var][:]

# Take difference hist - histNat
var_diff = varh - varhn
# Compute std of histNat
varstd = np.ma.std(varhn, axis=0)


# Average in domains
if SouthST['Atlantic'] != None :
    varSouthST = averageDom(var_diff[:,1,:,:], 3, SouthST['Atlantic'], lat, density)
    noiseSouthST = averageDom(2*varstd[1,:,:], 2, SouthST['Atlantic'], lat, density)
if SO['Atlantic'] != None :
    varSO = averageDom(var_diff[:,1,:,:], 3, SO['Atlantic'], lat, density)
    noiseSO = averageDom(2*varstd[1,:,:], 2, SO['Atlantic'], lat, density)
if NA['Atlantic'] != None :
    varNA = averageDom(var_diff[:,1,:,:], 3, NA['Atlantic'], lat, density)
    noiseNA = averageDom(2*varstd[1,:,:], 2, NA['Atlantic'], lat, density)


# ----- Plot ------

fig, ax = plt.subplots(figsize=(10,5))

ax.set_xlim([tmin+iniyear,tmax+iniyear])
# North Atlantic