Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

3. Workflow

Guillaume Jouvet edited this page May 9, 2023 · 54 revisions

Gridding and data format: IGM used a regular horizontal 2D raster grid, i.e. data/variables are defined at the center of each cell of the grid. The preferred and default format for I/O in IGM is NetCDF files.

Pre-processing (with OGGM )

To run IGM, you are required to provide at least topographical data (the bedrock, and initial ice thickness if any) in a NetCDF file (default name: geology.nc). You may include any other 2D variables relevant for modeling (e.g., ice flow parametrization, mask for surface mass balance modeling, ...). Any variables provided in the input NetCDF file (e.g., called myfield) will be automatically accessible and modifiable as glacier.myfield in IGM. IGM directly inherits from the 2D raster grid and the system of coordinates of this file and does all computations on it.

Optionally, IGM includes an inverse modeling/data assimilation module (of interest only for modern glaciers for which data are available) that seeks for optimal ice thickness, top surface elevation and ice flow parametrization that fit at best observational data such as ice flow speeds, ect. (provided in a file called observation.nc by default). Including the inverse modeling/data assimilation can be easily done by adding the command glacier.optimize() prior a forward model. Check for this page for the documentation of this module.

The workflow that includes optional inverse modelling and forward modeling is depicted in the following flowchart.

To create input files geology.nc and/or observation.nc, check at the script prepare-data-from-rgi.py based on OGGM in folder utils, which allows you to generate these two files providing the RGI number of your glacier (make sure to do it under the OGGM python environment, and make sure to use the latest version of OGGM). Thanks to Fabien Maussion for his support for the script, and Ethan Welty for helping with the integration of GlaThiDa data.

Ice flow emulator

Ice flow dynamics are modelled using Artificial Neural Networks emulators in IGM. Ready-to-used trained emulators can be found in the folder 'model-lib'. In IGM's original version (v1), the ice flow emulators were trained externally from ice flow model realizations. The downside of this original approach was the dependence on the instructor model realizations, and the difficulty to "generalize", i.e. to get an emulator that is valid beyond the "hull" defined by the data set. Therefore, IGM now proposes an improved emulation strategy in the second version (v2) that can deal with this issue by using physics-informed deep learning. Users may set the version glacier.config.version to 'v1' or 'v2' to choose the version of the emulator. In both cases, the link to the folder that contains the emulator has to be provided as a parameter in IGM (e.g. glacier.config.iceflow_model_lib_path = 'model-lib/f15_cfsflow_GJ_22_a'), and emulators are used when calling within the time iteration loop:

glacier.update_iceflow()

Most of the examples given in the wiki and examples refer to version 1. To migrate to version 2, read the following, and check at example aletsch-simple-v2.

Version 1: Original ice flow emulator (Default)

Reference : (Jouvet and al., JOG, 2022) & (Jouvet, JOG, 2023)

Emulator f15_cfsflow_GJ_22_a takes as input ice thickness, top surface slopes, the sliding coefficient, the Arrhenius factor, and returns basal, surface, and depth-averaged ice flow velocities. The spatial resolution must fit the one available with the emulator. You may visit folder 'model-lib' and READMEs, or check at this page for more information. If you want to train your own ice flow emulator, the 2D to 2D Deep-Learning Emulator (DLE) builds and trains convolutional neural networks, which map multi-channels 2D gridded inputs to outputs and capture spatial patterns from data. For that purpose, just visit this page.

Version 2: Physics Informed ice flow emulator (Experimental)

Reference : (Jouvet and Cordonnier, JOG, submitted)

In version 2, the emulator predicts 3D ice flow velocities (defined along a given number glacier.config.Nz of layers) from ice thickness, ice surface topography, sliding coefficient, the Arrhenius factor, and spatial resolution. Therefore, the user can take any spatial resolution. Here, the user can choose between i) taking a pre-trained emulator (as in version 1) as before setting glacier.config.iceflow_model_lib_path to the right path, e.g. '../../model-lib/f21_pinnbp_GJ_23_a/' OR ii) train its own from scratch setting glacier.config.iceflow_model_lib_path to an empty string ''. Then, the user can choose to re-trained the emulator on-the-fly (or online) according to his/her needs (what we recommend), or keep it as it is. In version 2, calling glacier.update_iceflow() is equivalent to calling:

glacier.update_iceflow_emulator()
glacier.update_iceflow_emulated()

where glacier.update_iceflow_emulator() controls the live-retraining of the emulator through the iterations with frequency parameter (glacier.config.retrain_iceflow_emulator_freq, set the 0 to not retrain (the cheapest, the least accurate), 1 to retrain at each iteration (the most expensive, the most accurate)), the learning rate parameter (retrain_iceflow_emulator_lr, set between 0.001 and 0.00002), and the number of training epochs (retrain_iceflow_emulator_nbit, set to 1 for online retraining, and to a large number of initial "from scratch" emulator). The second command glacier.update_iceflow_emulated() is the simple application of the emulator.

Any pre-trained ice flow emulator comes with two parameters that define the vertical discretization, namely glacier.config.Nz is the number of vertical points along the ice thickness and glacier.config.vert_spacing is a parameter that controls the vertical spacing (1 makes uniform spacing, while e.g. 4 produces 4 times finer layers near the bed compared to the surface as it is usually interesting the refine near the bedrock). When picking a pre-trained emulator, glacier.config.Nz and glacier.config.vert_spacing are automatically overridden with the values of the emulator. When training from scratch, these two parameters may be changed from default values (glacier.config.Nz=10 and glacier.config.vert_spacing=4).

