Simulations¶
Synthetic extremes generators for testing, teaching, and method development — data with a known ground truth, so you can check whether an estimator recovers the parameters you put in.
Unlike the rest of the package these are NumPy-based and take an integer
seed rather than a JAX PRNG key.
Extreme-value simulators¶
Per-variable simulators with physically sensible defaults: temperature block
maxima from a GEV, precipitation extremes, and wind gusts from a Weibull. Each
salts its RNG with a per-variable constant, so the same seed across
variables still yields independent fields rather than rank-correlated ones.
Synthetic extreme value data generators.
Temporal trajectories (GMST, energy balance), spatial domain/terrain generators, and variable-specific extreme generators for temperature, precipitation, and wind.
simulate_temp_extremes(mu: xr.DataArray, scale: float = 1.5, shape: float = -0.1, seed: int = 42) -> xr.Dataset
¶
Simulates Block Maxima Temperature via the GEV distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
DataArray
|
Location parameter (varying over time/space). |
required |
scale
|
float
|
Scale parameter (assumed constant here, but could be array). |
1.5
|
shape
|
float
|
Shape parameter (xi). |
-0.1
|
seed
|
int
|
Reproducibility seed. The stream is salted per variable, so temperature, precipitation, and wind simulators called with equal seeds still draw independently of each other. |
42
|
Source code in src/xtremax/simulations/extremes.py
simulate_precip_extremes(spatial_ds: xr.Dataset, gmst_da: xr.DataArray, seed: int = 42) -> xr.Dataset
¶
Simulates Precipitation Extremes: 1. Intensity (Rx1day): Gamma or GEV distribution. 2. Duration (Consecutive Wet Days - CWD): Poisson/Geometric approach.
The seed is salted per variable (see :func:simulate_temp_extremes).
Note: CWD is modelled as a Poisson draw whose mean is floored at 1.0 — a count model, not a true maximum over wet runs; it captures the trend in duration, not the extremal behaviour of run lengths.
Source code in src/xtremax/simulations/extremes.py
simulate_wind_extremes(spatial_ds: xr.Dataset, gmst_da: xr.DataArray, seed: int = 42) -> xr.Dataset
¶
Simulates Extreme Wind Speeds (Gusts) using Weibull distribution.
The seed is salted per variable (see :func:simulate_temp_extremes).
Source code in src/xtremax/simulations/extremes.py
Climate signals & GMST¶
Covariate trajectories for non-stationary EVT — a synthetic global mean
surface temperature series to regress the GEV parameters against.
generate_gmst_trajectory is the cheap statistical version;
generate_physical_gmst runs a 0-D energy-balance model for a trajectory with
physical structure rather than a fitted curve.
Synthetic extreme value data generators.
Temporal trajectories (GMST, energy balance), spatial domain/terrain generators, and variable-specific extreme generators for temperature, precipitation, and wind.
generate_gmst_trajectory(n_years: int = 40, start_year: int = 1981, trend_type: Literal['linear', 'exponential', 'logistic'] = 'linear', noise_std: float = 0.05, seed: int = 42) -> xr.DataArray
¶
Generates a synthetic Global Mean Surface Temperature (GMST) anomaly curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trend_type
|
Literal['linear', 'exponential', 'logistic']
|
Shape of the warming curve. |
'linear'
|
Source code in src/xtremax/simulations/temporal.py
generate_physical_gmst(n_years: int = 100, start_year: int = 1900, climate_sensitivity: float = 3.0, ocean_heat_capacity: float = 10.0, seed: int = 42) -> xr.Dataset
¶
Simulates Global Mean Surface Temperature (GMST) using a 0-D Energy Balance Model.
The evolution of temperature anomaly T(t) is governed by the ODE:
C * dT/dt = F(t) - lambda * T(t)
Where
C : Effective heat capacity of the system (ocean mixed layer). lambda : Climate feedback parameter (Watts / m2 / K). F(t) : Total Radiative Forcing (Watts / m2).
The feedback parameter lambda is derived from Equilibrium Climate Sensitivity (ECS): lambda = F_2xCO2 / ECS (F_2xCO2 is approx 3.7 W/m2)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_years
|
int
|
Duration of simulation. |
100
|
climate_sensitivity
|
float
|
Equilibrium warming for doubled CO2. |
3.0
|
ocean_heat_capacity
|
float
|
Thermal inertia (higher = slower response). |
10.0
|
Returns:
| Type | Description |
|---|---|
Dataset
|
xr.Dataset containing Temperature, Total Forcing, and Components. |
Source code in src/xtremax/simulations/temporal.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
compute_climate_signal(spatial_ds: xr.Dataset, gmst_da: xr.DataArray, base_val: float, coeffs: dict[str, float]) -> xr.DataArray
¶
Combines Spatial and Temporal fields to create a mean climate signal (Mu).
Formula: Mu = Base + C1Elev + C2Lat + C3GMST + (C4GMST*Elev)
Source code in src/xtremax/simulations/extremes.py
compute_advanced_climate_signal(spatial_ds: xr.Dataset, gmst_da: xr.DataArray) -> xr.Dataset
¶
Generates Tmax and Precip Mean fields using advanced physics proxies.
New Physics: 1. Continentality: Tmax increases with dist_to_coast. 2. Orographic Lift: Precip increases with Slope * Wind_Direction alignment. 3. Insolation: Tmax higher on South-facing slopes (Aspect ~ 180).
Source code in src/xtremax/simulations/spatial.py
Spatial domains & terrain¶
A worked spatial testbed: a procedural Iberian Peninsula with fractal Brownian-motion terrain, plus the feature extractors (elevation, distance to coast, and friends) that turn that geometry into covariates for spatial pooling.
Synthetic extreme value data generators.
Temporal trajectories (GMST, energy balance), spatial domain/terrain generators, and variable-specific extreme generators for temperature, precipitation, and wind.
SpatialFeatureExtractor
¶
Static methods to derive physical features from a Digital Elevation Model (DEM).
get_distance_to_coast(ds: xr.Dataset) -> xr.DataArray
staticmethod
¶
Calculates Euclidean distance to the nearest coast (mask boundary). Uses SciPy's Distance Transform.
Source code in src/xtremax/simulations/spatial.py
get_slope_and_aspect(ds: xr.Dataset) -> tuple[xr.DataArray, xr.DataArray]
staticmethod
¶
Calculates local Slope (magnitude) and Aspect (direction). Slope is critical for orographic precipitation. Aspect is critical for solar insolation (South vs North facing).
Source code in src/xtremax/simulations/spatial.py
get_roughness(ds: xr.Dataset, window_size: int = 3) -> xr.DataArray
staticmethod
¶
Calculates Terrain Roughness Index (TRI). Roughness = Std Dev of elevation in a local window.
Source code in src/xtremax/simulations/spatial.py
create_iberian_domain(res_deg: float = 0.1, bounds: tuple[float, float, float, float] = (-10, 5, 36, 44), seed: int = 42) -> xr.Dataset
¶
Creates the master spatial dataset with Lat, Lon, Elevation, and Land Mask.
Source code in src/xtremax/simulations/spatial.py
generate_iberia_mask(lat_grid: np.ndarray, lon_grid: np.ndarray) -> np.ndarray
¶
Procedurally generates a boolean mask approximating the Iberian Peninsula and Balearic Islands using geometrical primitives.
Source code in src/xtremax/simulations/spatial.py
generate_fractal_terrain(shape: tuple[int, int], scale: float = 100.0, octaves: int = 4, persistence: float = 0.5, lacunarity: float = 2.0, seed: int = 42) -> np.ndarray
¶
Generates coherent terrain using Fractal Brownian Motion (fBm). Instead of random elevations, this creates mountain ranges and valleys.
Source code in src/xtremax/simulations/spatial.py
generate_spatial_field(n_sites: int = 158, bounds: tuple[float, float, float, float] = (-9, 3, 36, 44), seed: int = 42) -> xr.Dataset
¶
Generates static spatial data: Lat, Lon, Elevation, Distance to Coast.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
tuple[float, float, float, float]
|
(lon_min, lon_max, lat_min, lat_max) |
(-9, 3, 36, 44)
|
Source code in src/xtremax/simulations/extremes.py
augment_spatial_features(ds: xr.Dataset) -> xr.Dataset
¶
Pipeline to run all extractors and merge into Dataset.
Returns a new Dataset; the input is not modified.