PySLFP: Python Sea Level Fingerprints

pyslfp computes how sea level changes when mass is redistributed at the
Earth's surface, on a spherically symmetric, self-gravitating, rotating Earth.
It solves the sea level equation with the deformation of the solid Earth,
gravitational self-consistency between ice, oceans and solid Earth, and
rotational feedbacks, for two descriptions of the solid Earth:
- Elastic, for sea level fingerprints: the instantaneous pattern of sea
level change produced, for example, by the melting of an ice sheet.
- Viscoelastic, for glacial isostatic adjustment (GIA): sea level,
deformation and rotation evolving through an ice history on an Earth with a
mantle viscosity, with fixed or migrating shorelines.
Around these it provides:
- Love numbers computed for any spherically layered model described by
planetmodel, including the generalised
numbers the adjoint theory needs; a table for PREM is used by default.
- Sensitivity kernels by adjoint methods: for elastic fingerprints, and for a
viscoelastic evolution with respect to the ice history, the initial sea
level and the mantle viscosity.
- The fingerprint and the viscoelastic response to an ice history as linear
operators between Hilbert spaces, with observation models for tide gauges,
satellite altimetry, GRACE and GNSS, for Bayesian inversions built on
pygeoinf.
- Ice histories (ICE-5G, ICE-6G and ICE-7G), regional masks, and plotting on
map projections.
The theory follows Al-Attar et al. (2024)
for fingerprints and their kernels. Viscoelastic loading uses the
internal-variable formulation of Al-Attar & Tromp (2014), and its adjoints and
sensitivity kernels the adjoint theory of glacial isostatic adjustment of
Crawford et al. (2018), extended to
rotational feedbacks by Yu et al. (2025).
Documentation is at pyslfp.readthedocs.io.
Installation
pyslfp requires Python 3.12 or later and is available from PyPI:
pip install pyslfp
Plotting works out of the box. plt.show() needs matplotlib to have an
interactive backend, which on a Python built with tkinter, the usual case, it
already has. Where tkinter is absent, or if you would rather use Qt:
pip install "pyslfp[interactive]"
For development, clone the repository and use Poetry:
poetry install # runtime dependencies only
poetry install --with dev # adds pytest, sphinx, ruff, jupyter and the hooks
See CONTRIBUTING.md for the git hooks, the documentation
build and the release process.
A sea level fingerprint
The following melts ten per cent of the West Antarctic Ice Sheet and plots the
resulting sea level change. It is a condensed form of
the first tutorial.
import matplotlib.pyplot as plt
import pyslfp as sl
# PREM Earth model with present-day ICE-7G as the background state.
sle = sl.LinearSeaLevelEquation.from_defaults(lmax=256)
# The load associated with a 10% loss of West Antarctic ice.
direct_load = sle.state.west_antarctic_load(fraction=0.1)
# Sea level change, vertical displacement, potential change, and the angular
# velocity change (polar wander and length of day).
relative_sea_level_change, displacement, potential_change, angular_velocity_change = (
sle.solve_sea_level_equation(direct_load)
)
# Plot the sea level change in metres, masked to the oceans.
metre = sle.state.model.parameters.length_scale
fig, ax = sl.create_map_figure(figsize=(12, 6))
sl.plot(
relative_sea_level_change * sle.state.ocean_projection() * metre,
ax=ax,
colorbar_kwargs={"label": "Sea level change (m)"},
)
plt.show()
LinearSeaLevelEquation holds the shoreline fixed, the usual assumption for
present-day and near-future problems. The engine beneath it,
SeaLevelEquation, also solves the nonlinear equation with migrating
shorelines, and the generalised equation that adjoint calculations need.
A glacial isostatic adjustment run
The following runs the last deglaciation, ICE-7G from 26 ka to the present, on
PREM with a Maxwell mantle of viscosity 10²¹ Pa s beneath an elastic
lithosphere. It is a condensed form of
the seventh tutorial, and takes
about half a minute.
import numpy as np
import pyslfp as sl
from pyslfp.ice import IceNG
from pyslfp.viscoelastic import (
SeaLevelEvolution,
ViscoelasticOperator,
prem_maxwell,
viscoelastic_earth,
)
lmax = 64
# PREM with a Maxwell mantle of 10^21 Pa s, its top 77 km left elastic,
# made into the Earth model and the rheology in the library's units.
model = prem_maxwell(upper_mantle=1.0e21, lower_mantle=1.0e21)
earth_model, rheology = viscoelastic_earth(model, lmax)
operator = ViscoelasticOperator(rheology, lmax)
# The background state that ICE-7G records at 26 ka.
ice_model = IceNG(length_scale=earth_model.parameters.length_scale)
state = sl.EarthState.from_ice_model(ice_model, 26.0, earth_model)
# Half-kiloyear steps to the present; each snapshot holds the response,
# whose fields (sea level change, displacement, potential change) are
# read by name, with the angular velocity change beside them.
evolution = SeaLevelEvolution(operator, state)
snapshots, _ = evolution.run_ice_history(np.arange(26.0, -0.1, -0.5), ice_model)
present = snapshots[-1].response.field("relative_sea_level_change")
run_ice_history takes shorelines="migrating" to let the shorelines move,
and final_sea_level= to choose the initial sea level so that the run reaches
a given present-day sea level, as an ice history without its own sea level
needs. SeaLevelEvolution computes sensitivity kernels of any objective built
from the snapshots, by adjoint_ice_history and
continuous_adjoint_ice_history.
Units
Calculations are carried out in a single non-dimensional frame, planetmodel's
Scales.geophysical at the Earth's mean radius, in which the radius, the mean
density and the gravitational constant are one. Results are returned in these
units and converted to SI through the scales held by
state.model.parameters: length_scale for sea level and displacement,
parameters.scales.factor(...) for anything else. Ice histories are dated in
kiloyears before present. See the
units page.
Documentation
- Theory and methods:
the sea level equation, Love numbers and their conventions, rotational
feedback, viscoelastic loading and the adjoint kernels.
- Numerics and performance:
discretisation, convergence, cost, and the use of threads and processes.
- The API reference.
- The theory note,
docs/theory/pyslfp_theory.pdf,
with the full derivations.
Tutorials
The tutorials are scripts under tutorials/scripts, written in cells (# %%) so
that they run from the command line or cell by cell in an editor. Each has a
notebook generated from it in tutorials/notebooks, which can be run locally or
in Google Colab. They read the real datasets, so the first run downloads them.
| Tutorial |
Contents |
Colab |
01_first_fingerprint |
Everything at its default: the fingerprint of a West Antarctic melt. |
|
02_physics |
The scales, the Earth model, a state from an analytic ice model, a load of one's own, the linear and non-linear solutions. |
|
03_love_numbers |
The shipped table, computing Love numbers from PREM, the identities, the radial solutions, files, and the complex numbers of a viscoelastic body. |
|
04_operators |
The fingerprint as an operator, composition, adjoints and sensitivity kernels, polar wander and length of day, Sobolev spaces and tide gauges. |
|
05_inversion |
A Bayesian inversion of synthetic GLOSS tide gauge data for ice thickness change. |
|
06_forward_gia |
A first forward GIA run: a melting ice cap on a viscoelastic PREM, and postglacial rebound. |
|
07_ice7g_deglaciation |
ICE-7G from 26 ka to the present: uplift rates, the sea level curve and a Hudson Bay emergence record. |
|
08_gia_kernels |
Ice-history sensitivity kernels by the discrete and continuous adjoints. |
|
09_decay_time_viscosity |
The decay time of postglacial emergence and its viscosity kernel. |
|
10_initial_sea_level |
Calibrating the initial sea level of a thickness-only history against the present day, by the classical update and the adjoint gradient. |
|
11_anelastic_softening |
Fingerprints on an anelastic Earth: Love numbers of PREM softened to periods of months to decades, and the bias in mass recovered from GRACE with elastic numbers. |
|
12_ice_altimetry |
Ice altimetry and GRACE over the ice sheets: the mass that gravimetry sees and the height that altimetry sees, separated by inverting the two together. |
|
Data
The package needs a number of external datasets: a table of Love numbers for
PREM, the ICE-NG ice histories, ETOPO 2022 topography, the GLOSS tide gauge
network, the Randolph Glacier Inventory, and shapefiles for the regional
definitions. They are not distributed with the package, but
downloaded from Zenodo on first use and
cached locally, so the first call that needs a dataset pauses while it is
fetched. Datasets are fetched individually, so only what is used is downloaded.
The cache lives in ~/.pyslfp_data unless the PYSLFP_DATA environment
variable says otherwise, which is useful on shared machines and in CI. The cache
is only checked for presence, so a dataset that has changed on Zenodo is not
fetched again by itself: pyslfp.data.ensure_data("LOVE_NUMBERS", refresh=True)
deletes the cached copy and downloads it afresh, and
LoveNumbers.default(refresh=True) does the same for the Love number table.
Performance
The spherical harmonic transforms dominate the cost of a sea level
calculation; they use the multi-threaded ducc0 backend, with the thread count
read from OMP_NUM_THREADS when Python starts (all cores if it is unset). When
running many independent solves in worker processes, set OMP_NUM_THREADS=1
before starting Python so that the workers share the cores rather than
oversubscribe them; pyslfp.set_num_threads(n) changes the count in the
current process. The
numerics page gives
costs and the details.
Package layout