Modeling run

To perform a forward glacier evolution simulation, IGM will run a loop in time to pass over a certain number of (mandatory and optional) model components (including physical and postprocessing), which are described below.

Once you prepared the input file (e.g. geology.nc) and having prepared ice flow emulators (in model-lib), one can run the glacier evolution model using the following command in a terminal:

python igm-run.py

where igm-run.py looks like:

import tensorflow as tf                           # import the tensorflow library
from igm import Igm                               # import the Igm class from the igm python package

glacier = Igm()                                   # Define an object 'glacier' of class Igm

# Here We can change all parameters we want, we give here a short list of important parameters.
glacier.config.working_dir            = ''        # Working directory
glacier.config.tstart                 = 1880      # Starting time
glacier.config.tend                   = 2100      # Ending time
glacier.config.tsave                  = 5         # Saving frequency
glacier.config.usegpu                 = True      # If True, it will try the GPU (fallback: CPU)
glacier.config.plot_result            = True      # Plot results in png when saved (alternative to NetCDF)
glacier.config.plot_live              = True      # Plot live the results during computation 
glacier.config.iceflow_model_lib_path = '../../model-lib/f15_cfsflow_GJ_22_a'  # Select ice flow emulator
glacier.config.geology_file           = 'geology.nc'                           # Geology file name

# Here we provide the time loop of model components (all what follows can be replaced by glacier.run())
glacier.initialize()                                     # Initialize essential variable of IGM
with tf.device(glacier.device_name):                     # This sends the job on CPU or GPU
    glacier.load_ncdf_data(glacier.config.geology_file)  # Open the geology.nc input data file
    glacier.initialize_fields()                          # Initialize all 2D fields 
    while glacier.t < glacier.config.tend:               # Time loop
	glacier.update_climate()            #(optional)  # Update climate variable
	glacier.update_smb()                #(mandatory) # Update surface mass balance
	glacier.update_iceflow()            #(mandatory) # Update ice flow dynamics
        glacier.update_particles()          #(optional)  # Update particle space-time positions
	glacier.update_t_dt()               #(mandatory) # Update time step, and time
	glacier.update_thk()                #(mandatory) # Update ice thickness
        glacier.update_topg()               #(optional)  # Update basal topography
	glacier.update_ncdf_ex()            #(optional)  # Output choseen 2D fields into a NetCDF file
	glacier.update_ncdf_ts()            #(optional)  # Output time series into a NetCDF file
	glacier.update_plot()               #(optional)  # Create new plot
	glacier.print_info()                #(optional)  # Print essential information (e.g. ice volume)

glacier.print_all_comp_info()                            # Print statistic of computational times

To build your own evolution model, just copy-paste this code and select the components you want to keep (but please respect the order, and do not remove mandatory components). The following section provides specific documentation about each model component while the list of all parameters can be found on this page. To go further, you may learn customizing IGM functions by checking this page.

Tip: Instead of passing the parameters in igm-run.py, you may pass them calling igm-run.py as follows (look for all options available adding --help):

python igm-run.py --tstart 0 --usegpu False 

IGM variables: All update functions above do operations on IGM variables (e.g., ice thickness). The list, name, and description of variables are described in this page. Any variables can be accessed/modified via glacier.nameofthevariable, e.g.,

glacier.thk   # is the ice thickness variable
glacier.usurf # is the top surface elevation

Plotting the ice thickness can be done with the following command:

import matplotlib.pyplot as plt
plt.imshow(glacier.thk,origin='lower') ; plt.colorbar()

Model components

The table below gives -- for each component -- a link to the documentation, the parameters, and code, as well as the input and output in terms of igm 2D variables:

Component igm function Doc, params, code Input Output
Climate update_climate() Here usurf air_temp, precipitation
Surface Mass Balance update_smb() Here usurf, (air_temp, precipitation) smb
Ice dynamics update_iceflow() Here thk,usurf,arrhenius,slidingco ubar,vbar,uvelbase,vvelbase,uvelsurf,vvelsurf
Particle tracking update_particles() Here xpos,ypos,ubar,vbar,thk xpos,ypos
Time step and time update_t_dt() Here ubar,vbar dt,t
Mass conservation update_thk() Here thk,smb,ubar,vbar thk
Lithospheric motion update_topg() Here topg, uvelbase, vvelbase topg, usurf
2D result output update_ncdf_ex() Here all ex.nc
Output (time series) update_ncdf_ts() Here ts.nc
Plotting update_plot() Here png files
Print results print_info() Here

Outputs

There are multiple ways to output IGM results:

  • Using update_ncdf_ex() will store results (wished list of variable can be changed in glacier.config.vars_to_save parameter) into a NetCDF file called ex.nc at a frequency defined by glacier.config.tsave (e.g. 5 y).

  • Using update_ncdf_ts() will store time series results into a NetCDF file called ts.nc at a frequency defined by glacier.config.tsave (e.g. 5 y).

  • Using update_plot() and setting glacier.config.plot_result = True will either produce png file or "live plots" (if glacier.config.plot_live = True) at a frequency defined by glacier.config.tsave (e.g. 5 y).

  • print_info() permits to print during the computation essential information on the run.

  • igm-run-parameters.txt summarizes all the parameters used for the run.

  • Function animate_result() permits to create a video animation from the output NetCDF file ex.nc

Clone this wiki locally