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)
WORKING_DIR = utils.gettempdir('OGGM_spinup_run')
utils.mkdir(WORKING_DIR, reset=True)
cfg.PATHS['working_dir'] = WORKING_DIR

# Use multiprocessing?
cfg.PARAMS['use_multiprocessing'] = False
2021-06-07 15:09:31: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.
2021-06-07 15:09:31: oggm.cfg: Multiprocessing switched OFF according to the parameter file.
2021-06-07 15:09:31: oggm.cfg: Multiprocessing: using all available processors (N=2)

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)
2021-06-07 15:09:31: oggm.cfg: PARAMS['border'] changed from `40` to `80`.
2021-06-07 15:09:31: oggm.workflow: init_glacier_regions from prepro level 4 on 1 glaciers.
2021-06-07 15:09:31: oggm.workflow: Execute entity task gdir_from_prepro on 1 glaciers
2021-06-07 15:09:31: 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);
2021-06-07 15:09:31: oggm.workflow: Execute entity task process_cesm_data on 1 glaciers
2021-06-07 15:09:31: oggm.shop.gcm_climate: (RGI60-11.00897) process_cesm_data
2021-06-07 15:09:32: 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)
2021-06-07 15:09:33: oggm.workflow: Execute entity task process_cesm_data on 1 glaciers
2021-06-07 15:09:33: oggm.shop.gcm_climate: (RGI60-11.00897) process_cesm_data
2021-06-07 15:09:34: 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')
2021-06-07 15:09:34: oggm.workflow: Execute entity task run_from_climate_data on 1 glaciers
2021-06-07 15:09:34: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_no_spinup
2021-06-07 15:09:38: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_no_spinup
[<oggm.core.flowline.FluxBasedModel at 0x7fa80f41a760>]
# 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')
2021-06-07 15:09:44: oggm.workflow: Execute entity task run_constant_climate on 1 glaciers
2021-06-07 15:09:44: oggm.core.flowline: (RGI60-11.00897) run_constant_climate_spinup
2021-06-07 15:09:44: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_spinup
2021-06-07 15:09:49: oggm.workflow: Execute entity task run_from_climate_data on 1 glaciers
2021-06-07 15:09:49: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_with_spinup
2021-06-07 15:09:53: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_with_spinup
[<oggm.core.flowline.FluxBasedModel at 0x7fa80ccbf610>]

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.

# 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')
2021-06-07 15:09:59: oggm.workflow: Execute entity task run_from_climate_data on 1 glaciers
2021-06-07 15:09:59: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_with_spinup_50yr
2021-06-07 15:10:02: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_with_spinup_50yr
[<oggm.core.flowline.FluxBasedModel at 0x7fa80d12cf70>]
# 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')
2021-06-07 15:10:09: oggm.utils: Applying global task compile_glacier_statistics on 1 glaciers
2021-06-07 15:10:09: oggm.workflow: Execute entity task glacier_statistics on 1 glaciers
2021-06-07 15:10:09: oggm.utils: (RGI60-11.00897) glacier_statistics
2021-06-07 15:10:09: oggm.utils: Applying global task compile_run_output on 1 glaciers
2021-06-07 15:10:09: oggm.utils: Applying compile_run_output on 1 gdirs.
2021-06-07 15:10:09: oggm.utils: Applying global task compile_run_output on 1 glaciers
2021-06-07 15:10:09: oggm.utils: Applying compile_run_output on 1 gdirs.
2021-06-07 15:10:09: oggm.utils: Applying global task compile_run_output on 1 glaciers
2021-06-07 15:10:09: 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?