#model_name_list.remove('AWI-CM-1-1-MR')

for i, model_name in enumerate(model_name_list):

    try:
        # read in SSTs
        if model_name != 'ERA20C':
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/tos_regridded/'
            full_path = data_path0 + ML.model_institute[
                model_name] + '/' + model_name + '/tos/'
            list_of_files = files_in_directory(
                full_path,
                concat_directory=True,
                include_files_with=ML.ensemble_id[model_name])
            tos_data, lats, lons, levs, times, calendar, t_units = read_in_variable(
                list_of_files[:], 'tos')
        else:
            file_name = [
                '/network/group/aopp/met_data/MET003_ERA20C/data/tos/mon/tos_mon_ERA20C_2.5x2.5_189002-201012.nc'
            ]
            tos_data, lats, lons, levs, times, calendar, t_units = read_in_variable(
                file_name, 'sst')
        SST_am, years_SST = calculate_annual_mean(tos_data,
                                                  times,
                                                  calendar,
                                                  t_units,
                                                  season=season)

        # read in THF
        if model_name != 'ERA20C':
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/piControl/'
                          season)

        # read in variable
        #data_path0 = '/network/group/aopp/predict/AWH007_BEFORT_CMIP6/piControl/'
        #data_path1 = '/piControl/Amon/'+var_name+'/gn/latest'
        data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/piControl/ua/'
        data_path1 = '/' + var_name + '/'
        full_path = data_path0 + model_institute[
            model_name] + '/' + model_name + data_path1
        #list_of_files = files_in_directory(full_path,concat_directory=True,exclude_files_with='AER')
        list_of_files = [
            full_path + var_name + '_Amon_' + model_name + '_piControl_' +
            ensemble_id[model_name] + '_' + season + '.nc'
        ]
        toc1 = time.perf_counter()
        data_am, lats_var, lons_var, levs_var, times_var, calendar_var, t_units_var = read_in_variable(
            list_of_files[:], var_name, chosen_level=chosen_level)
        toc2 = time.perf_counter()
        if decadal_mean == True:
            data_am, years = take_decadal_mean(data_am, times_var,
                                               calendar_var, t_units_var)
        #data_am, years = calculate_annual_mean(var_data,times_var,calendar_var,t_units_var,season=season,decadal_mean=decadal_mean)
        print(toc2 - toc1)
        print(data_am.shape, IOBM.shape)
        climatology_model = np.mean(data_am, axis=0)
        data_am = data_am - np.mean(data_am, axis=0).reshape(
            1, lats_var.shape[0], lons_var.shape[0])  # calculate anomalies
        if var_name == 'psl': data_am = 0.01 * data_am  # convert to hPa
        elif var_name == 'pr': data_am = 86400 * data_am  # convert to mm/day

        # create composite masks
        NINO34_plus = NINO34 > 1
    return NINO34_SST


# read in data
id = 'r102i1p1f1'  #'r101i1p1f1' #'r1i1p2f1' #'r2i1p1f1' #'r1i1p5f1' #'r1i1p3f1' #'r1i1p1f3' #'r1i2p1f1' # 'r1i1p1f2' #'r1i1p1f1' # ensemble member

for i, model_name in enumerate(model_name_list):
    try:
        if model_name is not 'ERA20C':
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/tos_regridded/'
            full_path = data_path0 + model_institute[
                model_name] + '/' + model_name + '/tos/'
            list_of_files = files_in_directory(full_path,
                                               concat_directory=True,
                                               include_files_with=id)
            tos_data, lats, lons, levs, times, calendar, t_units = read_in_variable(
                list_of_files[:], 'tos')
        else:
            list_of_files = [
                '/network/group/aopp/met_data/MET003_ERA20C/data/tos/mon/tos_mon_ERA20C_2.5x2.5_189002-201012.nc'
            ]
            tos_data, lats, lons, levs, times, calendar, t_units = read_in_variable(
                list_of_files[:], 'sst')
        PDO = calculate_PDO(tos_data, lats, lons, times, t_units, calendar)
        IPO = calculate_IPO(tos_data, lats, lons, times, t_units, calendar)
        IOBM = calculate_IOBM(tos_data, lats, lons, times, t_units, calendar)
        IOBM2 = calculate_IOBM2(tos_data, lats, lons, times, t_units, calendar)
        IOD = calculate_IOD(tos_data, lats, lons, times, t_units, calendar)
        NINO34 = calculate_NINO34(tos_data, lats, lons, times, t_units,
                                  calendar)

        # calculate regression onto original time series
Esempio n. 4
0
a = np.arange(0.1, 0.81, 0.1)
clevs = np.append(-a[::-1], a)

