I'm getting a consistent error when just trying to run the Initialization example, with the downloaded oetztal shapefiles. Any help is appreciated! My goal is to run this on a few glaciers in the Garibaldi Region of BC, Canada but at the moment I just wanted to get the examples working!
2021-05-19 19:47:51: oggm.workflow: Execute entity task t_star_from_refmb on 1 g laciers
2021-05-19 19:47:51: oggm.core.climate: (RGI60-11.00897) t_star_from_refmb
2021-05-19 19:47:51: oggm.core.climate: FileNotFoundError occurred during task t _star_from_refmb on RGI60-11.00897: [Errno 2] No such file or directory: 'workdi r/per_glacier/RGI60-11/RGI60-11.00/RGI60-11.00897/inversion_flowlines.pkl'
Traceback (most recent call last):
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/pandas/core/indexes/base.py", line 2898, in get_loc
return self._engine.get_loc(casted_key)
File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_ loc
File "pandas/_libs/index.pyx", line 101, in pandas._libs.index.IndexEngine.get _loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1675, in pandas._libs.has htable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1683, in pandas._libs.has htable.PyObjectHashTable.get_item
KeyError: 'tstar'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "init_test.py", line 62, in <module>
preprocessing(gdir)
File "/fs/vnas_Hnrcan/gia_models/mal007/venv/lib/python3.6/site-packages/initi alization/core.py", line 614, in preprocessing
workflow.climate_tasks(gdirs)
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/oggm/utils/_workflow.py", line 547, in _global_task
return task_func(gdirs, **kwargs)
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/oggm/workflow.py", line 578, in climate_tasks
climate.compute_ref_t_stars(gdirs)
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/oggm/utils/_workflow.py", line 547, in _global_task
return task_func(gdirs, **kwargs)
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/oggm/core/climate.py", line 1459, in compute_ref_t_stars
df['tstar'] = df['tstar'].astype(int)
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/pandas/core/frame.py", line 2906, in __getitem__
indexer = self.columns.get_loc(key)
File "/fs/ssm/hpco/exp/oggm/oggm_1.4.0_ubuntu-18.04-amd64-64/lib/python3.6/sit e-packages/pandas/core/indexes/base.py", line 2900, in get_loc
raise KeyError(key) from err
KeyError: 'tstar'
import sys
import os
import salem
from initialization.core import *
from initialization.plots import *
from oggm import cfg, workflow,utils
import warnings
warnings.filterwarnings("ignore")
import matplotlib.pyplot as plt
#matplotlib inline
# settings for plots
mpl.rcParams['axes.linewidth'] = 3
mpl.rcParams['xtick.major.width'] = 3
mpl.rcParams['ytick.major.width'] = 3
mpl.rcParams['font.size'] =15
mpl.rcParams['font.weight'] = 'medium'
mpl.rcParams['axes.labelweight'] = 'medium'
mpl.rcParams['legend.fontsize']= 15
mpl.rcParams['lines.linewidth']=3
mpl.rcParams['figure.figsize'] = 10,10
cfg.initialize()
# path to working and plot directory
WORKING_DIR = 'workdir'
cfg.PATHS['working_dir'] = WORKING_DIR
utils.mkdir(cfg.PATHS['working_dir'], reset=False)
cfg.PATHS['plot_dir'] = os.path.join(cfg.PATHS['working_dir'], 'plots')
utils.mkdir(cfg.PATHS['plot_dir'], reset=False)
# Use multiprocessing?
cfg.PARAMS['use_multiprocessing'] = True
# How many grid points around the glacier?
cfg.PARAMS['border'] = 200
# Set to True for operational runs
cfg.PARAMS['continue_on_error'] = True
# We use intersects
db = utils.get_rgi_intersects_region_file(version='61', region='02')
cfg.set_intersects_db(db)
cfg.PARAMS['run_mb_calibration'] = True
cfg.PARAMS['optimize_inversion_params'] = False
# read shapefile with 66 glaciers in the Oetztal Alps
rgidf = salem.read_shapefile('/fs/vnas_Hnrcan/gia_models/mal007/Outlines/oetztal.shp')
# sort for efficient using
rgidf = rgidf.sort_values('Area', ascending=False)
# select Hintereisferner only
gdir = workflow.init_glacier_regions(rgidf[rgidf.RGIId=='RGI60-11.00897'])[0]
# preprocessing
preprocessing(gdir)
##########################################################################################################
## Synthetic Experiment ##
#########################################################################################################
synthetic_experiments_parallel([gdir], 1917,gdir.rgi_date)
calibration_runs([gdir],1917)
# reads the expermient model
ep = gdir.get_filepath('model_run', filesuffix='_synthetic_experiment')
ex_mod = FileModel(ep)
# read model_flowlines (RGI state)
fls = gdir.read_pickle('model_flowlines')
fls_mod = FluxBasedModel(flowlines=fls)
ex_mod.run_until(gdir.rgi_date)
x = (np.arange(ex_mod.fls[-1].nx) * ex_mod.fls[-1].dx * ex_mod.fls[-1].map_dx)[:120]/1000
# plot the surface elevations of the synthetic experiment and the RGI state
plt.plot(x,ex_mod.fls[-1].surface_h[:120], color='C0', label='synth. experiment')
plt.plot(x,fls_mod.fls[-1].surface_h[:120], color='C1', label='RGI state')
plt.plot(x,ex_mod.fls[-1].bed_h[:120], color='k')
plt.legend()
plt.title(gdir.rgi_id+': Hintereisferner, t='+str(gdir.rgi_date))
plt.xlabel('Distance along the main flowline (km)')
plt.ylabel('Altitude (m)');
print('RGI state: '+ str(fls_mod.length_m/1000)+' km, '+str(round(fls_mod.area_km2,2)) +r' km², '+str(round(fls_mod.volume_km3,2)) +r' km³')
print('synth. exp.: '+ str(ex_mod.length_m/1000)+' km, '+str(round(ex_mod.area_km2,2)) +r' km², ' +str(round(ex_mod.volume_km3,2)) +r' km³')
################################################################################################
# get calibration run output file (OGGM state)
ex = [f for f in os.listdir(gdir.dir) if f.startswith('model_run_calibration_past')][0]
dst = os.path.join(gdir.dir,ex)
cal_mod = FileModel(dst)
cal_mod.run_until(gdir.rgi_date)
# get the optimal mb offset value from file name
optimal_mb_offset = float(dst.split('_')[-1].split('.nc')[0])
print(optimal_mb_offset)
# reads the expermient model
ep = gdir.get_filepath('model_run', filesuffix='_synthetic_experiment')
ex_mod = FileModel(ep)
ex_mod.run_until(gdir.rgi_date)
# read model_flowlines (RGI state)
fls = gdir.read_pickle('model_flowlines')
fls_mod = FluxBasedModel(flowlines=fls)
x = (np.arange(fls_mod.fls[-1].nx) * fls_mod.fls[-1].dx * fls_mod.fls[-1].map_dx)[:120]/1000
plt.plot(x,fls_mod.fls[-1].surface_h[:120], color='C1', label='RGI state')
plt.plot(x,ex_mod.fls[-1].surface_h[:120], color='C0', label='synth. experiment')
plt.plot(x,cal_mod.fls[-1].surface_h[:120], color='C2', label='best calibration run')
plt.plot(x,cal_mod.fls[-1].bed_h[:120], color='k')
plt.legend()
plt.title(gdir.rgi_id+': Hintereisferner, t='+ str(gdir.rgi_date))
plt.xlabel('Distance along the main flowline (km)')
plt.ylabel('Altitude (m)');
print('RGI state: '+ str(fls_mod.length_m/1000)+' km, '+str(round(fls_mod.area_km2,2)) +r' km², '+str(round(fls_mod.volume_km3,2)) +r' km³')
print('calibration run: '+ str(cal_mod.length_m/1000)+' km, '+str(round(cal_mod.area_km2,2)) +r' km², ' +str(round(cal_mod.volume_km3,2)) +r' km³')
print('synth. exp.: '+ str(ex_mod.length_m/1000)+' km, '+str(round(ex_mod.area_km2,2)) +r' km², ' +str(round(ex_mod.volume_km3,2)) +r' km³')