OGGM-Shop and Glacier Directories in OGGM¶
Set-up¶
Input data folders¶
If you are using your own computer: before you start, make sure that you have set-up the input data configuration file at your wish. In the course of this tutorial, we will need to download data needed for each glacier (a couple of mb at max, depending on the chosen glaciers), so make sure you have an internet connection.
cfg.initialize() and cfg.PARAMS¶
An OGGM simulation script will always start with the following commands:
from oggm import cfg, utils
cfg.initialize(logging_level='WARNING')
2021-02-17 22:20:46: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.
2021-02-17 22:20:46: oggm.cfg: Multiprocessing switched OFF according to the parameter file.
2021-02-17 22:20:46: oggm.cfg: Multiprocessing: using all available processors (N=8)
A call to cfg.initialize() will read the default parameter file (or any user-provided file) and make them available to all other OGGM tools via the cfg.PARAMS
dictionary. Here are some examples of these parameters:
cfg.PARAMS['continue_on_error']
False
cfg.PARAMS['border']
40
cfg.PARAMS['has_internet']
True
Workflow¶
import os
from oggm import workflow, tasks
Working directory¶
Each OGGM run needs a single folder where to store the results of the computations for all glaciers. This is called a “working directory” and needs to be specified before each run. Here we create a temporary folder for you:
cfg.PATHS['working_dir'] = utils.gettempdir(dirname='OGGM-Shop', reset=True)
cfg.PATHS['working_dir']
'/tmp/OGGM/OGGM-Shop'
We use a temporary directory for this example, but in practice you will set this working directory yourself (for example: /home/john/OGGM_output
. The size of this directory will depend on how many glaciers you’ll simulate!
This working directory is meant to be persistent, i.e. you can stop your processing workflow after any task, and restart from an existing working directory at a later stage.
Define the glaciers for the run¶
rgi_ids = ['RGI60-01.13696'] # Malaspina glacier (large - hungry in memory)
rgi_ids = ['RGI60-05.00800'] # Glacier in Greenland
You can provide any number of glacier identifiers. You can find other glacier identifiers by exploring the GLIMS viewer.
For an operational run on an RGI region, you might want to download the Randolph Glacier Inventory dataset instead, and start from it. This case is covered in the working with the RGI tutorial and in the “Starting from scratch” section below.
Starting from RGItopo¶
The OGGM workflow is organized as a list of tasks that have to be applied to a list of glaciers. The vast majority of tasks are called entity tasks: they are standalone operations to be realized on one single glacier entity. These tasks are executed sequentially (one after another): they often need input generated by the previous task(s): for example, the glacier mask task needs the glacier topography data.
To handle this situation, OGGM uses a workflow based on data persistence on disk: instead of passing data as python variables from one task to another, each task will read the data from disk and then write the computation results back to the disk, making these new data available for the next task in the queue.
These glacier specific data are located in glacier directories. These directories are initialized with the following command (this can take a little while on the first call, as OGGM needs to download some data):
# The RGI version to use
# V62 is an unofficial modification of V6 with only minor, backwards compatible modifications
prepro_rgi_version = 62
# Size of the map around the glacier.
prepro_border = 10
# Degree of processing level. This is OGGM specific and for the shop 1 is the one you want
from_prepro_level = 1
# URL of the preprocessed Gdirs
base_url = 'https://cluster.klima.uni-bremen.de/data/gdirs/dems_v1/default/'
gdirs = workflow.init_glacier_directories(rgi_ids,
from_prepro_level=from_prepro_level,
prepro_base_url=base_url,
prepro_rgi_version=prepro_rgi_version,
prepro_border=prepro_border)
2021-02-17 22:20:47: oggm.workflow: init_glacier_directories from prepro level 1 on 1 glaciers.
2021-02-17 22:20:47: oggm.workflow: Execute entity task gdir_from_prepro on 1 glaciers
gdirs
is a list of GlacierDirectory objects (one for each glacier). Glacier directories are used by OGGM as “file and attribute manager” for single glaciers.
For example, we now know where to find the glacier mask files for this glacier:
gdir = gdirs[0] # take Unteraar
print('Path to the DEM:', gdir.get_filepath('glacier_mask'))
Path to the DEM: /tmp/OGGM/OGGM-Shop/per_glacier/RGI60-05/RGI60-05.00/RGI60-05.00800/glacier_mask.tif
And we can also access some attributes of this glacier:
gdir
<oggm.GlacierDirectory>
RGI id: RGI60-05.00800
Region: 05: Greenland
Subregion: 05-01: Greenland (periphery)
Glacier type: Glacier
Terminus type: Marine-terminating
Area: 246.825 km2
Lon, Lat: (-52.141, 66.0945)
Grid (nx, ny): (176, 158)
Grid (dx, dy): (200.0, -200.0)
gdir.rgi_date # date at which the outlines are valid
2000
The advantage of this Glacier Directory data model is that it simplifies greatly the data transfer between tasks. The single mandatory argument of all entity tasks will allways be a glacier directory. With the glacier directory, each task will find the input it needs: for example, the glacier outlines are needed for the next plotting function, and are available via the gdir
argument:
from oggm import graphics
graphics.plot_googlemap(gdir, figsize=(8, 7))

For most glaciers in the world there are several digital elevation models (DEM) which cover the respective glacier. In OGGM we have currently implemented many different open access DEMs to choose from. For some, you need to register to get access, see dem_sources.ipynb/register. Some are regional and only available in certain areas (e.g. Greenland or Antarctica) and some cover almost the entire globe. For more information, visit the rgitools documentation about DEMs.
RGItopo data¶
sources = [src for src in os.listdir(gdir.dir) if src in utils.DEM_SOURCES]
print('RGI ID:', gdir.rgi_id)
print('Available DEM sources:', sources)
RGI ID: RGI60-05.00800
Available DEM sources: ['DEM3', 'ASTER', 'GIMP', 'COPDEM', 'ARCTICDEM', 'TANDEM', 'MAPZEN', 'AW3D30']
# We use xarray to store the data
import xarray as xr
import numpy as np
ods = xr.Dataset()
for src in sources:
demfile = os.path.join(gdir.dir, src) + '/dem.tif'
with xr.open_rasterio(demfile) as ds:
data = ds.sel(band=1).load() * 1.
ods[src] = data.where(data > -100, np.NaN)
sy, sx = np.gradient(ods[src], gdir.grid.dx, gdir.grid.dx)
ods[src + '_slope'] = ('y', 'x'), np.arctan(np.sqrt(sy**2 + sx**2))
with xr.open_rasterio(gdir.get_filepath('glacier_mask')) as ds:
ods['mask'] = ds.sel(band=1).load()
# Decide on the number of plots and figure size
ns = len(sources)
n_col = 3
x_size = 12
n_rows = -(-ns // n_col)
y_size = x_size / n_col * n_rows
from mpl_toolkits.axes_grid1 import AxesGrid
import salem
import matplotlib.pyplot as plt
smap = salem.graphics.Map(gdir.grid, countries=False)
smap.set_shapefile(gdir.read_shapefile('outlines'))
smap.set_plot_params(cmap='topo')
smap.set_lonlat_contours(add_tick_labels=False)
smap.set_plot_params(vmin=np.nanquantile([ods[s].min() for s in sources], 0.25),
vmax=np.nanquantile([ods[s].max() for s in sources], 0.75))
fig = plt.figure(figsize=(x_size, y_size))
grid = AxesGrid(fig, 111,
nrows_ncols=(n_rows, n_col),
axes_pad=0.7,
cbar_mode='each',
cbar_location='right',
cbar_pad=0.1
)
for i, s in enumerate(sources):
data = ods[s]
smap.set_data(data)
ax = grid[i]
smap.visualize(ax=ax, addcbar=False, title=s)
if np.isnan(data).all():
grid[i].cax.remove()
continue
cax = grid.cbar_axes[i]
smap.colorbarbase(cax)
# take care of uneven grids
if ax != grid[-1]:
grid[-1].remove()
grid[-1].cax.remove()

Original (raw) topography data¶
See dem_sources.ipynb.
OGGM-Shop: ITS-live¶
This is an example on how to extract velocity fields from the ITS_live Regional Glacier and Ice Sheet Surface Velocities Mosaic (Gardner, A. et al 2019) at 120 m resolution and reproject this data to the OGGM-glacier grid. This only works where ITS-live data is available! (not in the Alps)
# this will download severals large dataset (2*~800MB)
from oggm.shop import its_live, rgitopo
workflow.execute_entity_task(rgitopo.select_dem_from_dir, gdirs, dem_source='COPDEM', keep_dem_folders=True);
workflow.execute_entity_task(tasks.glacier_masks, gdirs);
workflow.execute_entity_task(its_live.velocity_to_gdir, gdirs);
2021-02-17 22:21:04: oggm.workflow: Execute entity task select_dem_from_dir on 1 glaciers
2021-02-17 22:21:04: oggm.workflow: Execute entity task glacier_masks on 1 glaciers
2021-02-17 22:21:05: oggm.workflow: Execute entity task velocity_to_gdir on 1 glaciers
By applying the entity task its_live.velocity_to_gdir() the model downloads and reprojects the ITS_live files to a given glacier map.
The velocity components (vx, vy) are added to the gridded_data
nc file stored on each glacier directory.
According to the ITS_LIVE documentation velocities are given in ground units (i.e. absolute velocities). We then use bilinear interpolation to reproject the velocities to the local glacier map by re-projecting the vector distances.
By specifying add_error=True
, we also reproject and scale the error for each component (evx, evy).
Now we can read in all the gridded data that comes with OGGM, including the ITS_Live velocity components.
with xr.open_dataset(gdir.get_filepath('gridded_data')) as ds:
ds = ds.load()
ds
<xarray.Dataset> Dimensions: (x: 176, y: 158) Coordinates: * x (x) float32 -1.828e+04 -1.808e+04 ... 1.652e+04 1.672e+04 * y (y) float32 7.344e+06 7.344e+06 ... 7.313e+06 7.312e+06 Data variables: topo (y, x) float32 1.56e+03 1.576e+03 1.596e+03 ... 675.4 634.6 topo_smoothed (y, x) float32 1.562e+03 1.576e+03 ... 666.6 640.1 topo_valid_mask (y, x) int8 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 glacier_mask (y, x) int8 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 glacier_ext (y, x) int8 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 obs_icevel_x (y, x) float32 0.1185 0.1567 0.1677 ... 7.448 5.996 4.791 obs_icevel_y (y, x) float32 1.509 0.8505 0.5083 ... 7.928 5.952 3.744 Attributes: author: OGGM author_info: Open Global Glacier Model pyproj_srs: +proj=tmerc +lat_0=0 +lon_0=-52.141 +k=0.9996 +x_0=0 +y_0... max_h_dem: 2159.736 min_h_dem: 0.0 max_h_glacier: 2097.7734 min_h_glacier: 0.0
- x: 176
- y: 158
- x(x)float32-1.828e+04 -1.808e+04 ... 1.672e+04
- units :
- m
- long_name :
- x coordinate of projection
- standard_name :
- projection_x_coordinate
array([-18283.69 , -18083.69 , -17883.69 , -17683.69 , -17483.69 , -17283.69 , -17083.69 , -16883.69 , -16683.69 , -16483.69 , -16283.689 , -16083.689 , -15883.689 , -15683.689 , -15483.689 , -15283.689 , -15083.689 , -14883.689 , -14683.689 , -14483.689 , -14283.689 , -14083.689 , -13883.689 , -13683.689 , -13483.689 , -13283.689 , -13083.689 , -12883.689 , -12683.689 , -12483.689 , -12283.689 , -12083.689 , -11883.689 , -11683.689 , -11483.689 , -11283.689 , -11083.689 , -10883.689 , -10683.689 , -10483.689 , -10283.689 , -10083.689 , -9883.689 , -9683.689 , -9483.689 , -9283.689 , -9083.689 , -8883.689 , -8683.689 , -8483.689 , -8283.689 , -8083.6895 , -7883.6895 , -7683.6895 , -7483.6895 , -7283.6895 , -7083.6895 , -6883.6895 , -6683.6895 , -6483.6895 , -6283.6895 , -6083.6895 , -5883.6895 , -5683.6895 , -5483.6895 , -5283.6895 , -5083.6895 , -4883.6895 , -4683.6895 , -4483.6895 , -4283.6895 , -4083.6895 , -3883.6895 , -3683.6895 , -3483.6895 , -3283.6895 , -3083.6895 , -2883.6895 , -2683.6895 , -2483.6895 , -2283.6895 , -2083.6895 , -1883.6895 , -1683.6895 , -1483.6895 , -1283.6895 , -1083.6895 , -883.68945, -683.68945, -483.68948, -283.68948, -83.68948, 116.31052, 316.31052, 516.31055, 716.31055, 916.31055, 1116.3105 , 1316.3105 , 1516.3105 , 1716.3105 , 1916.3105 , 2116.3105 , 2316.3105 , 2516.3105 , 2716.3105 , 2916.3105 , 3116.3105 , 3316.3105 , 3516.3105 , 3716.3105 , 3916.3105 , 4116.3105 , 4316.3105 , 4516.3105 , 4716.3105 , 4916.3105 , 5116.3105 , 5316.3105 , 5516.3105 , 5716.3105 , 5916.3105 , 6116.3105 , 6316.3105 , 6516.3105 , 6716.3105 , 6916.3105 , 7116.3105 , 7316.3105 , 7516.3105 , 7716.3105 , 7916.3105 , 8116.3105 , 8316.311 , 8516.311 , 8716.311 , 8916.311 , 9116.311 , 9316.311 , 9516.311 , 9716.311 , 9916.311 , 10116.311 , 10316.311 , 10516.311 , 10716.311 , 10916.311 , 11116.311 , 11316.311 , 11516.311 , 11716.311 , 11916.311 , 12116.311 , 12316.311 , 12516.311 , 12716.311 , 12916.311 , 13116.311 , 13316.311 , 13516.311 , 13716.311 , 13916.311 , 14116.311 , 14316.311 , 14516.311 , 14716.311 , 14916.311 , 15116.311 , 15316.311 , 15516.311 , 15716.311 , 15916.311 , 16116.311 , 16316.311 , 16516.31 , 16716.31 ], dtype=float32)
- y(y)float327.344e+06 7.344e+06 ... 7.312e+06
- units :
- m
- long_name :
- y coordinate of projection
- standard_name :
- projection_y_coordinate
array([7343714., 7343514., 7343314., 7343114., 7342914., 7342714., 7342514., 7342314., 7342114., 7341914., 7341714., 7341514., 7341314., 7341114., 7340914., 7340714., 7340514., 7340314., 7340114., 7339914., 7339714., 7339514., 7339314., 7339114., 7338914., 7338714., 7338514., 7338314., 7338114., 7337914., 7337714., 7337514., 7337314., 7337114., 7336914., 7336714., 7336514., 7336314., 7336114., 7335914., 7335714., 7335514., 7335314., 7335114., 7334914., 7334714., 7334514., 7334314., 7334114., 7333914., 7333714., 7333514., 7333314., 7333114., 7332914., 7332714., 7332514., 7332314., 7332114., 7331914., 7331714., 7331514., 7331314., 7331114., 7330914., 7330714., 7330514., 7330314., 7330114., 7329914., 7329714., 7329514., 7329314., 7329114., 7328914., 7328714., 7328514., 7328314., 7328114., 7327914., 7327714., 7327514., 7327314., 7327114., 7326914., 7326714., 7326514., 7326314., 7326114., 7325914., 7325714., 7325514., 7325314., 7325114., 7324914., 7324714., 7324514., 7324314., 7324114., 7323914., 7323714., 7323514., 7323314., 7323114., 7322914., 7322714., 7322514., 7322314., 7322114., 7321914., 7321714., 7321514., 7321314., 7321114., 7320914., 7320714., 7320514., 7320314., 7320114., 7319914., 7319714., 7319514., 7319314., 7319114., 7318914., 7318714., 7318514., 7318314., 7318114., 7317914., 7317714., 7317514., 7317314., 7317114., 7316914., 7316714., 7316514., 7316314., 7316114., 7315914., 7315714., 7315514., 7315314., 7315114., 7314914., 7314714., 7314514., 7314314., 7314114., 7313914., 7313714., 7313514., 7313314., 7313114., 7312914., 7312714., 7312514., 7312314.], dtype=float32)
- topo(y, x)float321.56e+03 1.576e+03 ... 675.4 634.6
- units :
- m
- long_name :
- DEM topography
array([[1559.9685 , 1576.0101 , 1596.1437 , ..., 1635.7552 , 1634.1139 , 1631.9781 ], [1555.8754 , 1569.4413 , 1587.9323 , ..., 1644.9546 , 1642.1221 , 1639.3105 ], [1543.4315 , 1551.2893 , 1564.975 , ..., 1652.2167 , 1649.6512 , 1648.2223 ], ..., [ 721.311 , 793.7348 , 794.76855, ..., 670.80975, 638.66534, 593.50665], [ 583.3742 , 631.0298 , 643.98315, ..., 682.8188 , 657.583 , 620.7182 ], [ 397.87878, 454.5713 , 499.87976, ..., 689.34955, 675.3821 , 634.56604]], dtype=float32)
- topo_smoothed(y, x)float321.562e+03 1.576e+03 ... 666.6 640.1
- units :
- m
- long_name :
- DEM topography smoothed with radius: 3e+02 m
array([[1562.3899 , 1575.5225 , 1595.2311 , ..., 1636.1016 , 1635.7295 , 1634.0154 ], [1556.8356 , 1568.0334 , 1585.9905 , ..., 1642.8981 , 1642.0519 , 1640.1488 ], [1544.1066 , 1550.8052 , 1564.2987 , ..., 1650.3658 , 1649.824 , 1648.6449 ], ..., [ 718.1247 , 767.41565, 784.8907 , ..., 672.33405, 637.82294, 605.0041 ], [ 584.9133 , 620.1594 , 637.7927 , ..., 683.28156, 654.1354 , 626.2491 ], [ 448.80246, 488.51 , 523.30054, ..., 690.9097 , 666.60297, 640.1041 ]], dtype=float32)
- topo_valid_mask(y, x)int81 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1
- units :
- -
- long_name :
- DEM validity mask according to geotiff input (1-0)
array([[1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], ..., [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1]], dtype=int8)
- glacier_mask(y, x)int80 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
- units :
- -
- long_name :
- Glacier mask
array([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], dtype=int8)
- glacier_ext(y, x)int80 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
- units :
- -
- long_name :
- Glacier external boundaries
array([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], dtype=int8)
- obs_icevel_x(y, x)float320.1185 0.1567 ... 5.996 4.791
- units :
- m yr-1
- long_name :
- ITS LIVE velocity data in x map direction
array([[ 0.11848804, 0.15672402, 0.1676761 , ..., -3.611141 , -3.760553 , -3.6730022 ], [ 0.56412727, 0.66713625, 0.6472863 , ..., -1.8328778 , -1.9028624 , -1.8890616 ], [ 1.2289239 , 1.3438406 , 1.2844102 , ..., -0.7396673 , -0.8272911 , -0.9901537 ], ..., [15.45903 , 13.641185 , 10.196897 , ..., 6.4445724 , 5.391897 , 4.3860908 ], [13.317044 , 12.784773 , 9.83638 , ..., 7.119299 , 5.9328203 , 4.7705607 ], [ 7.593328 , 9.6364 , 7.0203457 , ..., 7.448215 , 5.996424 , 4.790665 ]], dtype=float32)
- obs_icevel_y(y, x)float321.509 0.8505 0.5083 ... 5.952 3.744
- units :
- m yr-1
- long_name :
- ITS LIVE velocity data in y map direction
array([[ 1.5092185 , 0.85045826, 0.5083212 , ..., -7.437274 , -7.5707464 , -5.826358 ], [ 1.3472883 , 0.7037182 , 0.32918996, ..., -10.173233 , -10.328931 , -8.146098 ], [ 1.3309436 , 0.8246813 , 0.4023115 , ..., -8.284247 , -8.553694 , -6.611468 ], ..., [ 18.186663 , 16.372404 , 12.205127 , ..., 6.109201 , 5.067505 , 3.8290935 ], [ 15.883765 , 15.469172 , 11.790064 , ..., 7.0543294 , 5.51023 , 3.8219392 ], [ 9.263445 , 11.766118 , 8.174723 , ..., 7.9282246 , 5.952441 , 3.7444026 ]], dtype=float32)
- author :
- OGGM
- author_info :
- Open Global Glacier Model
- pyproj_srs :
- +proj=tmerc +lat_0=0 +lon_0=-52.141 +k=0.9996 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
- max_h_dem :
- 2159.736
- min_h_dem :
- 0.0
- max_h_glacier :
- 2097.7734
- min_h_glacier :
- 0.0
# plot the salem map background, make countries in grey
smap = ds.salem.get_map(countries=False)
smap.set_shapefile(gdir.read_shapefile('outlines'))
smap.set_topography(ds.topo.data);
# get the wind data at 10000 m a.s.l.
u = ds.obs_icevel_x.where(ds.glacier_mask == 1)
v = ds.obs_icevel_y.where(ds.glacier_mask == 1)
ws = (u**2 + v**2)**0.5
The ds.glacier_mask == 1
command will remove the data outside of the glacier outline.
# get the axes ready
f, ax = plt.subplots(figsize=(9, 9))
# Quiver only every 3rd grid point
us = u[1::3, 1::3]
vs = v[1::3, 1::3]
smap.set_data(ws)
smap.set_cmap('Blues')
smap.plot(ax=ax)
smap.append_colorbar(ax=ax, label = 'ice velocity (m s$^{-1}$)')
# transform their coordinates to the map reference system and plot the arrows
xx, yy = smap.grid.transform(us.x.values, us.y.values, crs=gdir.grid.proj)
xx, yy = np.meshgrid(xx, yy)
qu = ax.quiver(xx, yy, us.values, vs.values)
qk = ax.quiverkey(qu, 0.82, 0.97, 100, '100 m s$^{-1}$',
labelpos='E', coordinates='axes')

OGGM-Shop: bed topography data¶
from oggm.shop import bedtopo
workflow.execute_entity_task(bedtopo.add_consensus_thickness, gdirs);
2021-02-17 22:21:18: oggm.workflow: Execute entity task add_consensus_thickness on 1 glaciers
with xr.open_dataset(gdir.get_filepath('gridded_data')) as ds:
ds = ds.load()
# plot the salem map background, make countries in grey
smap = ds.salem.get_map(countries=False)
smap.set_shapefile(gdir.read_shapefile('outlines'))
smap.set_topography(ds.topo.data);
f, ax = plt.subplots(figsize=(9, 9))
smap.set_data(ds.consensus_ice_thickness)
smap.set_cmap('Blues')
smap.plot(ax=ax)
smap.append_colorbar(ax=ax, label='ice thickness (m)');

OGGM-Shop: climate data¶
# TODO
What’s next?¶
look at the OGGM-Shop documentation
return to the OGGM documentation
back to the table of contents