
Overview¶
GDEX hosts output from a range of General Circulation Models (GCMs), including CMIP-era simulations. This notebook demonstrates how to access and analyze that output directly from GDEX, using one such dataset as a worked example.
The CESM2 Large Ensemble
(CESM2-LE) is a 100-member ensemble of climate simulations run with the Community
Earth System Model v2, designed to separate forced climate change from internal
variability. GDEX hosts it as dataset d010092
in cloud-optimized Zarr stores served over OSDF.
In this notebook we compute the ensemble’s Global Mean Surface Temperature
(GMST) — opening the Zarr stores directly (no intake-ESM) and using a Dask
LocalCluster to handle the out-of-core computation.
Spin up a Dask
LocalClusterOpen CESM2-LE
TREFHTZarr stores directly over OSDFCompute an area-weighted, annual-mean GMST across the ensemble
Visualize the GMST anomaly and its ensemble spread
Prerequisites¶
| Concepts | Importance | Notes |
|---|---|---|
| Introduction to ARCO/Zarr on GDEX | Necessary | Opening Zarr stores on GDEX |
| xarray | Necessary | Labeled N-D arrays |
| Dask | Necessary | Parallel / out-of-core compute |
| OSDF Cookbook | Helpful | What OSDF is and how to stream data |
| Area-weighted averaging | Helpful | Why we cosine-weight by latitude |
Time to learn: 35 minutes
Imports¶
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
from dask.distributed import LocalClusterSpin up a Dask cluster¶
CESM2-LE TREFHT is far larger than memory (tens of GB per scenario across all
members). A Dask LocalCluster
parallelizes the computation across your machine’s cores and streams data lazily,
so we never hold the full arrays in memory at once. Click the dashboard link in
the output to watch tasks execute.
cluster = LocalCluster(
n_workers=5,
memory_limit="4GiB",) # per worker
#
client = cluster.get_client()
client/home/runner/micromamba/envs/gdex-cookbook/lib/python3.12/site-packages/distributed/node.py:195: UserWarning: Port 8787 is already in use.
Perhaps you already have a cluster running?
Hosting the HTTP server on port 36043 instead
warnings.warn(
CESM2-LE on GDEX¶
We use TREFHT (reference-height air temperature, in K) at monthly frequency.
The ensemble is split across two forcing variants — cmip6 and smbb (50 members
each, 100 total) — and two experiments: historical (1850–2014) and ssp370
(2015–2100). Each combination is a single Zarr store.
The store paths follow a regular naming pattern, so we build the URLs directly. You can also discover them on the
d010092 data-access page,
or from the dataset’s intake-ESM catalog.)
DSID = "d010092"
# base = f"https://osdf-director.osg-htc.org/ncar-gdex/{DSID}/atm/monthly"
base = f"osdf:///ncar-gdex/{DSID}/atm/monthly"
stores = {
("historical", "cmip6"): f"{base}/cesm2LE-historical-cmip6-TREFHT.zarr",
("ssp370", "cmip6"): f"{base}/cesm2LE-ssp370-cmip6-TREFHT.zarr",
("historical", "smbb"): f"{base}/cesm2LE-historical-smbb-TREFHT.zarr",
("ssp370", "smbb"): f"{base}/cesm2LE-ssp370-smbb-TREFHT.zarr",
}
stores{('historical',
'cmip6'): 'osdf:///ncar-gdex/d010092/atm/monthly/cesm2LE-historical-cmip6-TREFHT.zarr',
('ssp370',
'cmip6'): 'osdf:///ncar-gdex/d010092/atm/monthly/cesm2LE-ssp370-cmip6-TREFHT.zarr',
('historical',
'smbb'): 'osdf:///ncar-gdex/d010092/atm/monthly/cesm2LE-historical-smbb-TREFHT.zarr',
('ssp370',
'smbb'): 'osdf:///ncar-gdex/d010092/atm/monthly/cesm2LE-ssp370-smbb-TREFHT.zarr'}Opening the Zarr stores¶
These are Zarr v2 stores with consolidated metadata, so we pass
consolidated=True and zarr_format=2. chunks={} keeps the arrays lazy
(Dask-backed) — nothing is read until we compute. We focus on the cmip6 forcing
variant here; swap in smbb to analyze the other half of the ensemble.
def open_store(experiment, forcing):
return xr.open_dataset(
stores[(experiment, forcing)],
engine="zarr",
chunks={},
consolidated=True,
zarr_format=2,)
historical = open_store("historical", "cmip6")
ssp370 = open_store("ssp370", "cmip6")
historicalComputing area-weighted GMST¶
A simple average over grid cells would over-weight the poles, where cells cover
less area. Therefore the correct method is to weight each cell by the cosine of its latitude.
We average over latitude and longitude while keeping time and member_id,
so we retain one GMST time series per ensemble member.
def get_lat_name(ds):
for lat_name in ["lat", "latitude"]:
if lat_name in ds.coords:
return lat_name
raise RuntimeError("Couldn't find a latitude coordinate")
def global_mean(ds):
lat = ds[get_lat_name(ds)]
weight = np.cos(np.deg2rad(lat))
weight /= weight.mean()
other_dims = set(ds.dims) - {"time", "member_id"}
return (ds * weight).mean(other_dims)We concatenate historical and ssp370 into one 1850–2100 timeline, take the
annual mean, compute the area-weighted global mean, and express it as an
anomaly relative to the 1850–1900 pre-industrial baseline.
%%time
merged = xr.concat([historical, ssp370], dim="time")
merged = merged.isel(member_id=slice(0, 10))
annual = merged["TREFHT"].resample(time="YS").mean()
gmst = global_mean(annual).rename("gmst")
gmst_ano = gmst - gmst.sel(time=slice("1850", "1900")).mean("time")CPU times: user 318 ms, sys: 9.07 ms, total: 327 ms
Wall time: 328 ms
%%time
gmst_ano = gmst_ano.compute()CPU times: user 11.2 s, sys: 1.41 s, total: 12.6 s
Wall time: 1min
Visualizing the GMST anomaly¶
Plotting every member (thin grey lines) alongside the ensemble mean (bold) shows both the forced warming signal and the spread from internal variability.
fig, ax = plt.subplots(figsize=(10, 6))
gmst_ano.plot.line(
x="time", hue="member_id", add_legend=False,
color="grey", lw=0.5, alpha=0.3, ax=ax,
)
gmst_ano.mean("member_id").plot.line(
x="time", color="C3", lw=2, ax=ax, label="Ensemble mean",)
ax.set_title("CESM2-LE Global Mean Surface Temperature Anomaly\n(cmip6 forcing, relative to 1850–1900)")
ax.set_ylabel("GMST anomaly (K)")
ax.set_xlabel("Year")
ax.legend()
ax.grid(True, alpha=0.3)
plt.show()
client.close()
cluster.close()Summary¶
We computed the CESM2 Large Ensemble’s global mean surface temperature from
GDEX’s Zarr stores: spin up a LocalCluster → open the stores lazily →
area-weight and average to annual GMST per member → plot the forced signal
against the ensemble spread.
What’s next?¶
Continue to the High-Resolution Dataset Workflow, which applies a similar GDEX access pattern to high-resolution model output.