{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Calibration to the geodetic MB: one number, three parameters\n", "\n", "OGGM calibrates the mass balance (MB) model of each glacier against one\n", "number: its average MB over 2000-2020, from geodetic observations (Hugonnet et\n", "al., 2021). The MB model has three parameters (`melt_f`, `prcp_fac`,\n", "`temp_bias`). One equation, three unknowns: infinitely many parameter sets match\n", "the observation exactly. This is called **equifinality**.\n", "\n", "`mb_calibration_from_geodetic_mb` deals with this by fixing parameters: by\n", "default, it calibrates `melt_f` and keeps the two others fixed. The \"informed\n", "three-step\" calibration, used for OGGM's preprocessed directories, starts from\n", "informed guesses of the three parameters and moves them one after another, only\n", "as far as needed.\n", "\n", "Here we ask what the geodetic MB tells us *on its own*. We calibrate the three\n", "parameters together with AdaPBS, and a prior which is as uninformative as\n", "possible. We will see that:\n", "\n", "- AdaPBS is not useless: all its particles match the observation, and it rules\n", " out a large part of the parameter space;\n", "- but what remains is a surface which spans almost the whole plausible range of\n", " each parameter: the posterior of each parameter is close to its prior;\n", "- these parameter sets are equally good, but not equivalent: they disagree on\n", " the winter MB, and on how sensitive the glacier is to warming;\n", "- more precise data of the same kind do not help. A prior does, or other\n", " kinds of observations.\n", "\n", "This notebook follows `wgms_static_calibration.ipynb`, which explains how\n", "AdaPBS works (prior, forward model, iterations, weights): read it first.\n", "\n", "AdaPBS is the work of K. Aalstad and E. Alonso-González (MuSA). If you use it,\n", "please cite Aalstad et al. (2026, https://doi.org/10.5194/gmd-19-8565-2026) and\n", "Alonso-González et al. (2022, https://doi.org/10.5194/gmd-15-9127-2022)." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "from oggm import cfg, utils, workflow\n", "from oggm.core.massbalance import (mb_calibration_from_geodetic_mb,\n", " decide_winter_precip_factor)\n", "\n", "from oggm_adapbs import glogit, gexpit, weighted_summary\n", "from oggm_adapbs.massbalance import (mb_calibration_from_geodetic_mb_adapbs, mb_prior,\n", " static_mb_model, seasonal_specific_mb)" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## Glacier and data\n", "\n", "We use Vernagtferner (Ötztal Alps, Austria) again, as in the first notebook. Its\n", "WGMS seasonal MB will tell us, at the end, what the geodetic MB cannot. We start\n", "from the OGGM preprocessed directories at level 3 (W5E5 climate, elevation band\n", "flowlines)." ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "cfg.initialize(logging_level='WARNING')\n", "cfg.PATHS['working_dir'] = utils.gettempdir('adapbs_geodetic_equifinality', reset=True)\n", "\n", "rgi_id = 'RGI60-11.00719' # Vernagtferner\n", "base_url = ('https://cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.6/'\n", " 'L3-L5_files/2025.6/elev_bands/W5E5/per_glacier/')\n", "gdir = workflow.init_glacier_directories([rgi_id], from_prepro_level=3,\n", " prepro_border=80,\n", " prepro_base_url=base_url)[0]\n", "\n", "# The temperature bias file used by OGGM's informed calibration\n", "temp_bias_file = ('https://cluster.klima.uni-bremen.de/~oggm/ref_mb_params/oggm_v1.6/'\n", " 'w5e5_rgi6_perglacier_temp_bias_v2025.6.2.csv')\n", "gdir.name" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "OGGM's table of geodetic MB (`utils.get_geodetic_mb_dataframe`, from Hugonnet et\n", "al., 2021) has three periods for each glacier: 2000-2010, 2010-2020 and\n", "2000-2020, in m w.e. yr-1, with their errors (1 sigma). We convert them to\n", "kg m-2 yr-1. OGGM uses the 20-year period by default." ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "geod = utils.get_geodetic_mb_dataframe().loc[[rgi_id]].set_index('period')\n", "geod = geod[['dmdtda', 'err_dmdtda']] * 1000 # m w.e. yr-1 -> kg m-2 yr-1\n", "print('Default period:', gdir.settings['geodetic_mb_period'])\n", "geod.round(0)" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "The glacier lost on average 913 kg m-2 per year (913 mm w.e.) between 2000\n", "and 2020, with an error of 154 kg m-2 yr-1. This is the one number we\n", "calibrate against.\n", "\n", "# Four deterministic calibrations\n", "\n", "`mb_calibration_from_geodetic_mb` calibrates up to three parameters, *one after\n", "the other*: it varies the first one within its bounds until the modelled MB\n", "matches the observation, and moves to the next one only if the first one cannot\n", "do it. The parameters which are not calibrated keep their starting values,\n", "taken from the glacier settings.\n", "\n", "The preprocessed directories were already calibrated (with the informed\n", "three-step method): their settings hold the calibrated values. We set the\n", "starting values back to OGGM's defaults first: `melt_f` = 5, `prcp_fac` from\n", "the winter precipitation (`decide_winter_precip_factor`), `temp_bias` = 0." ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "params = ['melt_f', 'prcp_fac', 'temp_bias']\n", "print('Calibrated in the preprocessed directory:',\n", " {p: round(gdir.settings[p], 2) for p in params})\n", "\n", "# Back to OGGM's default starting values\n", "gdir.settings['melt_f'] = cfg.PARAMS['melt_f']\n", "gdir.settings['prcp_fac'] = decide_winter_precip_factor(gdir)\n", "gdir.settings['temp_bias'] = 0.\n", "print('Starting values:', {p: round(gdir.settings[p], 2) for p in params})" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "Now four calls of `mb_calibration_from_geodetic_mb`, which differ only in the\n", "parameter calibrated first (`write_to_gdir=False`: we only want the values):\n", "\n", "- `melt_f` only (the default);\n", "- `temp_bias` only;\n", "- `prcp_fac` only;\n", "- the informed three-step calibration (`informed_threestep=True`): `temp_bias`\n", " is set from the temperature bias file, then `prcp_fac` moves within ±20% of\n", " its starting value, then `melt_f`, then `temp_bias` if needed." ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "calls = {\n", " 'melt_f only': dict(calibrate_param1='melt_f'),\n", " 'temp_bias only': dict(calibrate_param1='temp_bias'),\n", " 'prcp_fac only': dict(calibrate_param1='prcp_fac'),\n", " 'informed three-step': dict(informed_threestep=True,\n", " temp_bias_file_path=temp_bias_file),\n", "}\n", "det = {}\n", "for name, kwargs in calls.items():\n", " d = mb_calibration_from_geodetic_mb(gdir, write_to_gdir=False, **kwargs)\n", " det[name] = {p: float(d[p]) for p in params}\n", "det = pd.DataFrame(det).T" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "To check them, we compute the MB of each parameter set ourselves, with the\n", "static MB model of the first notebook (`static_mb_model`: the MB model on the\n", "inversion flowlines). The period 2000-01-01 to 2020-01-01 is the 20 years\n", "2000 to 2019. `set_params` sets the parameters of the MB model." ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "years = np.arange(2000, 2020)\n", "mb_mod, fls = static_mb_model(gdir, det.iloc[0].to_dict())\n", "\n", "def set_params(theta):\n", " # Set the parameters of the MB model (in the order of params)\n", " for p, v in zip(params, theta):\n", " setattr(mb_mod, p, v)\n", "\n", "def geodetic_mb(theta):\n", " # The mean MB 2000-2019 (kg m-2 yr-1) of one parameter set\n", " set_params(theta)\n", " return mb_mod.get_specific_mb(fls=fls, year=years).mean()\n", "\n", "det['MB 2000-2019'] = [geodetic_mb(th) for th in det[params].values]\n", "det.round(2)" ] }, { "cell_type": "markdown", "id": "12", "metadata": {}, "source": [ "Four parameter sets, four perfect fits. `melt_f` ranges from 5 to 12.4,\n", "`prcp_fac` from 0.50 to 3.36, `temp_bias` from 0 to 2.26 K. Which one is\n", "right? The geodetic MB cannot tell: the choice is made by the method (which\n", "parameter moves first, and from where), not by the data.\n", "\n", "# AdaPBS with a flat prior\n", "\n", "## There is no \"no prior\"\n", "\n", "AdaPBS needs a prior: it draws its first particles from it, and the posterior is\n", "the prior times the likelihood. The closest we can get to \"no prior\" is a\n", "**flat** prior: all values within the bounds are about equally likely.\n", "\n", "As in the first notebook, the prior of each parameter is logit-normal: Gaussian\n", "in the normal space, with the bounds at $-\\infty$ and $+\\infty$. Centred in the\n", "middle of the bounds (0 in the normal space) with a standard deviation of 1.4,\n", "it is close to uniform. For the bounds, we take OGGM's default ones, those of\n", "the deterministic calibration. They are wide: `temp_bias` goes from -15 to\n", "+15 K.\n", "\n", "Let's see what this prior looks like. We use `mb_prior` (see the first notebook)\n", "for the bounds only, and draw samples in the normal space:" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "# OGGM's default bounds, as used by mb_calibration_from_geodetic_mb\n", "oggm_bounds = {p: (gdir.settings[f'{p}_min'], gdir.settings[f'{p}_max']) for p in params}\n", "prior = mb_prior(gdir, params, prior_bounds=oggm_bounds)\n", "x_min, x_max = prior['x_min'], prior['x_max']\n", "\n", "# Samples of the flat prior: centred at 0 in normal space, sd 1.4\n", "flat_sd = 1.4\n", "rng = np.random.default_rng(0)\n", "flat_prior = gexpit(flat_sd * rng.standard_normal((10000, 3)), x_min, x_max)\n", "\n", "labels = {'melt_f': 'melt_f (kg m-2 day-1 K-1)', 'prcp_fac': 'prcp_fac',\n", " 'temp_bias': 'temp_bias (K)'}\n", "fig, axes = plt.subplots(1, 3, figsize=(13, 3))\n", "for k, (ax, p) in enumerate(zip(axes, params)):\n", " ax.hist(flat_prior[:, k], bins=np.linspace(x_min[k], x_max[k], 41), density=True,\n", " color='0.7')\n", " ax.set_xlabel(labels[p])\n", " ax.set_yticks([])\n", "axes[0].set_ylabel('density')\n", "plt.tight_layout()" ] }, { "cell_type": "markdown", "id": "14", "metadata": {}, "source": [ "Flat in the middle, falling off near the bounds. This is our \"we know\n", "nothing\" prior: `melt_f` anywhere between 1.5 and 17, `prcp_fac` between 0.1\n", "and 10, `temp_bias` between -15 and +15 K.\n", "\n", "## Running AdaPBS\n", "\n", "In the first notebook, we wrote the forward model ourselves. Here, the entity\n", "task `mb_calibration_from_geodetic_mb_adapbs` does everything for us: it reads\n", "the geodetic MB and its error, builds the prior, the forward model (the mean MB\n", "2000-2019 on the inversion flowlines, as above) and runs AdaPBS. Its arguments\n", "for the prior:\n", "\n", "- `prior_bounds`: the bounds (by default, those of `mb_prior`);\n", "- `centre_prior=False`: centre the prior in the middle of the bounds, not on\n", " OGGM's informed values;\n", "- `prior_sd`: the standard deviation in normal space.\n", "\n", "And for AdaPBS: we use 1000 particles per iteration, and allow up to 20\n", "iterations. A weakly constrained problem needs more of both: the posterior is a\n", "thin, curved surface, which is hard to approximate with the Gaussian proposals\n", "of AdaPBS. Each model run takes less than a millisecond, so this is cheap." ] }, { "cell_type": "code", "execution_count": null, "id": "15", "metadata": {}, "outputs": [], "source": [ "adapbs_kwargs = dict(n_particles=1000, max_iterations=20, neff_threshold=0.3, seed=0)\n", "\n", "ds = mb_calibration_from_geodetic_mb_adapbs(\n", " gdir,\n", " prior_bounds=oggm_bounds, # OGGM's default bounds\n", " centre_prior=False, # centred in the middle of the bounds\n", " prior_sd=flat_sd, # close to uniform\n", " **adapbs_kwargs)\n", "ds" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "The task returns an xarray Dataset:\n", "\n", "- one value per particle (dimension `particle`, all the particles of all the\n", " iterations): the parameters, their posterior `weight`, the predicted MB\n", " (`mb`) and the AdaPBS `iteration`;\n", "- the resampled, equally weighted particles (dimension `resampled`): the\n", " `posterior_*` variables;\n", "- the observation (`ref_mb`) and its error (`ref_mb_err`);\n", "- the AdaPBS diagnostics, one value per iteration (`adapbs_*`);\n", "- the prior and the log evidence (see below) in the attributes." ] }, { "cell_type": "code", "execution_count": null, "id": "17", "metadata": {}, "outputs": [], "source": [ "ds[['adapbs_n_history', 'adapbs_neff', 'adapbs_neff_frac']].to_dataframe().round(2)" ] }, { "cell_type": "markdown", "id": "18", "metadata": {}, "source": [ "AdaPBS needed 6 iterations (6000 model runs, a few seconds) to reach an effective sample\n", "size above 30% of 1000.\n", "\n", "Two small helper functions, to get the particles and their weights out of the\n", "Dataset, and the quantiles of the posterior (`weighted_summary`, see the first\n", "notebook):" ] }, { "cell_type": "code", "execution_count": null, "id": "19", "metadata": {}, "outputs": [], "source": [ "def particles(ds):\n", " # All the particles: one row per particle, one column per parameter\n", " return np.stack([ds[p].values for p in params], axis=1)\n", "\n", "def resampled(ds):\n", " # The equally weighted resampled particles\n", " return np.stack([ds[f'posterior_{p}'].values for p in params], axis=1)\n", "\n", "def summary(ds):\n", " return weighted_summary(particles(ds), ds['weight'].values, params)\n", "\n", "def fmt(row):\n", " return f\"{row['q50']:.2f} [{row['q5']:.2f}, {row['q95']:.2f}]\"\n", "\n", "flat_prior_df = weighted_summary(flat_prior, np.ones(len(flat_prior)) / len(flat_prior), params)\n", "pd.DataFrame({'flat prior': flat_prior_df.apply(fmt, axis=1),\n", " 'posterior': summary(ds).apply(fmt, axis=1)}).T" ] }, { "cell_type": "markdown", "id": "20", "metadata": {}, "source": [ "## The posterior\n", "\n", "The table gives the median and 5-95% range of each parameter. The ranges of\n", "`melt_f` and `prcp_fac` barely change: the posterior of these parameters is\n", "almost their prior. Only `temp_bias` is narrower: values far from 0 are ruled\n", "out (with -10 K, the glacier would grow whatever the other parameters are).\n", "\n", "The posterior is not exactly the prior either: the medians of `melt_f` and\n", "`prcp_fac` are lower. Where `melt_f` and `prcp_fac` are low, the MB is less\n", "sensitive to temperature, so that a wider range of `temp_bias` values matches\n", "the observation (within its error): these combinations get more weight." ] }, { "cell_type": "code", "execution_count": null, "id": "21", "metadata": {}, "outputs": [], "source": [ "colors = ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4']\n", "markers = {'melt_f only': 'o', 'temp_bias only': 's', 'prcp_fac only': '^',\n", " 'informed three-step': 'X'}\n", "\n", "def plot_marginals(results, priors=None):\n", " # Weighted histograms of the particles, one panel per parameter.\n", " # results: {name: (Dataset, color)}; priors: {name: (samples, color)}\n", " fig, axes = plt.subplots(1, 3, figsize=(13, 3.8))\n", " for k, (ax, p) in enumerate(zip(axes, params)):\n", " bins = np.linspace(x_min[k], x_max[k], 31)\n", " if p == 'temp_bias':\n", " bins = np.linspace(-6, 10, 31)\n", " for name, (samples, c) in (priors or {}).items():\n", " ax.hist(samples[:, k], bins=bins, density=True, histtype='step', ls='--',\n", " lw=1.2, color=c, label=name)\n", " for name, (r, c) in results.items():\n", " ax.hist(r[p].values, bins=bins, weights=r['weight'].values, density=True,\n", " histtype='step', lw=2, color=c, label=name)\n", " ax.set_xlabel(labels[p])\n", " ax.set_yticks([])\n", " axes[0].set_ylabel('density')\n", " axes[-1].legend(loc='upper left', bbox_to_anchor=(1.02, 1), frameon=False)\n", " plt.tight_layout()\n", "\n", "plot_marginals({'posterior': (ds, colors[0])}, priors={'flat prior': (flat_prior, '0.5')})" ] }, { "cell_type": "markdown", "id": "22", "metadata": {}, "source": [ "(The `temp_bias` panel is zoomed in on -6 to +10 K: the prior extends from -15\n", "to +15 K.)\n", "\n", "The marginals hide the most important thing: how the parameters depend on each\n", "other. The pair plots show the resampled particles, for each pair of\n", "parameters, coloured by the third one. The black markers are the four\n", "deterministic calibrations." ] }, { "cell_type": "code", "execution_count": null, "id": "23", "metadata": {}, "outputs": [], "source": [ "def plot_pairs(theta):\n", " pairs = [('melt_f', 'temp_bias', 'prcp_fac'), ('prcp_fac', 'temp_bias', 'melt_f'),\n", " ('melt_f', 'prcp_fac', 'temp_bias')]\n", " fig, axes = plt.subplots(1, 3, figsize=(14, 4))\n", " for ax, (px, py, pc) in zip(axes, pairs):\n", " ix, iy, ic = (params.index(p) for p in (px, py, pc))\n", " sc = ax.scatter(theta[:, ix], theta[:, iy], c=theta[:, ic], s=8, cmap='viridis')\n", " plt.colorbar(sc, ax=ax, label=labels[pc])\n", " for name, row in det.iterrows():\n", " ax.scatter(row[px], row[py], marker=markers[name], s=90, color='k',\n", " edgecolor='w', label=name, zorder=5)\n", " ax.set_xlabel(labels[px])\n", " ax.set_ylabel(labels[py])\n", " axes[0].legend(loc='upper right', fontsize=9)\n", " plt.tight_layout()\n", "\n", "plot_pairs(resampled(ds))" ] }, { "cell_type": "markdown", "id": "24", "metadata": {}, "source": [ "This is equifinality. The particles fill a two-dimensional surface in the\n", "three-dimensional parameter space:\n", "\n", "- left: for a given `prcp_fac` (a given colour), `melt_f` and `temp_bias`\n", " trade off along a curve. More melt per degree (higher `melt_f`) needs fewer\n", " degrees (lower `temp_bias`). A higher `prcp_fac` shifts the curve up: more\n", " snow needs more melt;\n", "- middle: for a given `melt_f`, more snow (higher `prcp_fac`) needs a higher\n", " `temp_bias`;\n", "- right: `melt_f` and `prcp_fac` alone tell us nearly nothing: (almost) any\n", " pair works, with the right `temp_bias`.\n", "\n", "The four deterministic calibrations all lie on this surface: each of them is\n", "one point of it, picked by the method.\n", "\n", "## The fit\n", "\n", "All these particles fit the observation. The histogram shows the predicted MB of\n", "the particles (with their weights), and the observation with its error:" ] }, { "cell_type": "code", "execution_count": null, "id": "25", "metadata": {}, "outputs": [], "source": [ "obs, obs_err = ds['ref_mb'].values[0], ds['ref_mb_err'].values[0]\n", "mb = ds['mb'].values[:, 0]\n", "\n", "fig, ax = plt.subplots(figsize=(7, 3.5))\n", "bins = np.linspace(obs - 5 * obs_err, obs + 5 * obs_err, 31)\n", "ax.hist(mb, bins=bins, weights=ds['weight'].values, density=True, color=colors[0],\n", " alpha=0.6, label='AdaPBS particles')\n", "x = np.linspace(bins[0], bins[-1], 200)\n", "ax.plot(x, np.exp(-0.5 * ((x - obs) / obs_err) ** 2) / (obs_err * np.sqrt(2 * np.pi)),\n", " color='k', label='observation ± error')\n", "ax.set_xlabel('MB 2000-2019 (kg m-2 yr-1)')\n", "ax.set_yticks([])\n", "ax.legend(frameon=False)\n", "\n", "# The particles of the first iteration are samples of the prior\n", "first = ds['iteration'].values == 1\n", "q = np.percentile(mb[first], [5, 95])\n", "print(f'MB of the prior samples, 5-95%: {q[0]:.0f} to {q[1]:.0f} kg m-2 yr-1')" ] }, { "cell_type": "markdown", "id": "26", "metadata": {}, "source": [ "The particles reproduce the observation and its error: the posterior predictive\n", "distribution of the MB is the observation. Before calibration (the samples of\n", "the prior), the MB ranged from -25 600 to +6 700 kg m-2 yr-1 (5-95%).\n", "\n", "So AdaPBS did its job: it found all the parameter sets which agree with the\n", "observation. It is the observation which does not say much about the\n", "parameters.\n", "\n", "# How much did we learn? The information gain\n", "\n", "How can we measure how much the observation told us? A standard measure is the\n", "**information gain**: the Kullback-Leibler (KL) divergence of the posterior\n", "from the prior,\n", "\n", "$$D_{KL} = \\int p(\\theta \\mid \\mathrm{obs}) \\,\n", "\\log \\frac{p(\\theta \\mid \\mathrm{obs})}{p(\\theta)} \\, d\\theta .$$\n", "\n", "It is 0 when the posterior is the prior (we learned nothing), and grows as the\n", "posterior becomes narrower than the prior. It is in nats (natural logarithm). An\n", "intuition: if prior and posterior were both uniform, the posterior would\n", "occupy a fraction $e^{-D_{KL}}$ of the volume of the prior.\n", "\n", "AdaPBS gives us all we need to compute it. With Bayes' theorem,\n", "$p(\\theta \\mid \\mathrm{obs}) / p(\\theta) = L(\\theta) / Z$, where $L$ is the\n", "likelihood and $Z$ the **evidence** (the probability of the observation under\n", "the prior, the normalising constant of the posterior). So:\n", "\n", "$$D_{KL} = \\mathrm{E}_{\\mathrm{posterior}}[\\log L(\\theta)] - \\log Z .$$\n", "\n", "The first term is the weighted mean of the log-likelihood of the particles\n", "(Gaussian, from their predicted MB). AdaPBS estimates $\\log Z$ along with the\n", "weights: it is in the attributes of the Dataset (`log_evidence`)." ] }, { "cell_type": "code", "execution_count": null, "id": "27", "metadata": {}, "outputs": [], "source": [ "def information_gain(ds):\n", " # KL divergence of the posterior from the prior (nats)\n", " err = ds['ref_mb_err'].values\n", " resid = (ds['mb'].values - ds['ref_mb'].values) / err # one row per particle\n", " log_lik = np.sum(-0.5 * np.log(2 * np.pi * err ** 2) - 0.5 * resid ** 2, axis=1)\n", " return np.sum(ds['weight'].values * log_lik) - ds.attrs['log_evidence']\n", "\n", "kl = information_gain(ds)\n", "print(f'Information gain: {kl:.2f} nats, exp(KL) = {np.exp(kl):.0f}')" ] }, { "cell_type": "markdown", "id": "28", "metadata": {}, "source": [ "The posterior occupies about 1/50 of the prior volume, in the sense above. This\n", "is not nothing: as we saw, most of it comes from ruling out values of\n", "`temp_bias` far from 0, which the flat prior allowed. But it is information\n", "about one *combination* of the parameters (the surface), not about each of\n", "them: the marginals of `melt_f` and `prcp_fac` are almost unchanged.\n", "\n", "How large is large? We get a feeling for it in the next section.\n", "\n", "# More data of the same kind\n", "\n", "What if the geodetic MB was more precise? Or if we used the two decades\n", "2000-2010 and 2010-2020 instead of the 20 years? We run the same calibration:\n", "\n", "- with half the observation error (`obs_err_factor=0.5`);\n", "- with the two decadal values as two observations (`ref_mb_period` with two\n", " periods: the task then has two observations, with their own errors)." ] }, { "cell_type": "code", "execution_count": null, "id": "29", "metadata": {}, "outputs": [], "source": [ "flat = dict(prior_bounds=oggm_bounds, centre_prior=False, prior_sd=flat_sd)\n", "results = {'20 years': ds}\n", "results['20 years, half error'] = mb_calibration_from_geodetic_mb_adapbs(\n", " gdir, obs_err_factor=0.5, **flat, **adapbs_kwargs)\n", "results['two decades'] = mb_calibration_from_geodetic_mb_adapbs(\n", " gdir, ref_mb_period=['2000-01-01_2010-01-01', '2010-01-01_2020-01-01'],\n", " **flat, **adapbs_kwargs)\n", "\n", "def table(results):\n", " rows = {}\n", " for name, r in results.items():\n", " row = summary(r).apply(fmt, axis=1).to_dict()\n", " row['iterations'] = r.sizes['adapbs_iteration']\n", " row['final Neff/Ne'] = f\"{r['adapbs_neff_frac'].values[-1]:.2f}\"\n", " row['KL (nats)'] = f'{information_gain(r):.2f}'\n", " rows[name] = row\n", " return pd.DataFrame(rows).T\n", "\n", "table(results)" ] }, { "cell_type": "markdown", "id": "30", "metadata": {}, "source": [ "Halving the error adds 0.65 nats of information, about $\\log 2 = 0.69$:\n", "exactly what we expect when the observation constrains a single direction of the\n", "parameter space (the surface gets twice as thin), and nothing else. The\n", "marginals do not change: a thinner surface is still a surface. It is only\n", "harder to sample: AdaPBS needs more iterations.\n", "\n", "The two decades are two observations, but they constrain the same thing (the MB\n", "of the decades differ by less than their errors, and the model gets the\n", "difference from the climate data anyway), and each of them is less precise\n", "than the 20-year value: no gain either.\n", "\n", "More data of the same kind do not help. We need either a prior (next sections)\n", "or observations of another kind.\n", "\n", "# Equally good, but not equivalent\n", "\n", "Does it matter which parameter set we pick, if they all fit the observation?\n", "For the past 20 years, not much. But the parameter sets describe different\n", "glaciers. We look at two quantities, for each resampled particle:\n", "\n", "- the winter MB (October to April) of the hydrological years 2000-2019, which\n", " WGMS measured on this glacier (`seasonal_specific_mb`, see the first\n", " notebook);\n", "- the sensitivity to warming: the change of the mean MB 2000-2019 when the\n", " temperature is 1 K higher (same geometry)." ] }, { "cell_type": "code", "execution_count": null, "id": "31", "metadata": {}, "outputs": [], "source": [ "def equifinal_check(theta):\n", " # The geodetic MB, the mean winter MB and the MB change for +1 K of each\n", " # parameter set (one row each)\n", " rows = []\n", " for th in theta:\n", " mb0 = geodetic_mb(th)\n", " winter = seasonal_specific_mb(mb_mod, fls, years)['winter'].mean()\n", " mb1 = geodetic_mb(th + [0, 0, 1]) # 1 K warmer\n", " rows.append({'MB 2000-2019': mb0, 'winter MB': winter, 'dMB / +1 K': mb1 - mb0})\n", " return pd.DataFrame(rows)\n", "\n", "check = equifinal_check(resampled(ds))\n", "check_det = equifinal_check(det[params].values).set_index(det.index)\n", "\n", "# The WGMS winter MB of the same years\n", "wgms = gdir.get_ref_mb_data(y0=2000, y1=2019)\n", "wgms_winter = wgms['WINTER_BALANCE'].mean()\n", "print(f'WGMS winter MB 2000-2019: {wgms_winter:.0f} kg m-2 '\n", " f\"({wgms['WINTER_BALANCE'].count()} years)\")\n", "\n", "summ = check.quantile([0.05, 0.5, 0.95]).T\n", "summ.columns = ['q5', 'q50', 'q95']\n", "pd.concat([summ, check_det.T], axis=1).round(0)" ] }, { "cell_type": "code", "execution_count": null, "id": "32", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(8, 5))\n", "th = resampled(ds)\n", "sc = ax.scatter(check['winter MB'], check['dMB / +1 K'], c=th[:, 1], s=8, cmap='viridis')\n", "plt.colorbar(sc, ax=ax, label=labels['prcp_fac'])\n", "for name, row in check_det.iterrows():\n", " ax.scatter(row['winter MB'], row['dMB / +1 K'], marker=markers[name], s=90,\n", " color='k', edgecolor='w', label=name, zorder=5)\n", "ax.axvline(wgms_winter, color='k', ls='--', lw=1.5, label='WGMS winter MB')\n", "ax.set_xlabel('mean winter MB 2000-2019 (kg m-2)')\n", "ax.set_ylabel('MB change for +1 K (kg m-2 yr-1)')\n", "ax.legend(loc='lower left', fontsize=9);" ] }, { "cell_type": "markdown", "id": "33", "metadata": {}, "source": [ "All these particles have the same MB 2000-2019 (within the observation error),\n", "but:\n", "\n", "- their winter MB ranges from 242 to 2897 kg m-2 (5-95%). It is\n", " mostly set by `prcp_fac` (the colours). WGMS measured 874 kg m-2;\n", "- their MB change for 1 K of warming ranges from -539 to -2066\n", " kg m-2 yr-1: a factor of about 4. Glaciers with a lot of\n", " accumulation (and therefore a lot of melt, to get the same MB) react more\n", " strongly to warming.\n", "\n", "The sensitivity to warming is what matters for projections: the same\n", "calibration data, with a different choice on the equifinal surface, give\n", "different futures. The deterministic calibrations each pick one point (their\n", "sensitivities range from -572 to -1552 kg m-2 yr-1), and say nothing about\n", "the others. AdaPBS shows the whole range.\n", "\n", "Here, the informed three-step calibration does well: its winter MB (935\n", "kg m-2) is close to the WGMS value. Its `prcp_fac` comes from the winter\n", "precipitation, which is precisely the information the geodetic MB lacks.\n", "\n", "The WGMS winter MB would select a band of this figure: the calibration with\n", "the winter and summer MB in the first notebook did exactly that. Without such\n", "observations, only the prior can choose.\n", "\n", "# The prior decides\n", "\n", "When the observations do not constrain the parameters, the posterior is\n", "whatever the prior makes of the equifinal surface. We compare three priors:\n", "\n", "- **flat**: as above;\n", "- **informed, OGGM bounds**: centred on OGGM's informed values (`melt_f` = 5,\n", " `prcp_fac` from the winter precipitation, `temp_bias` from the temperature\n", " bias file) with a standard deviation of 1, and OGGM's bounds. This is the\n", " prior of the first notebook;\n", "- **informed, narrow bounds**: the same centres, with the narrower default\n", " bounds of `mb_prior` (`prcp_fac` within a factor of 2 of its centre,\n", " `temp_bias` ±3 K). This is the default of\n", " `mb_calibration_from_geodetic_mb_adapbs`." ] }, { "cell_type": "code", "execution_count": null, "id": "34", "metadata": {}, "outputs": [], "source": [ "priors = {'flat': results['20 years']}\n", "priors['informed, OGGM bounds'] = mb_calibration_from_geodetic_mb_adapbs(\n", " gdir, prior_bounds=oggm_bounds, temp_bias_file_path=temp_bias_file, **adapbs_kwargs)\n", "priors['informed, narrow bounds'] = mb_calibration_from_geodetic_mb_adapbs(\n", " gdir, temp_bias_file_path=temp_bias_file, **adapbs_kwargs)\n", "\n", "tab = table(priors)\n", "for name, r in priors.items():\n", " q = equifinal_check(resampled(r))['dMB / +1 K'].quantile([0.05, 0.95])\n", " tab.loc[name, 'dMB / +1 K'] = f'[{q[0.05]:.0f}, {q[0.95]:.0f}]'\n", " tab.loc[name, 'log evidence'] = f\"{r.attrs['log_evidence']:.2f}\"\n", "tab.drop(columns=['iterations', 'final Neff/Ne'])" ] }, { "cell_type": "markdown", "id": "35", "metadata": {}, "source": [ "To plot the priors, we draw samples of the two informed ones, as for the flat\n", "prior. The prior of each run is stored in the attributes of its Dataset\n", "(centre, bounds and standard deviation, in the parameter space for the centre\n", "and bounds)." ] }, { "cell_type": "code", "execution_count": null, "id": "36", "metadata": {}, "outputs": [], "source": [ "def prior_samples(r, n=10000):\n", " # Samples of the prior of an AdaPBS run, from the attributes of its Dataset\n", " lo, hi = r.attrs['prior_min'], r.attrs['prior_max']\n", " mean = 0.\n", " if r.attrs['centre_prior']:\n", " mean = glogit(r.attrs['prior_centre'], lo, hi)\n", " z = mean + r.attrs['prior_sd'] * np.random.default_rng(0).standard_normal((n, 3))\n", " return gexpit(z, lo, hi)\n", "\n", "plot_marginals({f'{name} (posterior)': (r, c) for (name, r), c in zip(priors.items(), colors)},\n", " priors={f'{name} (prior)': (prior_samples(r), c)\n", " for (name, r), c in zip(priors.items(), colors)})" ] }, { "cell_type": "markdown", "id": "37", "metadata": {}, "source": [ "Dashed: the priors, solid: the posteriors. Each posterior follows its prior,\n", "except for the direction which the geodetic MB constrains. With the informed\n", "priors, the information gain is smaller (there was less to learn: the prior\n", "was already closer to the data), and the spread of the sensitivity to warming\n", "narrows: from [-2066, -539] kg m-2 yr-1 with the flat prior to [-1440, -633]\n", "with the narrow informed prior.\n", "\n", "The **log evidence** says how well each prior predicted the observation, before\n", "seeing it. It increases from the flat prior to the narrow informed one: the\n", "informed priors put more of their mass where the observation is (the\n", "difference between the flat and the narrow prior is a factor of\n", "$e^{1.95} \\approx 7$). This is a weak argument for them, with one\n", "observation. It does not tell whether the informed values are right: here, the\n", "WGMS winter MB agrees with them, but this need not be the case on other\n", "glaciers, and the narrow prior excludes parts of the equifinal surface which\n", "are physically possible.\n", "\n", "# Take-aways\n", "\n", "- One geodetic MB value cannot constrain three parameters: the parameter sets\n", " which fit it form a surface in the parameter space. OGGM's deterministic\n", " calibrations each pick one point on it; which one depends on the method, not\n", " on the data.\n", "- With a flat prior, AdaPBS finds this surface: all its particles fit the\n", " observation, and the posterior of each parameter is close to its prior,\n", " except for the values ruled out by the observation (`temp_bias` far from 0).\n", "- The information gain (KL divergence) quantifies this: about 3.9 nats. More\n", " precise data of the same kind add little: halving the error adds about\n", " $\\log 2$ nats, and two decadal values instead of one 20-year value add\n", " nothing.\n", "- The equifinal parameter sets are not equivalent: their winter MB differs by more\n", " than a factor of 10 and their sensitivity to warming by a factor of about 4. This uncertainty goes straight into projections.\n", "- With the geodetic MB alone, the prior decides. Choose it with care, report it,\n", " and check what it does to the quantities you care about. Observations of\n", " another kind (here the winter MB) are what really constrain the parameters.\n", "\n", "## Caveats\n", "\n", "- The observation error is that of the geodetic data only: the model error is\n", " not included (in the first notebook, it dominated). With a larger error, the\n", " surface would be thicker, but the conclusions would not change.\n", "- \"Flat\" depends on the parametrisation: a prior flat in `melt_f` is not flat\n", " in `log(melt_f)`. There is no prior without information.\n", "- The geometry is fixed: this calibrates the MB model, not the glacier\n", " evolution." ] } ], "metadata": { "kernelspec": { "display_name": "oggm_env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.15" } }, "nbformat": 4, "nbformat_minor": 5 }