Working with the RGI files
Contents
Working with the RGI files#
The glacier outlines obtained from the Randolph Glacier Inventory are the reference dataset for global and regional applications in OGGM. The current version is V6, and OGGM ships with a slightly modified version which we called 62
.
Download the glacier outlines#
To download this version, simply do:
# this might take a couple of minutes!
from oggm import utils
utils.get_rgi_dir(version='62') # path to the data after download
'/github/home/OGGM/rgi/RGIV62'
Access a region file#
The RGI is divided in 19 regions (and many more sub-regions, not plotted here):
Source: the RGI consortium
fr = utils.get_rgi_region_file(11, version='62') # Central Europe
The RGI region files are shapefiles, a vector format commonly used in GIS applications. The library of choice to read shapefiles in python is geopandas:
import geopandas as gpd
gdf = gpd.read_file(fr)
The RGI files and their attributes#
The gdf
variable is a GeoDataFrame
, i.e. you can use most of the tools you know from pandas’ DataFrames
:
len(gdf)
3927
gdf.head()
RGIId | GLIMSId | BgnDate | EndDate | CenLon | CenLat | O1Region | O2Region | Area | Zmin | ... | Lmax | Status | Connect | Form | TermType | Surging | Linkages | Name | check_geom | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | RGI60-11.00001 | G013599E47495N | 20030799 | 20030999 | 13.5987 | 47.4949 | 11 | 1 | 0.122 | 2191 | ... | 461 | 0 | 0 | 0 | 0 | 9 | 9 | NaN | NaN | POLYGON ((13.60035 47.49330, 13.59995 47.49332... |
1 | RGI60-11.00002 | G013614E47485N | 20030799 | 20030999 | 13.6135 | 47.4845 | 11 | 1 | 2.292 | 2203 | ... | 1853 | 0 | 0 | 0 | 0 | 9 | 9 | NaN | NaN | POLYGON ((13.60638 47.47578, 13.60599 47.47579... |
2 | RGI60-11.00003 | G013596E47484N | 20030799 | 20030999 | 13.5960 | 47.4835 | 11 | 1 | 0.851 | 2280 | ... | 1140 | 0 | 0 | 0 | 0 | 9 | 9 | NaN | NaN | POLYGON ((13.59765 47.47613, 13.59726 47.47614... |
3 | RGI60-11.00004 | G013583E47481N | 20030799 | 20030999 | 13.5829 | 47.4807 | 11 | 1 | 0.053 | 2319 | ... | 382 | 0 | 0 | 0 | 0 | 9 | 9 | NaN | NaN | POLYGON ((13.58283 47.47969, 13.58243 47.47971... |
4 | RGI60-11.00005 | G013603E47477N | 20030799 | 20030999 | 13.6026 | 47.4774 | 11 | 1 | 0.057 | 2656 | ... | 202 | 0 | 0 | 0 | 0 | 9 | 9 | NaN | NaN | POLYGON ((13.60076 47.47519, 13.60036 47.47521... |
5 rows × 24 columns
gdf[['Area']].plot(kind='hist', bins=100, logy=True);
gdf[['Aspect']].plot(kind='hist', bins=45);
Selecting glaciers per attribute#
You may want to select all glaciers in the subregion 2 (Pyrenees):
gdf_sel = gdf.loc[gdf.O2Region == '2']
'Glacier area in the Pyrenees: {} km2'.format(gdf_sel.Area.sum())
'Glacier area in the Pyrenees: 3.183 km2'
Selecting glaciers in a basin#
Let’s use a file shipped with OGGM for a start:
path = utils.get_demo_file('rofental_hydrosheds.shp')
basin = gpd.read_file(path)
basin.plot();
And select all glaciers within this shape:
import shapely.geometry as shpg
in_bas = [basin.geometry.contains(shpg.Point(x, y))[0] for
(x, y) in zip(gdf.CenLon, gdf.CenLat)]
gdf_sel = gdf.loc[in_bas]
ax = basin.plot();
gdf_sel.plot(ax=ax, edgecolor='k');
Select glaciers by their ID#
Each glacier in the RGI has a unique ID. It is sometimes difficult to find out which one, but some tools can help you out. For example, the GLIMS viewer allows to select glaciers and then see their ID. For example, the Aletsch Glacier in the Swiss Alps:
al = utils.get_rgi_glacier_entities(['RGI60-11.01450'], version='62')
al.plot();
Use the RGI files to start an OGGM run#
RGI files can be given as input to OGGM to make a run:
from oggm import cfg, workflow, tasks
cfg.initialize(logging_level='WARNING')
cfg.PARAMS['continue_on_error'] = True
cfg.PARAMS['use_multiprocessing'] = True
cfg.PARAMS['border'] = 80
cfg.PATHS['working_dir'] = utils.gettempdir(dirname='OGGM-Rofental', reset=True)
gdirs = workflow.init_glacier_directories(gdf_sel, from_prepro_level=4)
2023-03-07 12:47:40: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.
2023-03-07 12:47:40: oggm.cfg: Multiprocessing switched OFF according to the parameter file.
2023-03-07 12:47:40: oggm.cfg: Multiprocessing: using all available processors (N=2)
2023-03-07 12:47:40: oggm.cfg: PARAMS['continue_on_error'] changed from `False` to `True`.
2023-03-07 12:47:40: oggm.cfg: Multiprocessing switched ON after user settings.
2023-03-07 12:47:40: oggm.cfg: PARAMS['border'] changed from `40` to `80`.
2023-03-07 12:47:40: oggm.workflow: init_glacier_directories from prepro level 4 on 54 glaciers.
2023-03-07 12:47:41: oggm.workflow: Execute entity tasks [gdir_from_prepro] on 54 glaciers
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py", line 108, in __call__
res = self._call_internal(func, arg, kwargs)
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py", line 102, in _call_internal
return call_func(gdir, **kwargs)
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py", line 251, in gdir_from_prepro
return oggm.GlacierDirectory(entity, from_tar=from_tar)
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py", line 2529, in __init__
self.name = filter_rgi_name(name)
File "/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_funcs.py", line 734, in filter_rgi_name
if name is None or len(name) == 0:
TypeError: object of type 'float' has no len()
"""
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
Cell In[15], line 8
5 cfg.PARAMS['border'] = 80
6 cfg.PATHS['working_dir'] = utils.gettempdir(dirname='OGGM-Rofental', reset=True)
----> 8 gdirs = workflow.init_glacier_directories(gdf_sel, from_prepro_level=4)
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py:533, in init_glacier_directories(rgidf, reset, force, from_prepro_level, prepro_border, prepro_rgi_version, prepro_base_url, from_tar, delete_tar)
531 if cfg.PARAMS['dl_verify']:
532 utils.get_dl_verify_data('cluster.klima.uni-bremen.de')
--> 533 gdirs = execute_entity_task(gdir_from_prepro, entities,
534 from_prepro_level=from_prepro_level,
535 prepro_border=prepro_border,
536 prepro_rgi_version=prepro_rgi_version,
537 base_url=prepro_base_url)
538 else:
539 # We can set the intersects file automatically here
540 if (cfg.PARAMS['use_intersects'] and
541 len(cfg.PARAMS['intersects_gdf']) == 0 and
542 not from_tar):
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py:185, in execute_entity_task(task, gdirs, **kwargs)
183 if cfg.PARAMS['use_multiprocessing'] and ng > 1:
184 mppool = init_mp_pool(cfg.CONFIG_MODIFIED)
--> 185 out = mppool.map(pc, gdirs, chunksize=1)
186 else:
187 if ng > 3:
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/multiprocessing/pool.py:367, in Pool.map(self, func, iterable, chunksize)
362 def map(self, func, iterable, chunksize=None):
363 '''
364 Apply `func` to each element in `iterable`, collecting the results
365 in a list that is returned.
366 '''
--> 367 return self._map_async(func, iterable, mapstar, chunksize).get()
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/multiprocessing/pool.py:774, in ApplyResult.get(self, timeout)
772 return self._value
773 else:
--> 774 raise self._value
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/multiprocessing/pool.py:125, in worker()
123 job, i, func, args, kwds = task
124 try:
--> 125 result = (True, func(*args, **kwds))
126 except Exception as e:
127 if wrap_exception and func is not _helper_reraises_exception:
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/multiprocessing/pool.py:48, in mapstar()
47 def mapstar(args):
---> 48 return list(map(*args))
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py:108, in __call__()
106 for func in self.call_func:
107 func, kwargs = func
--> 108 res = self._call_internal(func, arg, kwargs)
109 return res
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py:102, in _call_internal()
99 gdir, gdir_kwargs = gdir
100 kwargs.update(gdir_kwargs)
--> 102 return call_func(gdir, **kwargs)
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/workflow.py:251, in gdir_from_prepro()
248 tar_base = utils.get_prepro_gdir(prepro_rgi_version, rid, prepro_border,
249 from_prepro_level, base_url=base_url)
250 from_tar = os.path.join(tar_base.replace('.tar', ''), rid + '.tar.gz')
--> 251 return oggm.GlacierDirectory(entity, from_tar=from_tar)
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py:2529, in __init__()
2525 raise RuntimeError('RGI Version not supported: '
2526 '{}'.format(self.rgi_version))
2528 # remove spurious characters and trailing blanks
-> 2529 self.name = filter_rgi_name(name)
2531 # region
2532 reg_names, subreg_names = parse_rgi_meta(version=self.rgi_version[0])
File /usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_funcs.py:734, in filter_rgi_name()
728 def filter_rgi_name(name):
729 """Remove spurious characters and trailing blanks from RGI glacier name.
730
731 This seems to be unnecessary with RGI V6
732 """
--> 734 if name is None or len(name) == 0:
735 return ''
737 if name[-1] in ['À', 'È', 'è', '\x9c', '3', 'Ð', '°', '¾',
738 '\r', '\x93', '¤', '0', '`', '/', 'C', '@',
739 'Å', '\x06', '\x10', '^', 'å', ';']:
TypeError: object of type 'float' has no len()
workflow.execute_entity_task(tasks.run_random_climate, gdirs, nyears=100,
y0=2009, halfsize=10, output_filesuffix='_2000')
ds2000 = utils.compile_run_output(gdirs, filesuffix='_2000')
ds2000.sum(dim='rgi_id').volume.plot();
This shows the summed up volume evolution of all glaciers of the Rofental basin.
What’s next?#
return to the OGGM documentation
back to the table of contents