Run with a long spinup and GCM data

Contents

Run with a long 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
2024-08-25 21:29:34: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.
2024-08-25 21:29:34: oggm.cfg: Multiprocessing switched OFF according to the parameter file.
2024-08-25 21:29:34: oggm.cfg: Multiprocessing: using all available processors (N=4)
2024-08-25 21:29:36: 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
# in OGGM v1.6 you have to explicitly indicate the url from where you want to start from
# we will use here the elevation band flowlines which are much simpler than the centerlines
base_url = ('https://cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.6/'
            'L3-L5_files/2023.3/elev_bands/W5E5/')
gdirs = workflow.init_glacier_directories(['RGI60-11.00897'], from_prepro_level=5,
                                          prepro_base_url=base_url)
2024-08-25 21:29:36: oggm.workflow: init_glacier_directories from prepro level 5 on 1 glaciers.
2024-08-25 21:29:36: oggm.workflow: Execute entity tasks [gdir_from_prepro] on 1 glaciers

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);
2024-08-25 21:29:36: oggm.workflow: Execute entity tasks [process_cesm_data] on 1 glaciers
2024-08-25 21:29:36: oggm.shop.gcm_climate: (RGI60-11.00897) process_cesm_data
2024-08-25 21:29:37: 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);
2024-08-25 21:29:37: oggm.workflow: Execute entity tasks [process_cesm_data] on 1 glaciers
2024-08-25 21:29:37: oggm.shop.gcm_climate: (RGI60-11.00897) process_cesm_data
2024-08-25 21:29:37: oggm.shop.gcm_climate: (RGI60-11.00897) process_gcm_data
# 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');
2024-08-25 21:29:37: oggm.workflow: Execute entity tasks [run_from_climate_data] on 1 glaciers
2024-08-25 21:29:37: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_no_spinup
2024-08-25 21:29:37: 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.
2024-08-25 21:29:37: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_no_spinup
# Run the spinup simulation: a rather "cold" climate with a cold temperature bias
execute_entity_task(tasks.run_constant_climate, gdirs, y0 = 1965,
                    nyears=100, bias=0, 
                    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');
2024-08-25 21:29:38: oggm.workflow: Execute entity tasks [run_constant_climate] on 1 glaciers
2024-08-25 21:29:38: oggm.core.flowline: (RGI60-11.00897) run_constant_climate_spinup
2024-08-25 21:29:38: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_spinup
2024-08-25 21:29:38: oggm.workflow: Execute entity tasks [run_from_climate_data] on 1 glaciers
2024-08-25 21:29:38: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_with_spinup
2024-08-25 21:29:38: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_with_spinup

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');
2024-08-25 21:29:39: oggm.workflow: Execute entity tasks [run_from_climate_data] on 1 glaciers
2024-08-25 21:29:39: oggm.core.flowline: (RGI60-11.00897) run_from_climate_data_with_spinup_50yr
2024-08-25 21:29:39: oggm.core.flowline: (RGI60-11.00897) flowline_model_run_with_spinup_50yr
# 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')
2024-08-25 21:29:39: oggm.utils: Applying global task compile_glacier_statistics on 1 glaciers
2024-08-25 21:29:39: oggm.workflow: Execute entity tasks [glacier_statistics] on 1 glaciers
2024-08-25 21:29:39: oggm.utils: (RGI60-11.00897) glacier_statistics
2024-08-25 21:29:39: oggm.utils: Applying global task compile_run_output on 1 glaciers
2024-08-25 21:29:39: oggm.utils: Applying compile_run_output on 1 gdirs.
2024-08-25 21:29:39: oggm.utils: Applying global task compile_run_output on 1 glaciers
2024-08-25 21:29:39: oggm.utils: Applying compile_run_output on 1 gdirs.
2024-08-25 21:29:40: oggm.utils: Applying global task compile_run_output on 1 glaciers
2024-08-25 21:29:40: 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('Year')
ax.set_title('Hintereisferner volume under CESM-LME forcing')
plt.legend()
plt.tight_layout()
../../_images/22245baa06d0f45e569e9ca0bc84b998a4591664693a553aa3b86237dbc94a65.png

What’s next?#