Skip to content

Commit 4d71053

Browse files
committed
committing an old version of PyGEM that was used for all HMA model runs and will constitute the initial release
1 parent fd2e9b7 commit 4d71053

36 files changed

+3125
-20924
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Farinotti_icethickness_process.ipynb

Lines changed: 0 additions & 378 deletions
This file was deleted.

Shean_mb_parallel_breakingdown.ipynb

Lines changed: 0 additions & 1520 deletions
This file was deleted.

analyze_erainterim.py

Lines changed: 0 additions & 931 deletions
This file was deleted.

analyze_massredistribution.py

Lines changed: 0 additions & 1374 deletions
This file was deleted.

analyze_mcmc.py

Lines changed: 214 additions & 195 deletions
Large diffs are not rendered by default.

analyze_simulation.py

Lines changed: 1096 additions & 3469 deletions
Large diffs are not rendered by default.

class_climate.py

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ def importGCMvarnearestneighbor_xarray(self, filename, vn, main_glac_rgi, dates_
235235
glac_variable_series = np.zeros((main_glac_rgi.shape[0],dates_table.shape[0]))
236236
# Determine the correct time indices
237237
if self.timestep == 'monthly':
238-
start_idx = (np.where(pd.Series(data[self.time_vn]).apply(lambda x: x.strftime('%Y-%m')) ==
239-
dates_table['date'].apply(lambda x: x.strftime('%Y-%m'))[0]))[0][0]
240-
end_idx = (np.where(pd.Series(data[self.time_vn]).apply(lambda x: x.strftime('%Y-%m')) ==
241-
dates_table['date']
238+
start_idx = (np.where(pd.Series(data[self.time_vn])
239+
.apply(lambda x: x.strftime('%Y-%m')) == dates_table['date']
240+
.apply(lambda x: x.strftime('%Y-%m'))[0]))[0][0]
241+
end_idx = (np.where(pd.Series(data[self.time_vn])
242+
.apply(lambda x: x.strftime('%Y-%m')) == dates_table['date']
242243
.apply(lambda x: x.strftime('%Y-%m'))[dates_table.shape[0] - 1]))[0][0]
243244
# np.where finds the index position where to values are equal
244245
# pd.Series(data.variables[gcm_time_varname]) creates a pandas series of the time variable associated with
@@ -296,18 +297,15 @@ def importGCMvarnearestneighbor_xarray(self, filename, vn, main_glac_rgi, dates_
296297

297298
# Perform corrections to the data if necessary
298299
# Surface air temperature corrections
299-
if vn in ['tas', 't2m', 'T2']:
300+
if (vn == 'tas') or (vn == 't2m') or (vn == 'T2'):
300301
if 'units' in data[vn].attrs and data[vn].attrs['units'] == 'K':
301302
# Convert from K to deg C
302303
glac_variable_series = glac_variable_series - 273.15
303304
else:
304305
print('Check units of air temperature from GCM is degrees C.')
305-
elif vn in ['t2m_std']:
306-
if 'units' in data[vn].attrs and data[vn].attrs['units'] not in ['C', 'K']:
307-
print('Check units of air temperature standard deviation from GCM is degrees C or K')
308306
# Precipitation corrections
309307
# If the variable is precipitation
310-
elif vn in ['pr', 'tp', 'TOTPRECIP']:
308+
elif (vn == 'pr') or (vn == 'tp') or (vn == 'TOTPRECIP'):
311309
# If the variable has units and those units are meters (ERA Interim)
312310
if 'units' in data[vn].attrs and data[vn].attrs['units'] == 'm':
313311
pass
@@ -333,24 +331,21 @@ def importGCMvarnearestneighbor_xarray(self, filename, vn, main_glac_rgi, dates_
333331

334332
#%% Testing
335333
if __name__ == '__main__':
336-
## gcm = GCM(name='CanESM2', rcp_scenario='rcp85')
334+
# gcm = GCM(name='CanESM2', rcp_scenario='rcp85')
337335
# gcm = GCM(name='ERA5')
338-
## gcm = GCM(name='ERA-Interim')
339-
#
340-
# main_glac_rgi = modelsetup.selectglaciersrgitable(rgi_regionsO1=input.rgi_regionsO1, rgi_regionsO2 = 'all',
341-
# rgi_glac_number=input.rgi_glac_number)
342-
# dates_table = modelsetup.datesmodelrun(startyear=1980, endyear=2017, spinupyears=0,
343-
# option_wateryear=input.gcm_wateryear)
344-
#
345-
# # Air temperature [degC], Precipitation [m], Elevation [masl], Lapse rate [K m-1]
346-
# gcm_temp, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.temp_fn, gcm.temp_vn, main_glac_rgi, dates_table)
347-
# gcm_prec, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.prec_fn, gcm.prec_vn, main_glac_rgi, dates_table)
348-
# gcm_elev = gcm.importGCMfxnearestneighbor_xarray(gcm.elev_fn, gcm.elev_vn, main_glac_rgi)
349-
# if gcm.name == 'ERA-Interim' or gcm.name == 'ERA5':
350-
# gcm_lr, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.lr_fn, gcm.lr_vn, main_glac_rgi, dates_table)
351-
# if gcm.name == 'ERA5':
352-
# gcm_tempstd, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.tempstd_fn, gcm.tempstd_vn, main_glac_rgi,
353-
# dates_table)
336+
gcm = GCM(name='ERA-Interim')
337+
338+
main_glac_rgi = modelsetup.selectglaciersrgitable(rgi_regionsO1=input.rgi_regionsO1, rgi_regionsO2 = 'all',
339+
rgi_glac_number=input.rgi_glac_number)
340+
dates_table = modelsetup.datesmodelrun(startyear=1980, endyear=2017, spinupyears=0,
341+
option_wateryear=input.gcm_wateryear)
342+
343+
# Air temperature [degC], Precipitation [m], Elevation [masl], Lapse rate [K m-1]
344+
gcm_temp, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.temp_fn, gcm.temp_vn, main_glac_rgi, dates_table)
345+
gcm_prec, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.prec_fn, gcm.prec_vn, main_glac_rgi, dates_table)
346+
gcm_elev = gcm.importGCMfxnearestneighbor_xarray(gcm.elev_fn, gcm.elev_vn, main_glac_rgi)
347+
if gcm.name == 'ERA-Interim' or gcm.name == 'ERA5':
348+
gcm_lr, gcm_dates = gcm.importGCMvarnearestneighbor_xarray(gcm.lr_fn, gcm.lr_vn, main_glac_rgi, dates_table)
354349
# else:
355350
# gcm_lr = np.tile(ref_lr_monthly_avg, int(gcm_temp.shape[1]/12))
356351
# # COAWST data has two domains, so need to merge the two domains
@@ -368,18 +363,4 @@ def importGCMvarnearestneighbor_xarray(self, filename, vn, main_glac_rgi, dates_
368363
# ~(input.coawst_d02_lon_min <= glac_lon <= input.coawst_d02_lon_max)):
369364
# gcm_prec[glac,:] = gcm_prec_d01[glac,:]
370365
# gcm_temp[glac,:] = gcm_temp_d01[glac,:]
371-
# gcm_elev[glac] = gcm_elev_d01[glac]
372-
373-
#%%
374-
# # Get range of dates
375-
# rcp_scenario = 'rcp85'
376-
# gcm_names = ['bcc-csm1-1', 'CanESM2', 'CESM1-CAM5', 'CCSM4', 'CNRM-CM5', 'CSIRO-Mk3-6-0', 'FGOALS-g2', 'GFDL-CM3',
377-
# 'GFDL-ESM2G', 'GFDL-ESM2M', 'GISS-E2-R', 'HadGEM2-ES', 'IPSL-CM5A-LR', 'IPSL-CM5A-MR', 'MIROC-ESM',
378-
# 'MIROC-ESM-CHEM', 'MIROC5', 'MPI-ESM-LR', 'MPI-ESM-MR', 'MRI-CGCM3', 'NorESM1-M', 'NorESM1-ME']
379-
# for gcm_name in gcm_names:
380-
# print(gcm_name)
381-
# ds = xr.open_dataset(input.cmip5_fp_var_prefix + rcp_scenario + input.cmip5_fp_var_ending +
382-
# 'tas' + '_mon_' + gcm_name + '_' + rcp_scenario + '_r1i1p1_native.nc')
383-
#
384-
# print(' ', ds.time[0].values,
385-
# '\n ', ds.time[-1].values)
366+
# gcm_elev[glac] = gcm_elev_d01[glac]

0 commit comments

Comments
 (0)