-
Notifications
You must be signed in to change notification settings - Fork 11
profsea-climate: Add new Antarctic component
#28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hemant Khatri (hmkhatri)
merged 24 commits into
profsea-climate
from
gm/add_AIS_emulator
Apr 13, 2026
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e6481bd
Added new antarctic component
gregrmunday a29f565
Improve performance + add ais_params.nc
gregrmunday 6deca3b
Add AIS and other notebooks
gregrmunday 2c09229
Updated code
gregrmunday 198652a
Dev updates
gregrmunday f4e68c9
model update
gregrmunday 18701d9
Merge branch 'profsea-climate' into gm/add_AIS_emulator
gregrmunday 7b37ee1
Resolve merge conflicts
gregrmunday 19f399b
Merge branch 'profsea-climate' into gm/add_AIS_emulator
gregrmunday 27da332
More AIS fitting...
gregrmunday b2ad506
Update comparison notebook
gregrmunday a9eff7a
Update for latest version
gregrmunday 41f3284
Mo' updates
gregrmunday cd616ce
Smol fix
gregrmunday eff2802
Optional spatial sampling
gregrmunday e80366e
Remove import
gregrmunday 792ad55
Add params
gregrmunday 4670d38
Add dim check and reformat
gregrmunday 4f29b6d
Fix bugs in probabilistic_wrapper.py
gregrmunday 763db36
Remove unnecessary notebooks
gregrmunday dd7ef43
Fix source attribute bug
gregrmunday 64cdbb3
Add comments and reformat
gregrmunday 11e388e
Smol fix
gregrmunday dfef6e9
Address review comments
gregrmunday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| from .gmslr import Global | ||
| from .spatial import Spatial | ||
| from .antarctica import AntarcticaISMIP6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| from pathlib import Path | ||
| from rich.progress import track | ||
| import numpy as np | ||
| from scipy.signal import fftconvolve | ||
| import xarray as xr | ||
|
|
||
|
|
||
| class AntarcticaISMIP6: | ||
| """ | ||
| ISMIP6 2300 Antarctic ice-sheet emulator with two-timescale response. | ||
|
|
||
| This emulation of the ISMIP6 ice-sheet model ensemble aims to capture | ||
| slow, fast and drift responses of the Antarctic ice sheet to GMST. | ||
| The slow response is modelled as the impulse response to temperature | ||
| forcing, convolved with two exponential decay kernels representing | ||
| different ice-sheet response timescales, depending on the region being modelled. | ||
| The fast response is modelled as a direct proportionality to the integrated | ||
| temperature anomaly, while the drift term captures any linear time-dependent | ||
| trends not explained by the temperature forcing. | ||
|
|
||
| Parameters provided are for the WAIS, EAIS and AIS Peninsula regions, since each has | ||
| different response characteristics to warming. | ||
| """ | ||
|
|
||
| def __init__(self, params_path: Path, samples: int = 1000): | ||
| self.param_ds = xr.load_dataset(params_path) | ||
| self.n_samples = samples | ||
| self.n_models = self.param_ds.coords["model"].shape[0] | ||
|
|
||
| def _impulse_response_term( | ||
| self, | ||
| tas: np.ndarray, | ||
| tau1: float, | ||
| tau2: float, | ||
| gamma: float, | ||
| params: np.ndarray, | ||
| dt: float, | ||
| ) -> np.ndarray: | ||
| """Computes the slow response term using convolution with two exponential decay kernels. | ||
| Parameters | ||
| ---------- | ||
| tas : np.ndarray | ||
| Time series of global mean surface air temperature anomalies (shape: n_time). | ||
| tau1 : float | ||
| Timescale of the first response component (in years). | ||
| tau2 : float | ||
| Timescale of the second response component (in years). | ||
| gamma : float | ||
| Exponent for the temperature forcing term. | ||
| params : np.ndarray | ||
| Array of shape (n_samples, 4) containing [alpha1, alpha2, beta, drift] parameters for each sample. | ||
| dt : float | ||
| Time step in years. | ||
| Returns | ||
| ------- | ||
| np.ndarray | ||
| Slow response term for each sample (shape: n_samples x n_time). | ||
| """ | ||
| n_time = tas.shape[0] | ||
|
|
||
| # Two slow coeffs | ||
| alphas1 = params[:, 0] | ||
| alphas2 = params[:, 1] | ||
|
|
||
| # Base forcing term to power of gamma, but preserving sign | ||
| forcing_base = np.sign(tas) * (np.abs(tas) ** gamma) | ||
|
|
||
| # Impulse response function for timescale 1 | ||
| decay_factors1 = np.exp(-np.arange(n_time) * dt / tau1) * (dt / tau1) | ||
| rate_delayed1 = fftconvolve(forcing_base, decay_factors1, mode="full")[:n_time] | ||
| t_conv1 = np.cumsum(rate_delayed1, axis=0) * dt | ||
| term_slow1 = alphas1[:, None] * t_conv1[None, :] | ||
|
|
||
| # Impulse response function for timescale 2 | ||
| decay_factors2 = np.exp(-np.arange(n_time) * dt / tau2) * (dt / tau2) | ||
| rate_delayed2 = fftconvolve(forcing_base, decay_factors2, mode="full")[:n_time] | ||
| t_conv2 = np.cumsum(rate_delayed2, axis=0) * dt | ||
| term_slow2 = alphas2[:, None] * t_conv2[None, :] | ||
|
|
||
| return term_slow1 + term_slow2 # Slow terms are linearly combined | ||
|
|
||
| def predict( | ||
| self, tas: np.ndarray, dt: float = 1.0, display_progress=True, seed=None | ||
| ) -> np.ndarray: | ||
| """ | ||
| Projects AIS response using empirical additive bootstrapping. | ||
| Parameters | ||
| ---------- | ||
| tas : np.ndarray | ||
| Time series of global mean surface air temperature anomalies (shape: n_time). | ||
| dt : float, optional | ||
| Time step in years (default: 1.0). | ||
| display_progress : bool, optional | ||
| Whether to show a progress bar during prediction (default: True). | ||
| seed : int or None, optional | ||
| Random seed for reproducibility (default: None). | ||
| Returns | ||
| ------- | ||
| np.ndarray | ||
| Projected AIS contributions (shape: n_models x n_samples x n_time). | ||
| """ | ||
| tas = np.squeeze(tas) | ||
| n_time = len(tas) | ||
| physical_time = np.arange(n_time) * dt | ||
|
|
||
| # RNG | ||
| rng = np.random.default_rng(seed) | ||
|
|
||
| # Integrated temperature term | ||
| tas_int = np.cumsum(tas) * dt | ||
|
|
||
| # Output shape: (n_models, n_samples, n_time) | ||
| all_preds = np.zeros((self.n_models, self.n_samples, n_time)) | ||
|
|
||
| # Shape assumed: (n_models, n_training_scenarios, 4) | ||
| all_residuals = self.param_ds.param_residuals.values | ||
| n_train_scenarios = all_residuals.shape[1] | ||
|
|
||
| for model in track( | ||
| range(self.n_models), | ||
| description="Projecting AIS response... ", | ||
| disable=not display_progress, | ||
| ): | ||
| # Unpack model-specific parameters | ||
| tau1 = float(self.param_ds.tau1[model].values) | ||
| tau2 = float(self.param_ds.tau2[model].values) | ||
| gamma = float(self.param_ds.gamma[model].values) | ||
|
|
||
| # Unpack general parameters [alpha1, alpha2, beta, drift] | ||
| general_p = self.param_ds.general_params[model].values | ||
|
|
||
| # Sample random parameter residuals for this model | ||
| rand_indices = rng.integers(0, n_train_scenarios, size=self.n_samples) | ||
| sampled_residuals = all_residuals[model, rand_indices, :] | ||
|
|
||
| # Add sampled parameter residuals to general parameters | ||
| total_params = general_p + sampled_residuals | ||
|
|
||
| # Slow response term | ||
| term_slow = self._impulse_response_term( | ||
| tas, tau1, tau2, gamma, total_params, dt | ||
| ) | ||
|
|
||
| # Fast response term | ||
| betas = total_params[:, 2] | ||
| term_fast = betas[:, None] * tas_int[None, :] | ||
|
|
||
| # Drift term | ||
| drift_coeffs = total_params[:, 3] | ||
| term_drift = drift_coeffs[:, None] * physical_time[None, :] | ||
|
|
||
| all_preds[model, :, :] = term_fast + term_slow + term_drift | ||
|
|
||
| return all_preds |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.