Run with a spinup and GCM data#

The initial state of glaciers play a large role for the model output. In this example we illustrate how to “spinup” a glacier (e.g.: make them grow) before running over the period of interest. For this example we use climate data from the CESM Last Millennium Ensemble.

# Libs
import matplotlib.pyplot as plt

# Locals
import oggm.cfg as cfg
from oggm import tasks, utils, workflow
from oggm.workflow import execute_entity_task
from oggm.utils import get_demo_file
# Initialize OGGM and set up the default run parameters
cfg.initialize()

# Local working directory (where OGGM will write its output)
cfg.PATHS['working_dir'] = utils.gettempdir('OGGM_spinup_run')

# Use multiprocessing?
cfg.PARAMS['use_multiprocessing'] = False

# This is necessary for spinup runs!
cfg.PARAMS['store_model_geometry'] = True
2023-03-07 12:45:56: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.
2023-03-07 12:45:56: oggm.cfg: Multiprocessing switched OFF according to the parameter file.
2023-03-07 12:45:56: oggm.cfg: Multiprocessing: using all available processors (N=2)
2023-03-07 12:45:56: oggm.cfg: PARAMS['store_model_geometry'] changed from `False` to `True`.

Pre-processed directories are being used here.

# How many grid points around the glacier?
# Make it large if you expect your glaciers to grow large
cfg.PARAMS['border'] = 80

# Go - initialize glacier directories
gdirs = workflow.init_glacier_regions(['RGI60-11.00897'], from_prepro_level=4)
2023-03-07 12:45:56: oggm.cfg: PARAMS['border'] changed from `40` to `80`.
2023-03-07 12:45:56: oggm.workflow: init_glacier_regions from prepro level 4 on 1 glaciers.
2023-03-07 12:45:56: oggm.workflow: Execute entity tasks [gdir_from_prepro] on 1 glaciers
2023-03-07 12:45:56: oggm.utils: /github/home/OGGM/download_cache/cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.4/L3-L5_files/CRU/centerlines/qc3/pcp2.5/no_match/RGI62/b_080/L4/RGI60-11/RGI60-11.00.tar verified successfully.

Here the paths to the CESM-LME files are set. (The demo files that are being used in this example don’t contain the whole last millennium, neither do they have the global coverage that they original files have. These demo files have been made for test purposes and to reduce the time it takes to run the example. If you use the demo files for a glacier outside the domain, you won’t get an error. Instead the climate of the nearest point to the glacier that is available in the demo files will be used, which could be thousands of kilometers away.)

# Additional climate file (CESM)
cfg.PATHS['cesm_temp_file'] = get_demo_file('cesm.TREFHT.160001-200512'
                                            '.selection.nc')
cfg.PATHS['cesm_precc_file'] = get_demo_file('cesm.PRECC.160001-200512'
                                             '.selection.nc')
cfg.PATHS['cesm_precl_file'] = get_demo_file('cesm.PRECL.160001-200512'
                                             '.selection.nc')
execute_entity_task(tasks.process_cesm_data, gdirs);
2023-03-07 12:45:56: oggm.workflow: Execute entity tasks [process_cesm_data] on 1 glaciers
2023-03-07 12:45:56: oggm.shop.gcm_climate: (RGI60-11.00897) process_cesm_data
2023-03-07 12:45:57: oggm.shop.gcm_climate: (RGI60-11.00897) process_gcm_data

Here the CESM-LME data is being pre-processed. This process makes use of the delta method and uses scaled temperature anomalies by default (it is strongly recommended to use this default setting of scaling the temperature anomalies, unless you have very good reasons not to do so).

execute_entity_task(tasks.process_cesm_data, gdirs)
2023-03-07 12:45:57: oggm.workflow: Execute entity tasks [process_cesm_data] on 1 glaciers
2023-03-07 12:45:57: oggm.shop.gcm_climate: (RGI60-11.00897) process_cesm_data
2023-03-07 12:45:57: oggm.shop.gcm_climate: (RGI60-11.00897) process_gcm_data
[None]
# Run the last 200 years with the default starting point (current glacier)
# and CESM data as input
execute_entity_task(tasks.run_from_climate_data, gdirs,
                    climate_filename='gcm_data',
                    ys=1801, ye=2000,
                    output_filesuffix='_no_spinup')
2023-03-07 12:45:58: oggm.workflow: Execute entity tasks [run_from_climate_data] on 1 glaciers
2023-03-07 12:45:58: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_no_spinup
2023-03-07 12:45:58: oggm.core.flowline: You are attempting to run_with_climate_data at dates prior to the RGI inventory date. This may indicate some problem in your workflow. Consider using `fixed_geometry_spinup_yr` for example.
/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py:2939: UserWarning: Unpickling a shapely <2.0 geometry object. Please save the pickle again; shapely 2.1 will not have this compatibility.
  out = pickle.load(f)
