Running the DLESyM ISCCP-ERA5 Model¶
Coupled inference with the upstream DLESyM checkpoints, including precipitation.
This example demonstrates the upstream DLESyM model distributed by the
AtmosSci-DLESM/DLESyM group
(the University of Washington team behind Cresswell-Clay et al. 2024). It shares
the coupled atmosphere/ocean HEALPix architecture of the base
earth2studio.models.px.DLESyM model, but differs in a few ways that
are worth highlighting:
- The atmosphere carries an outgoing longwave radiation (OLR) channel. The model
was trained on ISCCP-distributed OLR, so the wrapper accepts ERA5
ttrand applies a per-day-of-year moment-matching transform to convert it to OLR internally (controlled by theuse_ttrflag). - A separate
earth2studio.models.dx.DLESyMv0_ISCCP_ERA5Precipdiagnostic predicts 6-hourly accumulated precipitation (tp06) from the full coupled state.
In this example you will learn:
- How to instantiate the upstream prognostic and precipitation models
- How the
ttr-> OLR transform shows up in the input/output variable sets - How to run a coupled forecast with the lat/lon convenience wrapper
- How to chain the precipitation diagnostic off the prognostic output
Set Up¶
As with the base DLESyM model, the upstream checkpoints run on a HEALPix
nside=64 grid, with derived input variables that no data source provides.
earth2studio.models.px.DLESyMv0_ISCCP_ERA5
recommends a source that prepares them: DLESyMInputSource fetches the base
variables from a lat/lon source (ARCO ERA5 by default), computes the derived
variables, fills the sea surface temperature over land and regrids onto HEALPix.
The model, the precipitation diagnostic and their outputs all stay on the native
grid; we regrid onto lat/lon only for plotting.
import os
os.makedirs("outputs", exist_ok=True)
from dotenv import load_dotenv
load_dotenv() # TODO: make common example prep function
import numpy as np
import torch
from earth2studio.data.utils import fetch_data
from earth2studio.models.dx import DLESyMv0_ISCCP_ERA5Precip
from earth2studio.models.px import DLESyMv0_ISCCP_ERA5
device = "cuda"
if not torch.cuda.is_available():
raise RuntimeError("GPU/CUDA required for DLESyM")
# Load the coupled prognostic and the precip diagnostic.
package = DLESyMv0_ISCCP_ERA5.load_default_package()
model = DLESyMv0_ISCCP_ERA5.load_model(package).to(device)
# The model's recommended source: ARCO ERA5 prepared as native HEALPix inputs
data = model.default_sources()
# The prognostic output is already in OLR space, so we load the precip
# diagnostic with ``use_ttr=False`` -- no further TTR -> OLR transform is needed
# when chaining off the model's own output. (Pass ``use_ttr=True`` to run the
# diagnostic standalone from an ERA5 initial condition instead.)
precip = DLESyMv0_ISCCP_ERA5Precip.load_model(package, use_ttr=False).to(device)
Console output60 lines
Downloading config.yaml: 0%| | 0.00/2.42k [00:00<?, ?B/s]
Downloading config.yaml: 100%|โโโโโโโโโโ| 2.42k/2.42k [00:00<00:00, 27.1kB/s]
Downloading hpx_lat.npy: 0%| | 0.00/384k [00:00<?, ?B/s]
Downloading hpx_lat.npy: 100%|โโโโโโโโโโ| 384k/384k [00:00<00:00, 596kB/s]
Downloading hpx_lat.npy: 100%|โโโโโโโโโโ| 384k/384k [00:00<00:00, 593kB/s]
Downloading hpx_lon.npy: 0%| | 0.00/384k [00:00<?, ?B/s]
Downloading hpx_lon.npy: 100%|โโโโโโโโโโ| 384k/384k [00:00<00:00, 962kB/s]
Downloading hpx_lon.npy: 100%|โโโโโโโโโโ| 384k/384k [00:00<00:00, 956kB/s]
Downloading atmos_model_0.mdlus: 0%| | 0.00/13.4M [00:00<?, ?B/s]
Downloading atmos_model_0.mdlus: 74%|โโโโโโโโ | 10.0M/13.4M [00:00<00:00, 17.5MB/s]
Downloading atmos_model_0.mdlus: 100%|โโโโโโโโโโ| 13.4M/13.4M [00:00<00:00, 22.3MB/s]
Downloading ocean_model_0.mdlus: 0%| | 0.00/2.97M [00:00<?, ?B/s]
Downloading ocean_model_0.mdlus: 100%|โโโโโโโโโโ| 2.97M/2.97M [00:00<00:00, 6.03MB/s]
Downloading ocean_model_0.mdlus: 100%|โโโโโโโโโโ| 2.97M/2.97M [00:00<00:00, 5.95MB/s]
Downloading land_sea_mask.npy: 0%| | 0.00/192k [00:00<?, ?B/s]
Downloading land_sea_mask.npy: 100%|โโโโโโโโโโ| 192k/192k [00:00<00:00, 496kB/s]
Downloading land_sea_mask.npy: 100%|โโโโโโโโโโ| 192k/192k [00:00<00:00, 493kB/s]
Downloading topography.npy: 0%| | 0.00/192k [00:00<?, ?B/s]
Downloading topography.npy: 100%|โโโโโโโโโโ| 192k/192k [00:00<00:00, 485kB/s]
Downloading topography.npy: 100%|โโโโโโโโโโ| 192k/192k [00:00<00:00, 483kB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 0%| | 0.00/137M [00:00<?, ?B/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 7%|โ | 10.0M/137M [00:00<00:09, 13.4MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 15%|โโ | 20.0M/137M [00:00<00:05, 24.4MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 22%|โโโ | 30.0M/137M [00:01<00:03, 33.4MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 29%|โโโ | 40.0M/137M [00:01<00:02, 41.8MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 36%|โโโโ | 50.0M/137M [00:01<00:01, 51.9MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 44%|โโโโโ | 60.0M/137M [00:01<00:01, 56.4MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 58%|โโโโโโ | 80.0M/137M [00:01<00:00, 74.5MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 66%|โโโโโโโ | 90.0M/137M [00:01<00:00, 77.5MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 73%|โโโโโโโโ | 100M/137M [00:01<00:00, 82.5MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 80%|โโโโโโโโ | 110M/137M [00:02<00:00, 83.0MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 87%|โโโโโโโโโ | 120M/137M [00:02<00:00, 87.2MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 95%|โโโโโโโโโโ| 130M/137M [00:02<00:00, 89.6MB/s]
Downloading era5_ttr_doy_stats_hpx64.nc: 100%|โโโโโโโโโโ| 137M/137M [00:02<00:00, 60.0MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 0%| | 0.00/137M [00:00<?, ?B/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 7%|โ | 10.0M/137M [00:00<00:08, 15.8MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 15%|โโ | 20.0M/137M [00:00<00:04, 27.7MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 22%|โโโ | 30.0M/137M [00:00<00:02, 39.6MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 29%|โโโ | 40.0M/137M [00:01<00:02, 46.6MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 44%|โโโโโ | 60.0M/137M [00:01<00:01, 67.6MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 51%|โโโโโ | 70.0M/137M [00:01<00:01, 45.4MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 58%|โโโโโโ | 80.0M/137M [00:02<00:01, 36.8MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 66%|โโโโโโโ | 90.0M/137M [00:02<00:01, 27.8MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 73%|โโโโโโโโ | 100M/137M [00:03<00:01, 26.4MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 80%|โโโโโโโโ | 110M/137M [00:03<00:01, 23.1MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 87%|โโโโโโโโโ | 120M/137M [00:04<00:00, 25.7MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 95%|โโโโโโโโโโ| 130M/137M [00:04<00:00, 26.0MB/s]
Downloading isccp_olr_doy_stats_hpx64.nc: 100%|โโโโโโโโโโ| 137M/137M [00:04<00:00, 31.2MB/s]
Downloading precip_model_0.mdlus: 0%| | 0.00/5.45M [00:00<?, ?B/s]
Downloading precip_model_0.mdlus: 100%|โโโโโโโโโโ| 5.45M/5.45M [00:00<00:00, 12.7MB/s]
Downloading precip_model_0.mdlus: 100%|โโโโโโโโโโ| 5.45M/5.45M [00:00<00:00, 12.5MB/s]Inspecting the Variable Sets¶
Note that ttr appears in the prognostic input variables (the wrapper
converts it to OLR internally), while the output variables report rlut
(OLR) -- the model variable space. The precip diagnostic consumes the full
10-variable coupled state and emits a single tp06 field.
in_coords = model.input_coords()
out_coords_vars = model.output_coords(in_coords)["variable"]
print("Prognostic input variables: ", in_coords["variable"])
print("Prognostic output variables:", out_coords_vars)
print("Precip input variables: ", precip.input_coords()["variable"])
Console output15 lines
Prognostic input variables: <xarray.DataArray 'variable' (variable: 10)> Size: 400B
array(['z500', 'tau300-700', 'z1000', 't2m', 'tcwv', 't850', 'z250', 'ws10m',
'ttr', 'sst'], dtype='<U10')
Coordinates:
* variable (variable) <U10 400B 'z500' 'tau300-700' 'z1000' ... 'ttr' 'sst'
Prognostic output variables: <xarray.DataArray 'variable' (variable: 10)> Size: 400B
array(['z500', 'tau300-700', 'z1000', 't2m', 'tcwv', 't850', 'z250', 'ws10m',
'rlut', 'sst'], dtype='<U10')
Coordinates:
* variable (variable) <U10 400B 'z500' 'tau300-700' 'z1000' ... 'rlut' 'sst'
Precip input variables: <xarray.DataArray 'variable' (variable: 10)> Size: 400B
array(['z500', 'tau300-700', 'z1000', 't2m', 'tcwv', 't850', 'z250', 'rlut',
'ws10m', 'sst'], dtype='<U10')
Coordinates:
* variable (variable) <U10 400B 'z500' 'tau300-700' 'z1000' ... 'ws10m' 'sst'Making a Coupled Prediction¶
We fetch an ERA5 initial condition, prepared on the HEALPix grid by the
source, and run the model directly. As with the base DLESyM model, the
atmosphere is predicted every 6 hours while the ocean only advances every
48 hours, so we use the retrieve_valid_* helpers to select the valid lead
times for each component.
ic_date = np.datetime64("2021-06-15")
x = fetch_data(
source=data,
time=np.array([ic_date]),
variable=np.array(in_coords["variable"]),
lead_time=in_coords.coords["lead_time"].values,
device=device,
)
# Run a single coupled step on the native grid
from earth2studio.run import _dimension_coords, map_field
x = map_field(x, in_coords)
y = model(x)
y_atmos = model.retrieve_valid_atmos_outputs(y)
y_ocean = model.retrieve_valid_ocean_outputs(y)
y_atmos_coords = _dimension_coords(y_atmos)
y_ocean_coords = _dimension_coords(y_ocean)
print(
"Atmosphere outputs (variables, lead_time [hrs]):",
y_atmos_coords["variable"],
y_atmos_coords["lead_time"].astype("timedelta64[h]"),
)
print(
"Ocean outputs (variables, lead_time [hrs]):",
y_ocean_coords["variable"],
y_ocean_coords["lead_time"].astype("timedelta64[h]"),
)
Console output64 lines
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 24.58it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 27.38it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 30.02it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 33.24it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 29.26it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 32.43it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 29.28it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 33.15it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 30.54it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 34.55it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 28.85it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 32.68it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 28.49it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 31.62it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 29.16it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 32.93it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 data: 0%| | 0/8 [00:00<?, ?it/s]
Fetching ARCO_ERA5 data: 88%|โโโโโโโโโ | 7/8 [00:00<00:00, 30.89it/s]
Fetching ARCO_ERA5 data: 100%|โโโโโโโโโโ| 8/8 [00:00<00:00, 34.93it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Fetching ARCO_ERA5 statistics: 0it [00:00, ?it/s]
Atmosphere outputs (variables, lead_time [hrs]): ['z500' 'tau300-700' 'z1000' 't2m' 'tcwv' 't850' 'z250' 'ws10m' 'rlut'] [ 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96]
Ocean outputs (variables, lead_time [hrs]): ['sst'] [48 96]Rolling Out to a 16-Day Forecast¶
A single coupled step advances 96 hours (4 days), so to reach a 16-day lead time we roll the iterator forward four steps. The iterator yields the initial condition first, then one coupled step per iteration; we keep the final step and re-select the valid atmosphere/ocean outputs from it.
forecast_days = 16
hours_per_step = int(model.atmos_output_times[-1] / np.timedelta64(1, "h")) # 96h
n_steps = int(np.ceil(forecast_days * 24 / hours_per_step))
model_iter = model.create_iterator(x)
# The iterator yields forecasts only (no initial condition)
for _ in range(n_steps):
y = next(model_iter)
y_atmos = model.retrieve_valid_atmos_outputs(y)
y_ocean = model.retrieve_valid_ocean_outputs(y)
y_coords = _dimension_coords(y)
y_atmos_coords = _dimension_coords(y_atmos)
y_ocean_coords = _dimension_coords(y_ocean)
print(
"Final forecast lead time:",
y_coords["lead_time"][-1].astype("timedelta64[h]"),
)
Console output1 line
Final forecast lead time: 384 hoursDiagnosing Precipitation¶
The precip diagnostic predicts 6-hourly accumulated precipitation from two
consecutive 6-hourly atmosphere timesteps of the full coupled state. The
16-day prognostic output y already contains exactly the 10 coupled
variables the diagnostic expects (in OLR / rlut space), so we take its
last two atmosphere lead times as the [-6, 0] history window. Both models
are on the same HEALPix grid, so no regridding is needed.
# The prognostic output carries the coupled variables in the prognostic's
# channel order, which differs from the order the precip diagnostic expects
# (e.g. ``ws10m`` and ``rlut`` are swapped). Reorder the variable axis to match
# the diagnostic's input variables before feeding it.
precip_vars = precip.input_coords().coords["variable"].values
# Last two atmosphere lead times form the [-6h, 0h] window relative to the
# diagnosed valid time; relative spacing is what the diagnostic validates.
precip_in = y.isel(lead_time=slice(-2, None)).sel(variable=precip_vars)
tp = precip(precip_in)
tp_coords = _dimension_coords(tp)
print(
"Precip output (variable, valid lead_time [hrs]):",
tp_coords["variable"],
tp_coords["lead_time"].astype("timedelta64[h]"),
)
Console output1 line
Precip output (variable, valid lead_time [hrs]): ['tp06'] [384]Plotting the Outputs¶
We plot a forecasted atmosphere field, the ocean SST, and the diagnosed
precipitation, regridded from HEALPix onto a 1 degree lat/lon grid with a
standalone earth2studio.grids.NearestRegridder.
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from earth2studio.grids import LatLonGrid, NearestRegridder
lat = np.linspace(90, -90, 181)
lon = np.linspace(0, 360, 360, endpoint=False)
to_latlon = NearestRegridder(
in_coords.attrs["earth2studio_grid_id"], LatLonGrid(lat, lon)
)
atmos_var, atmos_units = "ws10m", "m/s"
ocean_var, ocean_units = "sst", "K"
atmos_idx = list(y_atmos_coords["variable"]).index(atmos_var)
ocean_idx = list(y_ocean_coords["variable"]).index(ocean_var)
plt.close("all")
projection = ccrs.Robinson()
fig, axs = plt.subplots(1, 3, subplot_kw={"projection": projection}, figsize=(20, 6))
# Atmosphere: 10m wind speed at the final atmos lead time
atmos_lead = y_atmos_coords["lead_time"][-1]
im = axs[0].pcolormesh(
lon,
lat,
to_latlon(y_atmos[0, -1, atmos_idx].e2s.as_numpy()).values,
transform=ccrs.PlateCarree(),
cmap="cividis",
)
axs[0].set_title(f"{atmos_var} @ {atmos_lead.astype('timedelta64[h]')}")
axs[0].coastlines()
axs[0].gridlines()
cbar = fig.colorbar(im, ax=axs[0], orientation="horizontal", pad=0.05)
cbar.set_label(f"{atmos_var} [{atmos_units}]")
# Ocean: SST at the final ocean lead time
ocean_lead = y_ocean_coords["lead_time"][-1]
im = axs[1].pcolormesh(
lon,
lat,
to_latlon(y_ocean[0, -1, ocean_idx].e2s.as_numpy()).values,
transform=ccrs.PlateCarree(),
cmap="Spectral_r",
)
axs[1].set_title(f"{ocean_var} @ {ocean_lead.astype('timedelta64[h]')}")
axs[1].add_feature(cfeature.LAND, color="grey", zorder=100)
axs[1].coastlines()
axs[1].gridlines()
cbar = fig.colorbar(im, ax=axs[1], orientation="horizontal", pad=0.05)
cbar.set_label(f"{ocean_var} [{ocean_units}]")
# Precip: 6-hourly accumulated precipitation on a log color scale. We pin the
# color range to a fixed physical window (0.1 mm .. 50 mm per 6 h) rather than
# auto-scaling: the log-precip inverse transform can produce a handful of
# grid-scale outliers, and an auto-scaled norm would chase those and wash out
# the real field. Values are clipped into the window for display only.
precip_lead = tp_coords["lead_time"][-1]
precip_field = np.clip(to_latlon(tp[0, 0, 0].e2s.as_numpy()).values, 0.0, None)
vmin, vmax = 1e-4, 5e-2 # metres of accumulated precip over 6 h
im = axs[2].pcolormesh(
lon,
lat,
np.clip(precip_field, vmin, vmax),
transform=ccrs.PlateCarree(),
cmap="GnBu",
norm=LogNorm(vmin=vmin, vmax=vmax),
)
axs[2].set_title(f"tp06 @ {precip_lead.astype('timedelta64[h]')}")
axs[2].coastlines()
axs[2].gridlines()
cbar = fig.colorbar(im, ax=axs[2], orientation="horizontal", pad=0.05, extend="both")
cbar.set_label("tp06 [m] (log scale)")
plt.suptitle(f"Upstream DLESyM forecast - Initialization: {ic_date}")
plt.tight_layout()
plt.savefig("outputs/03_dlesym_climate_prediction.png")
