
Overview¶
NA-CORDEX (North American Coordinated Regional Downscaling Experiment) provides
regional climate model output over North America, dynamically downscaling global
models to higher resolution. GDEX hosts it as dataset
d316010.
This notebook makes quick diagnostic plots — first, middle, and last timesteps
across several model runs — to sanity-check a NA-CORDEX variable straight from
GDEX’s OSDF-hosted Zarr stores. We use daily maximum near-surface air temperature
(tmax) on the NAM-44i (~0.5°) grid for the evaluation scenario.
Spin up a Dask
LocalClusterOpen a NA-CORDEX Zarr store directly over OSDF
Build diagnostic plotting helpers
Plot first, middle, and last timesteps across model runs
Prerequisites¶
| Concepts | Importance | Notes |
|---|---|---|
| CESM2 Large Ensemble workflow | Helpful | Same OSDF direct-zarr + LocalCluster pattern |
| xarray | Necessary | Labeled N-D arrays |
| Dask | Necessary | Parallel / out-of-core compute |
| matplotlib | Necessary | Plotting |
Time to learn: 30 minutes
Imports¶
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
from dask.distributed import LocalClusterSpin up a Dask cluster¶
NA-CORDEX runs are large multi-member daily datasets. A LocalCluster parallelizes
the reads and the per-member reductions while keeping memory bounded.
cluster = LocalCluster(
n_workers=4,
threads_per_worker=2,
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 36175 instead
warnings.warn(
#url = "https://osdf-director.osg-htc.org/ncar-gdex/d316010/day/tmax.eval.day.NAM-44i.raw.zarr"
url = "osdf:///ncar-gdex/d316010/day/tmax.eval.day.NAM-44i.raw.zarr"
data_var = "tmax"
store_name = url.split("/")[-1]
ds = xr.open_dataset(url, engine="zarr", chunks={}, consolidated=True, zarr_format=2)
dsDiagnostic plotting helpers¶
Three small helpers: one to draw a single map with its min/max annotated, one to find the first and last timesteps that actually contain data (NA-CORDEX runs have different valid date ranges), and one to assemble a grid of first/middle/last maps for several members.
def plotMap(ax, map_slice, date_object=None, member_id=None):
"""Draw a single map on `ax`, annotating spatial min/max."""
ax.imshow(map_slice, origin="lower")
minval = map_slice.min(dim=["lat", "lon"])
maxval = map_slice.max(dim=["lat", "lon"])
ax.text(0.01, 0.03, "Min: %3g" % minval, transform=ax.transAxes, fontsize=12)
ax.text(0.99, 0.03, "Max: %3g" % maxval, transform=ax.transAxes, fontsize=12, horizontalalignment="right")
ax.set_xticks([])
ax.set_yticks([])
if date_object is not None:
ax.set_title(date_object.values.astype(str)[:10], fontsize=12)
if member_id is not None:
ax.set_ylabel(member_id, fontsize=12)
return axdef getValidDateIndexes(member_slice):
"""Return the indexes of the first and last timesteps with finite values."""
min_values = member_slice.min(dim=["lat", "lon"])
finite_indexes = np.where(np.isfinite(min_values))
return finite_indexes[0][0], finite_indexes[0][-1]def plot_first_mid_last(ds, data_var, store_name):
"""Plot first, middle, and final valid timesteps for several model runs."""
num_members_to_plot = 4
member_names = ds.coords["member_id"].values[0:num_members_to_plot]
fig, axs = plt.subplots(num_members_to_plot, 3, figsize=(18, 12), constrained_layout=True)
for index in np.arange(num_members_to_plot):
mem_id = member_names[index]
data_slice = ds[data_var].sel(member_id=mem_id)
start_index, end_index = getValidDateIndexes(data_slice)
mid_index = np.floor(len(ds.time) / 2).astype(int)
for col, t_index in enumerate([start_index, mid_index, end_index]):
date = ds.time[t_index]
step = data_slice.sel(time=date)
plotMap(axs[index, col], step, date, mem_id if col == 0 else None)
plt.suptitle(f'First, middle, and last timesteps for selected runs in "{store_name}"', fontsize=20)
return figPlotting first, middle, and last timesteps¶
This is the lightest of the diagnostics — it reads only a handful of 2D slices per member (plus a per-member finite-value scan to find valid dates).
%%time
plot_first_mid_last(ds, data_var, store_name)
plt.show()
CPU times: user 6.5 s, sys: 1.64 s, total: 8.14 s
Wall time: 1min 59s
client.close()
cluster.close()Summary¶
We opened NA-CORDEX daily maximum temperature directly from GDEX’s OSDF Zarr store,
spun up a LocalCluster, and produced first/middle/last diagnostic maps across
several regional-model runs — a quick way to sanity-check a multi-member dataset.
What’s next?¶
Continue to the CONUS404 workflow for another high-resolution GDEX dataset.