#%%
# regrid cube
regrid_cube = iris.load_cube(
    '/home/links/rmv203/obs_datasets/Tair_WFDEI_ann.nc')
regrid_cube = time_average(regrid_cube)
regrid_cube.coord('latitude').guess_bounds()
regrid_cube.coord('longitude').guess_bounds()
regrid_modelcube = regrid_cube.copy()

#%%
# Observational datasets

# Observational temperature
obs_temp_file = iris.load_cube(
    '/home/links/rmv203/obs_datasets/Tair_WFDEI_ann.nc')
obs_temp_file = select_time(obs_temp_file, 2001, 2010)
obs_temp_file = time_average(obs_temp_file)
obs_temp = obs_temp_file.data
obs_temp = np.ma.masked_where(obs_temp > 60, obs_temp)
current_temp = obs_temp.copy()

# Observational soil carbon
# ncscd
ncscd_file = Dataset(
    '/home/links/rmv203/obs_datasets/NCSCDV22_soilc_0.5x0.5.nc')
ncscd_data = ncscd_file.variables['soilc'][:]
n_lat_ncscd = ncscd_file.variables['lat'][:]
n_lon_ncscd = ncscd_file.variables['lon'][:]
# hwsd
hwsd_file = Dataset('/home/links/rmv203/obs_datasets/HWSD_soilc_0.5x0.5.nc')
hwsd_data = hwsd_file.variables['soilc'][:]
        for model_i in range(0, n_models):
            model = cmip5_models[model_i]  # seleting the models

            print(min_temperature, rcp, model)

            #%%

            #%%
            # finding spatial profile for future temperature

            # time averaged, area averaged historical/present day temperature
            tas_preindustrial_cube = combine_netCDF_cmip5(
                '/home/rmv203/cmip5_data/tas_Amon_' + model + '_historical*',
                'air_temperature', model)
            tas_preindustrial_cube = open_netCDF(tas_preindustrial_cube)
            tas_preindustrial_cube = select_time(tas_preindustrial_cube, 1995,
                                                 2005)
            tas_preindustrial_cube = time_average(tas_preindustrial_cube)
            tas_preindustrial_cube = area_average(tas_preindustrial_cube,
                                                  region_global)
            tas_preindustrial_data = tas_preindustrial_cube.data

            # cube to find future temperature change
            tas_cube = combine_netCDF_cmip5(
                '/home/rmv203/cmip5_historical_' + rcp + '/tas_Amon_' + model +
                '_*', 'air_temperature', model)
            tas_cube = open_netCDF(tas_cube)
            tas_test_cube = annual_average(tas_cube)
            # defining the time variable for years
            tas_test_years = tas_test_cube.coord('year').points
            tas_test_cube = area_average(tas_test_cube, region_global)
            tas_test_data = tas_test_cube.data
            '/home/rmv203/cmip5_data/rh_Lmon_' + model + '_historical*',
            'heterotrophic_respiration_carbon_flux', model)
        rh_historical_cube = open_netCDF(rh_historical_cube)
        # Soil Carbon (cSoil)
        cSoil_historical_cube = combine_netCDF_cmip5(
            '/home/rmv203/cmip5_data/cSoil_Lmon_' + model + '_historical*',
            'soil_carbon_content', model)
        cSoil_historical_cube = open_netCDF(cSoil_historical_cube)
        # Near Surface Air Temperature (tas)
        tas_historical_cube = combine_netCDF_cmip5(
            '/home/rmv203/cmip5_data/tas_Amon_' + model + '_historical*',
            'air_temperature', model)
        tas_historical_cube = open_netCDF(tas_historical_cube)

        # Select historical time period
        rh_historical_cube = select_time(rh_historical_cube, lower_historical,
                                         upper_historical)
        cSoil_historical_cube = select_time(cSoil_historical_cube,
                                            lower_historical, upper_historical)
        tas_historical_cube = select_time(tas_historical_cube,
                                          lower_historical, upper_historical)
        # Time average
        rh_historical_cube = time_average(rh_historical_cube)
        cSoil_historical_cube = time_average(cSoil_historical_cube)
        tas_historical_cube = time_average(tas_historical_cube)
        # Converting from cubes to numpy_arrays
        rh_historical_data = rh_historical_cube.data
        cSoil_historical_data = cSoil_historical_cube.data
        tas_historical_data = tas_historical_cube.data

        # save to use later
        historical_tas_save_data = tas_historical_data - 273.15
    for model_i in range(0, n_models_cmip5):
        model = cmip5_models[model_i] # seleting the models

        print(rcp, model)
        

        #%% modelled historical

        # Soil Carbon (cSoil)
        cSoil_historical_cube_new = combine_netCDF_cmip5('/home/rmv203/cmip5_data/cSoil_Lmon_'+model+'_historical*', 'soil_carbon_content', model)
        cSoil_historical_cube_new = open_netCDF(cSoil_historical_cube_new)
        # Near Surface Air Temperature (tas)
        tas_historical_cube = combine_netCDF_cmip5('/home/rmv203/cmip5_data/tas_Amon_'+model+'_historical*', 'air_temperature', model)
        tas_historical_cube = open_netCDF(tas_historical_cube)
        # Select historical time period
        cSoil_historical_cube_new = select_time(cSoil_historical_cube_new, lower_historical, upper_historical)
        tas_historical_cube = select_time(tas_historical_cube, lower_historical, upper_historical)
        # Time average
        cSoil_historical_time_av_cube_new = time_average(cSoil_historical_cube_new)
        tas_historical_cube = time_average(tas_historical_cube)
        tas_historical_data = tas_historical_cube.data

        # Converting from cubes to numpy_arrays
        cSoil_historical_time_av_data_new = cSoil_historical_time_av_cube_new.data


        #%%  Modelled Future

        # Soil Carbon (cSoil)
        cSoil_cube = combine_netCDF_cmip5('/home/rmv203/cmip5_data/cSoil_Lmon_'+model+'_'+rcp+'_*', 'soil_carbon_content', model)
        cSoil_cube = open_netCDF(cSoil_cube)
    rh_historical_cube = combine_netCDF_cmip5(
        '/home/rmv203/cmip5_data/rh_Lmon_' + model + '_historical*',
        'heterotrophic_respiration_carbon_flux', model)
    rh_historical_cube = open_netCDF(rh_historical_cube)
    # Soil Carbon (cSoil)
    cSoil_historical_cube = combine_netCDF_cmip5(
        '/home/rmv203/cmip5_data/cSoil_Lmon_' + model + '_historical*',
        'soil_carbon_content', model)
    cSoil_historical_cube = open_netCDF(cSoil_historical_cube)
    # Near Surface Air Temperature (tas)
    tas_historical_cube = combine_netCDF_cmip5(
        '/home/rmv203/cmip5_data/tas_Amon_' + model + '_historical*',
        'air_temperature', model)
    tas_historical_cube = open_netCDF(tas_historical_cube)
    # Select historical time period
    rh_historical_cube = select_time(rh_historical_cube, lower_historical,
                                     upper_historical)
    cSoil_historical_cube = select_time(cSoil_historical_cube,
                                        lower_historical, upper_historical)
    tas_historical_cube = select_time(tas_historical_cube, lower_historical,
                                      upper_historical)
    # Time average
    rh_historical_time_av_cube = time_average(rh_historical_cube)
    cSoil_historical_time_av_cube = time_average(cSoil_historical_cube)
    tas_historical_time_av_cube = time_average(tas_historical_cube)
    # Converting from cubes to numpy_arrays
    rh_historical_time_av_data = rh_historical_time_av_cube.data
    cSoil_historical_time_av_data = cSoil_historical_time_av_cube.data
    tas_historical_time_av_data = tas_historical_time_av_cube.data

    # Calculating Soil Turnover Time
    tau_s_data_historical = cSoil_historical_time_av_data / (
Beispiel #6
0
            '/home/rmv203/cmip5_data/rh_Lmon_' + model + '_historical*',
            'heterotrophic_respiration_carbon_flux', model)
        rh_historical_cube_new = open_netCDF(rh_historical_cube_new)
        # Soil Carbon (cSoil)
        cSoil_historical_cube_new = combine_netCDF_cmip5(
            '/home/rmv203/cmip5_data/cSoil_Lmon_' + model + '_historical*',
            'soil_carbon_content', model)
        cSoil_historical_cube_new = open_netCDF(cSoil_historical_cube_new)
        # Near Surface Air Temperature (tas)
        tas_historical_cube = combine_netCDF_cmip5(
            '/home/rmv203/cmip5_data/tas_Amon_' + model + '_historical*',
            'air_temperature', model)
        tas_historical_cube = open_netCDF(tas_historical_cube)
        # Select historical time period
        rh_historical_cube_new = select_time(rh_historical_cube_new,
                                             lower_historical,
                                             upper_historical)
        cSoil_historical_cube_new = select_time(cSoil_historical_cube_new,
                                                lower_historical,
                                                upper_historical)
        tas_historical_cube = select_time(tas_historical_cube,
                                          lower_historical, upper_historical)
        # Time average
        rh_historical_time_av_cube_new = time_average(rh_historical_cube_new)
        cSoil_historical_time_av_cube_new = time_average(
            cSoil_historical_cube_new)
        tas_historical_cube = time_average(tas_historical_cube)
        tas_historical_data = tas_historical_cube.data

        # Converting from cubes to numpy_arrays
        rh_historical_time_av_data_new = rh_historical_time_av_cube_new.data