for i, model_name in enumerate(model_name_list):

    try:
        # read in SST and THF perform correlation analysis
        if model_name != 'ERA20C':
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/tos_regridded/'
            full_path = data_path0 + ML.model_institute[
                model_name] + '/' + model_name + '/tos/'
            list_of_files = files_in_directory(
                full_path,
                concat_directory=True,
                include_files_with=ML.ensemble_id[model_name])
            tos_data, lats_SST, lons_SST, levs_SST, times_SST, calendar_SST, t_units_SST = read_in_variable(
                list_of_files[:], 'tos')
        else:
            file_name = [
                '/network/group/aopp/met_data/MET003_ERA20C/data/tos/mon/tos_mon_ERA20C_2.5x2.5_189002-201012.nc'
            ]
            tos_data, lats_SST, lons_SST, levs_SST, times, calendar, t_units = read_in_variable(
                file_name, 'sst')
        SST_am, years_SST = calculate_annual_mean(tos_data,
                                                  times_SST,
                                                  calendar_SST,
                                                  t_units_SST,
                                                  season=season)

        # set all unreasonably large values to NaN
        SST_am[np.abs(SST_am) > 1e3] = np.nan
            NINO34, years = prep_SST_index('NINO34',nc_SST,times_SST,calendar_SST,t_units_SST,season)
            IOBM2, years = prep_SST_index('IOBM2',nc_SST,times_SST,calendar_SST,t_units_SST,season)
            if apply_running_mean is not None: 
                NINO34 = running_mean(NINO34,apply_running_mean)
                IOBM2 = running_mean(IOBM2,apply_running_mean)

            # detrend SST
            NINO34 = detrend(NINO34)
            IOBM2 = detrend(IOBM2)

            # read in THF
            if model_name != 'ERA20C':
                data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/piControl/'
                full_path = data_path0 + 'hfls/'+ ML.model_institute[model_name] + '/' + model_name + '/hfls/'
                list_of_files = [full_path+'hfls_Amon_'+model_name+'_piControl_'+ML.ensemble_id[model_name]+'_'+season+'.nc']
                hfls,lats_var,lons_var,levs_var,times_var,calendar_var,t_units_var = read_in_variable(list_of_files[:],'hfls')
                full_path = data_path0 + 'hfss/' + ML.model_institute[model_name] + '/' + model_name + '/hfss/'
                list_of_files = [full_path+'hfss_Amon_'+model_name+'_piControl_'+ML.ensemble_id[model_name]+'_'+season+'.nc']
                hfss,lats_THF,lons_THF,levs_THF,times_THF,calendar_THF,t_units_THF = read_in_variable(list_of_files[:],'hfss')
            THF_am = hfls + hfss 

            # create THF index
            THF_NINO34 = create_THF_index(THF_am,lats_THF,lons_THF,-5,5,190,240)
            THF_IOBM2 = create_THF_index(THF_am,lats_THF,lons_THF,-20,20,40,110)
            if apply_running_mean is not None:
                THF_NINO34 = running_mean(THF_NINO34,apply_running_mean)
                THF_IOBM2 = running_mean(THF_IOBM2,apply_running_mean)

            # read in zonal wind
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/piControl/ua/'
            full_path = data_path0 + ML.model_institute[model_name] + '/' + model_name + '/ua/'
                NINO34 = running_mean(NINO34, apply_running_mean)

            # regress out other index
            IOBM2_no_NINO34 = regress_out_index(IOBM2, NINO34)
            NINO34_no_IOBM2 = regress_out_index(NINO34, IOBM2)

            # read in circulation indices
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/piControl/ua/'
            data_path1 = '/' + var_name + '/'
            full_path = data_path0 + model_institute[
                model_name] + '/' + model_name + data_path1
            list_of_files = [
                full_path + var_name + '_Amon_' + model_name + '_piControl_' +
                ensemble_id[model_name] + '_' + season + '.nc'
            ]
            ua200, lats_var, lons_var, levs_var, times_var, calendar_var, t_units_var = read_in_variable(
                list_of_files[:], var_name, chosen_level=20000)
            ua850, lats_var, lons_var, levs_var, times_var, calendar_var, t_units_var = read_in_variable(
                list_of_files[:], var_name, chosen_level=85000)
            if season == 'DJF':
                ua200 = ua200[::-1][1:][::-1]
                ua850 = ua850[::-1][1:][::-1]
            if apply_running_mean is not None:
                ua200 = running_mean(ua200, apply_running_mean)
                ua850 = running_mean(ua850, apply_running_mean)
                #nHalf = int((apply_running_mean)/2)
                #ua200 = ua200[nHalf:][::-1][nHalf:][::-1]
                #ua850 = ua850[nHalf:][::-1][nHalf:][::-1]

            # calculate regressions
            # also calculate pvalues and show regcoeffs < 0.05
            regress_coeff_IOBM2_ua200 = do_reg(IOBM2, ua200)
        # read in SST file and times
        SST_index_file_name = loading_dir + '/SST_indices_' + model_name + '.nc'
        nc_SST = Dataset(SST_index_file_name, 'r')
        times_SST = nc_SST.variables['times'][:]
        calendar_SST = nc_SST.variables['times'].calendar
        t_units_SST = nc_SST.variables['times'].units

        # read in precipitation, zonal wind, slp
        data_path0 = '/network/group/aopp/predict/AWH007_BEFORT_CMIP6/piControl/'
        # precip
        data_path_pr = '/piControl/Amon/pr/gn/latest'
        full_path_pr = data_path0 + model_institute[
            model_name] + '/' + model_name + data_path_pr
        list_of_files_pr = files_in_directory(full_path_pr,
                                              concat_directory=True)
        pr_data, lats_pr, lons_pr, levs_pr, times_pr, calendar_pr, t_units_pr = read_in_variable(
            list_of_files_pr[:], 'pr')
        # slp
        data_path_psl = '/piControl/Amon/psl/gn/latest'
        full_path_psl = data_path0 + model_institute[
            model_name] + '/' + model_name + data_path_psl
        list_of_files_psl = files_in_directory(full_path_psl,
                                               concat_directory=True)
        psl_data, lats_psl, lons_psl, levs_psl, times_psl, calendar_psl, t_units_psl = read_in_variable(
            list_of_files_psl[:], 'psl')

        # truncate times so that only a common time period is used
        #earliest_common_time = np.min(times_SST)
        #if np.min(times_SST) != np.min(times_psl) & (np.min(times_psl) > np.min(times_SST)): earliest_common_time = np.min(times_psl)
        #latest_common_time = np.max(times_SST)
        #if np.max(times_SST) != np.max(times_psl) & (np.max(times_psl) < np.max(times_SST)): latest_common_time = np.max(times_psl)
        #time_mask_SST = (times_SST>=earliest_common_time)&(times_SST<=latest_common_time)
