Exemple #1
0
def avg_parameters_20yr(component, area):
    """
    sum up annually and convert to km^3, average every 20 yrs, then convert to m w.e. and average every 20 yrs again
    """
    component_annual = ((pygemfxns.annual_sum_2darray(component))/1000)*area
    component_annual_regional_1 = np.sum(component_annual[:,1:], axis=0) # in km^3 aka gigatons
    component_avg_gt_20yr = (np.add.reduceat(component_annual_regional_1, np.arange(0, len(component_annual_regional_1), 20)))/20
    component_annual_regional_2 = ((component_annual_regional_1)/(np.sum(area[:,1:], axis=0)))*1000 # km^3 (gigatons) --> m w.e.
    component_avg_mwea_20yr = (np.add.reduceat(component_annual_regional_2, np.arange(0, len(component_annual_regional_2), 20)))/20
    
    return component_avg_gt_20yr, component_avg_mwea_20yr
Exemple #2
0
#dens_ice = 917 # in kg/m^3
#mb = ds.loc[:,'mb_mwea']
#area = ds.loc[:,'area']
#mb_uncertainty = ds.loc[:,'mb_mwea_sigma']

# variables for vol over time plot
# variables
time = ds.variables['year'].values[:]
glac_runoff = ds.variables['runoff_glac_monthly'].values[:]
offglac_runoff = ds.variables['offglac_runoff_monthly'].values[:]
total_runoff = glac_runoff + offglac_runoff
total_runoff = total_runoff[:,:,0]
runoff_region = np.sum(total_runoff, axis=0)
runoff_init = np.sum(total_runoff[:,0])
runoff_norm = runoff_region/runoff_init
runoff_region_annual = gcmbiasadj.annual_sum_2darray(total_runoff)
runoff_region_annual = np.sum(runoff_region_annual, axis=0)

# X,Y values
x_values = time  
y_values = runoff_region_annual
#y2_values = ds.loc[...]

# Set up your plot (and/or subplots)
fig, ax = plt.subplots(1, 1, squeeze=False, sharex=False, sharey=False, gridspec_kw = {'wspace':0.4, 'hspace':0.15})
             
# Plot
#  zorder controls the order of the plots (higher zorder plots on top)
#  label used to automatically generate legends (legends can be done manually for more control)
ax[0,0].plot(x_values, y_values, color='k', linewidth=1, zorder=2, label='plot1')
#ax[0,0].scatter(x_values, y_values, color='k', zorder=2, s=2)
Exemple #3
0
                       sharex=False,
                       sharey=False,
                       gridspec_kw={
                           'wspace': 0.4,
                           'hspace': 0.15
                       })
for j in range(len(rcp_list)):
    for i in range(len(sim_list)):
        ds = xr.open_dataset(os.getcwd() + '/../Output/simulations/' +
                             sim_list[i] + '/R1_' + sim_list[i] + '_rcp' +
                             rcp_list[j] + '_c1_ba1_1sets_1980_2100.nc')
        #    time = np.append(arr=time, values=ds.variables['year_plus1'].values[:])
        time = ds.variables['year'].values[:]
        #    vol = np.append(arr=vol, values=ds.variables['volume_glac_annual'].values[:,:,0])
        prec = ds.variables['prec_glac_monthly'].values[:, :, 0]
        prec_annual = pygemfxns.annual_sum_2darray(prec)
        prec_regional = np.sum(prec_annual, axis=0)
        prec_regional_annual = prec_regional / prec_regional[0]
        #    vol_regional = np.append(arr=vol_regional, values=np.sum(vol, axis=0))
        #    ax[0,0].scatter(time, vol_regional, color='k', zorder=2, s=2)
        ax[0, 0].plot(time,
                      prec_regional_annual,
                      linewidth=1,
                      zorder=2,
                      label='')

        ds.close()
#%%
#dens_ice = 917 # in kg/m^3
#mb = ds.loc[:,'mb_mwea']
#area = ds.loc[:,'area']
Exemple #4
0
ax[0,0].plot(y_values, y3_values, color='k', alpha=0.5, linewidth=1, zorder=1)

for i in range(len(sim_list)):   
    ds = pd.read_csv(os.getcwd() + '/../Climate_data/Zemp_etal_DataTables2a-t_results_regions_global/Zemp_etal_results_region_1_ALA.csv'
                     , skiprows=26)
    #time = ds.loc[:,'Year']
    mb = ds.loc[:, ' INT_mwe']
    mb = mb[10:]
    
    ds2 = xr.open_dataset(os.getcwd() + '/../Output/simulations/' + sim_list[i] + '/R1_' + sim_list[i] + '_rcp'
                          + rcp + '_c1_ba1_1sets_1960_2017.nc')
    #time = ds2.variables['year'].values[:]
    area = ds2.variables['area_glac_annual'].values[:,:-1,0]
    
    mb_mod = ds2.variables['massbaltotal_glac_monthly'].values[:,:,0]
    mb_mod_annual = ((pygemfxns.annual_sum_2darray(mb_mod))/1000)*area
    mb_mod_annual_regional = ((np.sum(mb_mod_annual, axis=0))/(np.sum(area, axis=0)))*1000
    
    # plot
    x_values = mb
    y_values = mb_mod_annual_regional[:-1]
    ax[0,0].scatter(x_values, y_values, linewidth=1, zorder=2, label='plot1', s=2)