2023-03-07 12:45:58: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_no_spinup
/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py:2939: UserWarning: Unpickling a shapely <2.0 geometry object. Please save the pickle again; shapely 2.1 will not have this compatibility.
  out = pickle.load(f)
[<oggm.core.flowline.FluxBasedModel at 0x7fc8f729bdc0>]
# Run the spinup simulation - t* climate with a cold temperature bias
execute_entity_task(tasks.run_constant_climate, gdirs,
                    nyears=100, bias=0, temperature_bias=-0.5,
                    output_filesuffix='_spinup')
# Run a past climate run based on this spinup
execute_entity_task(tasks.run_from_climate_data, gdirs,
                    climate_filename='gcm_data',
                    ys=1801, ye=2000,
                    init_model_filesuffix='_spinup',
                    output_filesuffix='_with_spinup')
2023-03-07 12:46:03: oggm.workflow: Execute entity tasks [run_constant_climate] on 1 glaciers
2023-03-07 12:46:03: oggm.core.flowline: (RGI60-11.00897) run_constant_climate_spinup
/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py:2939: UserWarning: Unpickling a shapely <2.0 geometry object. Please save the pickle again; shapely 2.1 will not have this compatibility.
  out = pickle.load(f)
2023-03-07 12:46:03: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_spinup
2023-03-07 12:46:07: oggm.workflow: Execute entity tasks [run_from_climate_data] on 1 glaciers
2023-03-07 12:46:07: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_with_spinup
/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py:2939: UserWarning: Unpickling a shapely <2.0 geometry object. Please save the pickle again; shapely 2.1 will not have this compatibility.
  out = pickle.load(f)
2023-03-07 12:46:08: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_with_spinup
[<oggm.core.flowline.FluxBasedModel at 0x7fc8f7c4abc0>]

When starting from a spin-up, by default the last year of the spin-up is being used to initialize a glacier. With init_model_yr, you can select any other year from the spin-up as initial year. An important parameter here is cfg.PARAMS['store_model_geometry'] = True set above, which told OGGM to store these “restart files” during the run.

# Run a past climate run based on this spinup
execute_entity_task(tasks.run_from_climate_data, gdirs,
                    climate_filename='gcm_data',
                    ys=1801, ye=2000, init_model_yr=50,
                    init_model_filesuffix='_spinup',
                    output_filesuffix='_with_spinup_50yr')
2023-03-07 12:46:13: oggm.workflow: Execute entity tasks [run_from_climate_data] on 1 glaciers
2023-03-07 12:46:13: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_with_spinup_50yr
/usr/local/pyenv/versions/3.10.10/lib/python3.10/site-packages/oggm/utils/_workflow.py:2939: UserWarning: Unpickling a shapely <2.0 geometry object. Please save the pickle again; shapely 2.1 will not have this compatibility.
  out = pickle.load(f)
2023-03-07 12:46:13: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_with_spinup_50yr
[<oggm.core.flowline.FluxBasedModel at 0x7fc902a7c3d0>]
# Compile output
utils.compile_glacier_statistics(gdirs)
ds1 = utils.compile_run_output(gdirs, input_filesuffix='_no_spinup')
ds2 = utils.compile_run_output(gdirs, input_filesuffix='_with_spinup')
ds3 = utils.compile_run_output(gdirs, input_filesuffix='_with_spinup_50yr')
2023-03-07 12:46:18: oggm.utils: Applying global task compile_glacier_statistics on 1 glaciers
2023-03-07 12:46:18: oggm.workflow: Execute entity tasks [glacier_statistics] on 1 glaciers
2023-03-07 12:46:18: oggm.utils: (RGI60-11.00897) glacier_statistics
2023-03-07 12:46:19: oggm.utils: Applying global task compile_run_output on 1 glaciers
2023-03-07 12:46:19: oggm.utils: Applying compile_run_output on 1 gdirs.
2023-03-07 12:46:19: oggm.utils: Applying global task compile_run_output on 1 glaciers
2023-03-07 12:46:19: oggm.utils: Applying compile_run_output on 1 gdirs.
2023-03-07 12:46:19: oggm.utils: Applying global task compile_run_output on 1 glaciers
2023-03-07 12:46:19: oggm.utils: Applying compile_run_output on 1 gdirs.
# Plot
f, ax = plt.subplots(figsize=(9, 4))
(ds1.volume.sum(dim='rgi_id') * 1e-9).plot(ax=ax, label='No spinup')
(ds2.volume.sum(dim='rgi_id') * 1e-9).plot(ax=ax, label='With 100-yr spinup')
(ds3.volume.sum(dim='rgi_id') * 1e-9).plot(ax=ax, label='With 50-yr spinup')
ax.set_ylabel('Volume (km$^3$)')
ax.set_xlabel('')
ax.set_title('Hintereisferner volume under CESM-LME forcing')
plt.legend()
plt.tight_layout()
../_images/run_with_a_spinup_and_gcm_data_14_0.png

What’s next?#