Esempio n. 8
0
            # regress out other index
            IOBM2_no_NINO34 = regress_out_index(IOBM2, NINO34)
            IOD_no_NINO34 = regress_out_index(IOD, NINO34)
            NINO34_no_IOBM2 = regress_out_index(NINO34, IOBM2)

            # read in circulation indices
            data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/piControl/ua/'
            data_path1 = '/' + var_name + '/'
            full_path = data_path0 + ML.model_institute[
                model_name] + '/' + model_name + data_path1
            list_of_files = [
                full_path + var_name + '_Amon_' + model_name + '_piControl_' +
                ML.ensemble_id[model_name] + '_' + season + '.nc'
            ]
            ua200, lats_ua, lons_ua, levs_ua, times_ua, calendar_ua, t_units_ua = read_in_variable(
                list_of_files[:], var_name, chosen_level=20000)
            U_climatology = np.mean(ua200, axis=0)

            if season == 'DJF':
                ua200 = ua200[::-1][1:][::-1]

            if apply_running_mean is not None:
                ua200 = running_mean(ua200, apply_running_mean)

            # calculate regressions
            regress_coeff_IOBM2_ua200 = do_reg(IOBM2, ua200)
            regress_coeff_IOBM2_no_NINO34_ua200 = do_reg(
                IOBM2_no_NINO34, ua200)
            regress_coeff_IOD_ua200 = do_reg(IOD, ua200)
            regress_coeff_IOD_no_NINO34_ua200 = do_reg(IOD_no_NINO34, ua200)
            regress_coeff_NINO34_ua200 = do_reg(NINO34, ua200)
# running mean
N = 10
halfN = int(N / 2)

for i, model_name in enumerate(model_name_list):

    try:
        data_path0 = '/network/group/aopp/predict/AWH007_BEFORT_CMIP6/piControl/'

        # variable 1
        data_path1 = '/piControl/Amon/' + variable1_name + '/gn/latest'
        full_path = data_path0 + model_institute[
            model_name] + '/' + model_name + data_path1
        list_of_files1 = files_in_directory(full_path, concat_directory=True)
        variable1_data, lats1, lons1, levs1, times1, calendar1, t_units1 = read_in_variable(
            list_of_files1[:], variable1_name, chosen_level=chosen_level1)

        # variable 2
        data_path2 = '/piControl/Amon/' + variable2_name + '/gn/latest'
        full_path = data_path0 + model_institute[
            model_name] + '/' + model_name + data_path2
        list_of_files2 = files_in_directory(full_path, concat_directory=True)
        variable2_data, lats2, lons2, levs2, times2, calendar2, t_units2 = read_in_variable(
            list_of_files2[:], variable2_name, chosen_level=chosen_level2)

        # truncate time series so that only common time periods are included
        if np.min(times1) != np.min(times2):
            if np.min(times1) > np.min(times2):
                earliest_common_time = np.min(times1)
            else:
                earliest_common_time = np.min(times2)