# figure styling
ax[0,0].set_xlim(-2,2)
ax[0,0].text(0.5, 0.99, 'Comparison to Zemp et al.: RCP ' + RCP, size=10, horizontalalignment='center', verticalalignment='top', transform=ax[0,0].transAxes)
axes[0,0].set_xlabel('Mass balance from Zemp et al. [m w.e. yr^-1]', size=10)
axes[0,0].set_ylabel('Mass balance from PyGEM [m w.e. yr^-1]', size=10)


# save figure
Exemple #5
0
sim_list = ['CSIRO-Mk3-6-0', 'CNRM-CM5', 'GISS-E2-R', 'GFDL-ESM2M', 'CCSM4', 'MPI-ESM-LR', 'NorESM1-M', 'CanESM2', 'GFDL-CM3', 'IPSL-CM5A-LR']
rcp_list = ['26', '45', '85']
RCP_list = ['RCP 2.6', 'RCP 4.5', 'RCP 8.5']
massbal_regional_all = np.zeros((len(sim_list),121), dtype=float)

# set up plot
fig, ax = plt.subplots(1, 3, squeeze=False, sharex=False, sharey=False, gridspec_kw = {'wspace':0.2, 'hspace':0.05})

for j in range(len(rcp_list)):
    for i  in range(len(sim_list)):
    # specific GCM
        ds = xr.open_dataset(os.getcwd() + '/../Output/simulations/' + sim_list[i] + '/R1_' + sim_list[i] + '_rcp' + rcp_list[j] + '_c1_ba1_1sets_1980_2100.nc')
        time = ds.variables['year'].values[:]
        area = ds.variables['area_glac_annual'].values[:,:-1,0]
        massbal = ds.variables['massbaltotal_glac_monthly'].values[:,:,0]
        massbal_annual = ((pygemfxns.annual_sum_2darray(massbal))/1000)*area
        massbal_annual_regional = ((np.sum(massbal_annual, axis=0))/(np.sum(area, axis=0)))*1000
        # If normalizing...
    #    massbal_regional_norm = massbal_annual_regional/massbal_annual_regional[0]
        ax[0,j].plot(time[37:], massbal_annual_regional[37:], linewidth=1, zorder=2, label=sim_list[i])
    # GCM averages background
        massbal_regional_all[i] = massbal_annual_regional
    massbal_regional_average = np.average(massbal_regional_all, axis=0)
    std = np.std(massbal_regional_all, axis=0)
    x_values=time[37:121]
    y_values=massbal_regional_average[37:121]
    error = std[37:121]
    ax[0,j].plot(x_values, y_values, color='k', linewidth=2, zorder=3, label='Average +/- st. dev.')
    ax[0,j].fill_between(x_values, y_values-error, y_values+error, color='k', alpha=0.2, linewidth=0.4)
    ds.close()
    #%%
Exemple #6
0
        str(int(df_old.loc[x, 'glacno'])).zfill(5)
        for x in np.arange(df_old.shape[0])
    ]

    # Find indices to select data from
    df_old_idx = np.where(df_old.rgino_str.isin(
        main_glac_rgi.rgino_str.values))[0]

    runoff_old_monthly = ds_old.runoff_glac_monthly.values[df_old_idx,
                                                           time_old_idx_start:,
                                                           0]
    offglac_runoff_old_monthly = ds_old.offglac_runoff_monthly.values[
        df_old_idx, time_old_idx_start:, 0]
    totalrunoff_old_monthly = (runoff_old_monthly +
                               offglac_runoff_old_monthly) / 10**9
    totalrunoff_old = gcmbiasadj.annual_sum_2darray(totalrunoff_old_monthly)
    totalrunoff_old_trishuli = totalrunoff_old.sum(axis=0)

    runoff_new_monthly = ds_new.runoff_glac_monthly.values[:,
                                                           time_new_idx_start:,
                                                           0]
    offglac_runoff_new_monthly = ds_new.offglac_runoff_monthly.values[:,
                                                                      time_new_idx_start:,
                                                                      0]
    totalrunoff_new_monthly = (runoff_new_monthly +
                               offglac_runoff_new_monthly) / 10**9
    totalrunoff_new = gcmbiasadj.annual_sum_2darray(totalrunoff_new_monthly)
    totalrunoff_new_trishuli = totalrunoff_new.sum(axis=0)

    dif_runoff = totalrunoff_new_trishuli.sum() - totalrunoff_old_trishuli.sum(
    )
Exemple #7
0
    '/../Output/simulations/CanESM2/R1_CanESM2_rcp45_c1_ba1_1sets_1950_2017.nc'
)
#dens_ice = 917 # in kg/m^3
#mb = ds.loc[:,'mb_mwea']
#area = ds.loc[:,'area']
#mb_uncertainty = ds.loc[:,'mb_mwea_sigma']

# variables for vol over time plot
# variables
time = ds.variables['year'].values[:]
temp = ds.variables['temp_glac_monthly'].values[:, :, 0]
prec = ds.variables['prec_glac_monthly'].values[:, :, 0]
#temp_regional = np.mean(temp, axis=0)
temp_regional = gcmbiasadj.annual_avg_2darray(temp)
#prec_regional = np.mean(prec, axis=0)
prec_regional = gcmbiasadj.annual_sum_2darray(prec)
#vol_init = np.sum(vol[:,:,0][:,-1])
#vol_norm = vol_norm/vol_init

# X,Y values
x_values = time
y_values = temp_regional.transpose()
y2_values = prec_regional.transpose()
#y2_values = ds.loc[...]

# Set up your plot (and/or subplots)
fig, ax = plt.subplots(2,
                       1,
                       squeeze=False,
                       sharex=False,
                       sharey=False,
Exemple #8
0
#!/usr/bin/env python3