Esempio n. 10
0
    cs = m.add_filled_contours(lons, lats, field1, clevs)
    m.add_contours(lons, lats, field2, clevs2, contour_labels=False)
    make_plots.add_lat_lon(ax)
    m.geography(ax, extent=[10, 220, 0, 70])
    make_plots.plot_box(lon_min=110, lon_max=180, lat_min=20, lat_max=50)
    ax.set_aspect(2)
    return cs


# select season
season = 'JJA'

# Read in HadGEM3 data and calculate annual means
full_path_psl = '/network/group/aopp/predict/AWH007_BEFORT_CMIP6/piControl/MOHC/HadGEM3-GC31-LL/piControl/Amon/psl/gn/latest/'
list_of_files_psl = files_in_directory(full_path_psl, concat_directory=True)
psl_HadGEM, lats_HadGEM, lons_HadGEM, levs_HadGEM, times_HadGEM, calendar_HadGEM, t_units_HadGEM = read_in_variable(
    list_of_files_psl[:], 'psl')
psl_am_HadGEM, years = calculate_annual_mean(psl_HadGEM,
                                             times_HadGEM,
                                             calendar_HadGEM,
                                             t_units_HadGEM,
                                             season=season)
psl_am_HadGEM = 0.01 * psl_am_HadGEM  # convert to hPa

# Read in ERA-Interim and calculate annual means
file_name = '/network/aopp/preds0/pred/data/Obs/Reanalysis/psl/mon/psl_mon_ERAInterim_1x1_197901-201512.nc'
psl_ERAI, lats_ERAI, lons_ERAI, levs_ERAI, times_ERAI, calendar_ERAI, t_units_ERAI = read_in_variable(
    [file_name], 'msl')
psl_am_ERAI, years = calculate_annual_mean(psl_ERAI,
                                           times_ERAI,
                                           calendar_ERAI,
                                           t_units_ERAI,
model_name_list.append('CESM2')

plt.figure(figsize=(30, 35))
gs = gridspec.GridSpec(8, 2)

for i, model_name in enumerate(model_name_list):

    try:
        #data_path0 = '/network/aopp/hera/mad/patterson/iCMIP6/data/piControl/ts/'
        data_path0 = '/network/group/aopp/predict/AWH007_BEFORT_CMIP6/piControl/'  #AWI/AWI-CM-1-1-MR/piControl/Amon/tas/gn/latest
        full_path = data_path0 + ML.model_institute[
            model_name] + '/' + model_name + '/piControl/Amon/tas/gn/latest/'
        list_of_files = files_in_directory(full_path,
                                           concat_directory=True,
                                           exclude_files_with='ImonAnt')
        ts, lats_ts, lons_ts, levs_ts, times_ts, calendar_ts, t_units_ts = read_in_variable(
            list_of_files[:], 'tas')

        ts_am, years = calculate_annual_mean(ts,
                                             times_ts,
                                             calendar_ts,
                                             t_units_ts,
                                             season=season)

        ts_mean = global_mean(ts_am, lats_ts)

        ax = plt.subplot(gs[i])
        plt.title(model_name, fontsize=20)
        plt.plot(ts_mean, color='r')
        plt.xlim(0, 1000)

        if i >= 14: plt.xlabel('Time (years)', fontsize=20)
        # otherwise read in SST and zonal wind files and perform regression, saving these
        except:
            print(
                'Cannot find regression file so reading in files to create one.'
            )
            # read in SST data
            if model_name != 'ERA20C':
                data_path0 = '/network/aopp/hera/mad/patterson/CMIP6/data/tos_regridded/'
                full_path = data_path0 + ML.model_institute[
                    model_name] + '/' + model_name + '/tos/'
                list_of_files = files_in_directory(
                    full_path,
                    concat_directory=True,
                    include_files_with=ML.ensemble_id[model_name])
                tos_data, lats_SST, lons_SST, levs_SST, times_SST, calendar_SST, t_units_SST = read_in_variable(
                    list_of_files[:], 'tos')
            else:
                file_name = [
                    '/network/group/aopp/met_data/MET003_ERA20C/data/tos/mon/tos_mon_ERA20C_2.5x2.5_189002-201012.nc'
                ]
                tos_data, lats_SST, lons_SST, levs_SST, times, calendar, t_units = read_in_variable(
                    file_name, 'sst')
            SST_am, years_SST = calculate_annual_mean(tos_data,
                                                      times_SST,
                                                      calendar_SST,
                                                      t_units_SST,
                                                      season=season)

            # set all unreasonably large values to NaN
            SST_am[np.abs(SST_am) > 1e3] = np.nan