ERA5 → 12 km plains-to-ocean, convection-permitting hindcast (Breeze + SlabLand + PrescribedOcean)
A limited-area model (LAM) example that downscales ERA5 reanalysis to a ~12 km Breeze compressible atmosphere over a domain running from the U.S. Southern Great Plains to the Gulf of Mexico and the open Atlantic, for the Midlatitude Continental Convective Clouds Experiment (MC3E) 20 May 2011 squall-line case (Fan et al., 2017). The lower boundary is part land, part ocean: an interactive SlabLand and a prescribed-SST ocean share the surface through a fractional SurfacePartition, all-sky RRTMGP radiation heats the column and the surface, and the low-level jet that feeds the squall line draws its moisture from the resolved Gulf.
nested_atmosphere_model(grid, dataset; dates, …) builds the whole nest: an ERA5 "parent" BoundaryPrescribedComponent — PrescribedAtmosphere strips of ERA5 on its native 0.25° pressure-level grid, covering the child's lateral boundaries — driving a Breeze "child" through open lateral boundary conditions + lateral boundary relaxation, both derived on the fly from the parent's raw state. The constructor also initializes the child from the reanalysis and spins it into balance, so a plain Simulation(model) then steps the ready nest.
What this example does
- Downloads ERA5 (pressure + single levels) and regrids it onto a terrain-following
LatitudeLongitudeGrid(ETOPO2022 orography, blended to the parent's at the boundary). - Initializes the prognostic state from ERA5 with a hydrostatic-from-surface pressure, a terrain-consistent
w̃ ≈ 0, and a dynamical-initialization (DFI) pass that balancesρw. - Integrates the compressible equations with split-explicit acoustic substepping, 1-moment mixed-phase microphysics, Coriolis, and Rayleigh damping.
- Couples an interactive
SlabLand(prognostic skin temperature + bucket hydrology) and aPrescribedOceanunder the child through Monin–Obukhov similarity fluxes. TheSurfacePartition— built automatically because the model has both surfaces — blends each cell's land and ocean fluxes by its ETOPO2022-derivedocean_fraction, so coastal cells are fractionally wet rather than binary. - Runs all-sky RRTMGP radiative transfer inside the child — interior heating rates on the evolving clouds, observed (CGLS 1 km) surface albedo, surface fluxes into the land energy budget, and the partition-blended skin temperature closing the longwave loop.
- Writes and animates horizontal slices, a vertical section, and the surface response.
What it does NOT do (yet)
- Single nest only (ERA5 → 12 km; coarsened 4× from Fan's 3 km Domain 3 for a fast configuration).
- The land is a slab: no soil column, no vegetation, and no boundary-layer or cumulus parameterization — diffusion is numerical, and deep convection is resolved on the grid.
- The ocean is prescribed: the SST follows ERA5's sea surface temperature but does not respond to the atmosphere above it.
- No snowpack: the child's frozen precipitation reaches the bucket as liquid water; immaterial for this warm-season case.
using NumericalEarth
using Oceananigans
using Oceananigans.Units # `minutes` for the output schedule (not re-exported by Oceananigans)
using Oceananigans.OutputReaders: Clamp # time-indexing scheme for the prescribed SST series
using Breeze
using CopernicusClimateDataStore # activates NumericalEarthCopernicusClimateDataStoreExt (ERA5 + land-albedo downloads)
using CloudMicrophysics # nested_atmosphere_model's default microphysics → 1-moment mixed-phase
using RRTMGP # activates Breeze's radiative-transfer extension (RadiativeTransferModel)
using CairoMakie # loads Makie → NumericalEarthMakieExt (`visualize_nested_domain`)
using NaturalEarth, GeoInterface # together → NumericalEarthNaturalEarthExt (`natural_earth_lines`)
using CUDA
using Printf
using Dates: DateTime, Second[ Info: Oceananigans will use 8 threads
This 12 km LAM (220×176×50 ≈ 1.9M cells, split-explicit) targets a CUDA GPU; switch to CPU() only for a small smoke test.
arch = GPU()Oceananigans.Architectures.GPU{CUDACore.CUDAKernels.CUDABackend}(CUDACore.CUDAKernels.CUDABackend(false, true))Set Oceananigans' global default float type, cascading to all grids, fields, and constants.
Oceananigans.defaults.FloatType = Float32Float32Configuration
The domain covers Fan et al. (2017)'s 3 km WRF Domain 3 around the DOE Atmospheric Radiation Measurement (ARM) Southern Great Plains (SGP) site in Lamont, OK — coarsened 4× and driven directly by ERA5 — and extends south past the Texas–Louisiana coast into the open Gulf and east across Florida into the Atlantic, so the surface under the child is genuinely part land, part ocean. The northern edge stops at 41.5°N: ETOPO2022's below-sea-level test reads the Great Lakes as ocean (Lake Michigan's bed lies ≈ 105 m below sea level), and its southern tip sits at 41.6°N.
# dates
name = "mc3e"
duration = 6hours
start_date = DateTime(2011, 05, 20, 0)
stop_date = start_date + Second(duration)
# location: ARM SGP inland, with the Gulf, the Florida Straits and the open Atlantic to the south and east
φ₀, λ₀ = 36.605, -97.485 # ARM SGP site (deg)
λ_west, λ_east = -104.5, -80.0
φ_south, φ_north = 22.0, 41.5
Lλ = λ_east - λ_west
Lφ = φ_north - φ_south
# horizontal resolution: grid spacing in degrees; the cell counts follow from the extent
# (which stays fixed, so the realized spacing Lλ/Nx only approximates Δλ)
Δλ = Δφ = 1/9 # ≈ 12 km in latitude (ERA5's native 0.25° → 2.25× refinement)
Nx = round(Int, Lλ / Δλ)
Ny = round(Int, Lφ / Δφ)
dates = (start_date, stop_date)(Dates.DateTime("2011-05-20T00:00:00"), Dates.DateTime("2011-05-20T06:00:00"))Vertical grid matched to Fan et al. (2017)'s WRF nest: Nz = 50 cells, a constant 60 m surface cell, 490 m maximum spacing, and a model top at ~20 km (~50 hPa).
z = ReferenceToStretchedDiscretization(extent = 19525.0,
bias = :left,
bias_edge = 0,
constant_spacing = 60,
constant_spacing_extent = 60,
maximum_spacing = 490,
stretching = LinearStretching(0.15))
Nz = length(z)50LAM grid
A bounded terrain-following LatitudeLongitudeGrid. The terrain itself is handled by nested_atmosphere_model (its terrain keyword): ETOPO2022 is regridded onto the grid, blended toward the parent's ERA5 orography over the outermost relax_width cells (so the terrain at the open boundaries matches the parent state driving them), and materialized onto the grid's terrain-following coordinate (Gal-Chen–Somerville σ): the bottom follows the ground, the top stays flat.
grid = LatitudeLongitudeGrid(arch;
longitude = (λ_west, λ_east),
latitude = (φ_south, φ_north),
z = TerrainFollowingVerticalDiscretization(z),
size = (Nx, Ny, Nz),
halo = (5, 5, 5),
topology = (Bounded, Bounded, Bounded))220×176×50 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Bounded} on CUDAGPU with 5×5×5 halo
├── longitude: Bounded λ ∈ [-104.5, -80.0] regularly spaced with Δλ=0.111364
├── latitude: Bounded φ ∈ [22.0, 41.5] regularly spaced with Δφ=0.110795
└── z: Bounded z ∈ [0.0, 20003.0] variably spaced with terrain-following min(Δr)=60.0, max(Δr)=490.0Build the nest
nested_atmosphere_model(grid, dataset; dates, …) loads ERA5 on its native pressure-level grid along strips that cover the child's boundaries and relaxation zone (padded by two native ERA5 cells), initializes the child from a full-domain ERA5 snapshot, anchors the default split-explicit compressible dynamics at the domain-mean ERA5 surface pressure, derives the parent-driven lateral BCs + boundary relaxation (cosine ramp over relaxation_width cells), materializes the blended terrain, and wraps parent + child in a NestedModel whose time_step! advances the child then ticks the parent clock.
Time window: a (start, end) tuple — the hourly forcing cadence is the dataset's own. The initial outer time step is gentle (the adaptive wizard below ramps it). The lateral boundary relaxation is an explicit nudge dφ/dt = −r(φ − φₚₐᵣₑₙₜ), stable only for r·Δt ≲ 2, so its rate is a fixed 1/300 s⁻¹ — small enough that r·Δt stays well below 1 even at the wizard's max_Δt, rather than tied to Δt (which would climb into the over-relaxation regime as Δt grows). Momentum uses a narrower WENO(5) stencil, which interacts less violently with the open-boundary halo than the default WENO(9).
era5_datadir = "era5" # where ERA5 data is saved locally
dataset = ERA5HourlyPressureLevels()
relax_width = 5
nest = nested_atmosphere_model(grid, dataset;
dates,
dir = era5_datadir,
terrain = ETOPO2022(),
terrain_blend_width = relax_width,
relaxation_rate = 1/300,
relaxation_width = relax_width,
momentum_advection = WENO(order = 5))NestedModel(BoundaryPrescribedComponent with sides west, east, south, north → AtmosphereModel{GPU, LatitudeLongitudeGrid}(time = 0 seconds, iteration = 0))
├── parent: BoundaryPrescribedComponent with sides west, east, south, north
└── child: AtmosphereModel{GPU, LatitudeLongitudeGrid}(time = 0 seconds, iteration = 0)No bottom_drag_coefficient: the surface stress (with the heat and moisture fluxes) comes from the surface coupling below, so the child's bottom boundary conditions stay the coupler's flux fields.
The nest holds ERA5 only on strips along the child's boundaries. For the domain map and the ERA5 panels below, load ERA5 over the whole child, padded by two native 0.25° cells.
parent = PrescribedAtmosphere(BoundingBox(grid; padding = 1/2), dates, dataset; dir = era5_datadir)
era5_region = BoundingBox(parent.grid)NumericalEarth.DataWrangling.BoundingBox{Tuple{Float32, Float32}, Tuple{Float32, Float32}, Nothing}((-105.125f0, -79.375f0), (21.25f0, 42.25f0), nothing)Nested domains
Visualize the nesting before stepping the model — the ERA5 forcing region and the 12 km LAM child, over ETOPO relief with Natural Earth state/country boundaries — so the domain geometry is written even if the run is cut short.
fig = visualize_nested_domain(grid;
parent = era5_region,
padding = 2.5,
title = "ERA5 → 12 km LAM nest (MC3E squall line, ARM SGP)",
label = "12 km LAM (child)",
parent_label = "ERA5 parent",
landmarks = tuple("ARM SGP" => (λ₀, φ₀)))
save("era5_breeze_domains.png", fig)
figERA5 pressure velocity ω (Pa/s), loaded raw onto the parent's own grid — so it shares the parent's time-varying geopotential vertical and composes in the w ≈ −ω/(ρg) operation with the parent state.
ω_metadata = Metadata(:vertical_velocity; dataset, dates, region = era5_region, dir = era5_datadir)
ω_series = FieldTimeSeries(ω_metadata, parent.grid; time_indices_in_memory = length(ω_metadata.dates))103×84×37×7 FieldTimeSeries{DatasetBackend} located at (Center, Center, Center) on Oceananigans.Architectures.CPU
├── grid: 103×84×37 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Bounded} on CPU with 3×3×3 halo
├── indices: (:, :, :)
├── time_indexing: Cyclical(period=25200.0)
├── backend: DatasetBackend(1, 7)
└── data: 109×90×43×7 StaticStridesOffsetArray(::Array{Float32, 4}, -2:106, -2:87, -2:40, 1:7) with eltype Float32 with indices -2:106×-2:87×-2:40×1:7
└── max=3.05137, min=-6.87546, mean=-0.00942436The land–ocean surface
The lower boundary is part land, part Gulf of Mexico, and both surfaces live on the child's horizontal grid. The land is an interactive SlabLand — prognostic skin temperature plus bucket hydrology, driven by the coupled turbulent fluxes, the child's rain, and the radiation below; its bucket starts with ≈ 20 mm of water. The ocean is a PrescribedOcean whose SST follows ERA5's sea surface temperature, a near-surface value distinct from the instantaneous skin temperature that initializes the land.
surface_grid = LatitudeLongitudeGrid(arch;
longitude = (λ_west, λ_east),
latitude = (φ_south, φ_north),
size = (Nx, Ny),
halo = (5, 5),
topology = (Bounded, Bounded, Flat))
skin_temperature = Metadatum(:skin_temperature; dataset = ERA5HourlySingleLevel(),
date = start_date, region = era5_region, dir = era5_datadir)
land = SlabLand(surface_grid)
set!(land.temperature, skin_temperature)
set!(land; M = 20)SlabLand{Float32, GPU, LatitudeLongitudeGrid}(time = 0 seconds, iteration = 0)
├── grid: 220×176×1 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Flat} on CUDAGPU with 5×5×0 halo
├── energy: ForceRestoreEnergy(dry_heat_capacity=222000.0, liquid_heat_capacity=4186.0, deep_temperature=0.0, deep_time_scale=Inf)
├── hydrology: BucketHydrology(maximum_water_storage=150.0)
├── surface_storage: Nothing
├── temperature: 220×176×1 Field{Center, Center, Center} on LatitudeLongitudeGrid on CUDAGPU
├── water_storage: 220×176×1 Field{Center, Center, Center} on LatitudeLongitudeGrid on CUDAGPU
├── saturation: 220×176×1 Field{Center, Center, Center} on LatitudeLongitudeGrid on CUDAGPU
├── fluxes: (:surface_energy_flux, :precipitation, :evaporation)
├── diagnostics: ()
└── prognostic: ()The ocean follows ERA5's sea surface temperature rather than holding the initial analysis: a FieldTimeSeries over the same dates as the forcing, which the coupler reads at the ocean clock, interpolating linearly between hours. Clamp holds the end values outside the record, where the dataset default Cyclical would wrap May 20 03:00 back onto 00:00 at the final step.
sea_surface_temperature = Metadata(:sea_surface_temperature; dataset = ERA5HourlySingleLevel(),
dates, region = era5_region, dir = era5_datadir)
sst = FieldTimeSeries(sea_surface_temperature, surface_grid;
time_indices_in_memory = length(sea_surface_temperature.dates),
time_indexing = Clamp())
ocean = PrescribedOcean(surface_grid, sst.times; sea_surface_temperature = sst)PrescribedOcean{Float32, GPU, LatitudeLongitudeGrid}(Nt = 7)
├── grid: 220×176×1 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Flat} on CUDAGPU with 5×5×0 halo
├── times: 7-element StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}
├── density: 1025.0
└── heat_capacity: 4000.0Surface partition
What makes a cell land or ocean is its ocean_fraction ℵᵒᶜ: the fraction of the cell's area below sea level in ETOPO2022 — the same dataset that shapes the child's terrain, so the coastline and the orography agree. Coastal cells carry genuine fractions rather than a binary mask: the coupler blends each cell's land and ocean fluxes as (1 - ℵᵒᶜ) * land_fluxes + ℵᵒᶜ * ocean_fluxes; the radiation sees the same blend of skin temperatures.
ocean_fraction = regrid_ocean_fraction(surface_grid; dataset = ETOPO2022())220×176×1 Field{Center, Center, Nothing} reduced over dims = (3,) on LatitudeLongitudeGrid on CUDAGPU
├── grid: 220×176×1 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Flat} on CUDAGPU with 5×5×0 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: ZeroFlux, east: ZeroFlux, south: ZeroFlux, north: ZeroFlux, bottom: Nothing, top: Nothing, immersed: Nothing
└── data: 230×186×1 StaticStridesOffsetArray(::CUDACore.CuArray{Float32, 3, CUDACore.DeviceMemory}, -4:225, -4:181, 1:1) with eltype Float32 with indices -4:225×-4:181×1:1
└── max=1.0, min=0.0, mean=0.265978Alongside ℵᵒᶜ in the left panel, the right panel shows the sea surface temperature the ocean part of each cell supplies. ERA5's sea surface temperature is undefined over land and is inpainted there from the nearest water; masking to ℵᵒᶜ > 1/2 shows the water the partition actually weights — the Gulf, the Florida Straits and the western Atlantic.
Tᵒᶜ = Field{Center, Center, Nothing}(surface_grid)
set!(Tᵒᶜ, ocean.sea_surface_temperature[1])
interior(Tᵒᶜ) .= ifelse.(interior(ocean_fraction) .> 1/2, interior(Tᵒᶜ) .- 273.15, NaN)
fig_partition = Figure(size = (1320, 560))
ax_ℵᵒᶜ = Axis(fig_partition[1, 1]; xlabel = "longitude (°)", ylabel = "latitude (°)",
title = "Ocean fraction ℵᵒᶜ (ETOPO2022)")
hm_ℵᵒᶜ = heatmap!(ax_ℵᵒᶜ, ocean_fraction; colormap = :dense, colorrange = (0, 1))
scatter!(ax_ℵᵒᶜ, [λ₀], [φ₀]; marker = :star5, color = :orange, markersize = 15)
text!(ax_ℵᵒᶜ, λ₀ + 0.3, φ₀; text = "ARM SGP", color = :orange, align = (:left, :center))
Colorbar(fig_partition[1, 2], hm_ℵᵒᶜ)
ax_T = Axis(fig_partition[1, 3]; xlabel = "longitude (°)",
title = "Initial sea surface temperature where ℵᵒᶜ > 1/2")
hm_T = heatmap!(ax_T, Tᵒᶜ; colormap = :thermal, colorrange = (5, 30))
Colorbar(fig_partition[1, 4], hm_T; label = "°C")
save("gulf_ocean_fraction.png", fig_partition)
fig_partitionRRTMGP radiation
All-sky RRTMGP: interior heating on the evolving clouds, surface fluxes into the land budget. The surface albedo is observed, not constant — passing the dataset materializes the CGLS 1 km blue-sky albedo at the ten-day date nearest epoch, with water pixels (NaN in the land product) defaulting to open water — the Gulf gets its open-water albedo the same way. Everything else is a Breeze default — per-column sun angles from the grid, climatological ozone, emissivity, effective radii. No surface temperature either: the coupled model below binds the partition-blended skin temperature, re-read every solve. Hourly solves match the ERA5 cadence.
radiation = RadiativeTransferModel(grid, AllSkyOptics(), nest.child.thermodynamic_constants;
solar_position = ApparentSolarPosition(epoch = start_date),
surface_albedo = CopernicusAlbedo(),
schedule = TimeInterval(1hour))RadiativeTransferModel
├── solar_constant: 1361.0 W m⁻²
├── solar_position: ApparentSolarPosition(coordinate=<from grid>, epoch=2011-05-20T00:00:00)
├── surface_temperature: Nothing
├── surface_emissivity: ConstantField(0.98)
├── direct_surface_albedo: 220×176×1 Field{Center, Center, Nothing} reduced over dims = (3,) on LatitudeLongitudeGrid on CUDAGPU
├── grid: 220×176×50 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Bounded} on CUDAGPU with 5×5×5 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: ZeroFlux, east: ZeroFlux, south: ZeroFlux, north: ZeroFlux, bottom: Nothing, top: Nothing, immersed: Nothing
└── data: 230×186×1 StaticStridesOffsetArray(::CUDACore.CuArray{Float32, 3, CUDACore.DeviceMemory}, -4:225, -4:181, 1:1) with eltype Float32 with indices -4:225×-4:181×1:1
└── max=0.371343, min=0.0346602, mean=0.149383
├── liquid_effective_radius: Breeze.AtmosphereModels.ConstantRadiusParticles{Float32}(1.0f-5)
├── ice_effective_radius: Breeze.AtmosphereModels.ConstantRadiusParticles{Float32}(3.0f-5)
└── diffuse_surface_albedo: 220×176×1 Field{Center, Center, Nothing} reduced over dims = (3,) on LatitudeLongitudeGrid on CUDAGPU
├── grid: 220×176×50 LatitudeLongitudeGrid{Float32, Bounded, Bounded, Bounded} on CUDAGPU with 5×5×5 halo
├── boundary conditions: FieldBoundaryConditions
│ └── west: ZeroFlux, east: ZeroFlux, south: ZeroFlux, north: ZeroFlux, bottom: Nothing, top: Nothing, immersed: Nothing
└── data: 230×186×1 StaticStridesOffsetArray(::CUDACore.CuArray{Float32, 3, CUDACore.DeviceMemory}, -4:225, -4:181, 1:1) with eltype Float32 with indices -4:225×-4:181×1:1
└── max=0.371343, min=0.0346602, mean=0.149383Coupled model
EarthSystemModel wires nest, land, ocean, and radiation together. Because the model has both a land and an ocean component, the SurfacePartition activates automatically: each coupled step computes Monin–Obukhov fluxes over both surfaces from the child's lowest-cell state, blends them by the cell's ocean_fraction, and writes the blend into the child's bottom flux boundary conditions; the land's accumulators receive their per-land-area fluxes. The RTM is bound to the partition-weighted skin temperature — SST over the Gulf, the live land skin temperature inland. The adaptive outer Δt is bounded by the advective CFL (acoustic modes are substepped).
Δt = 10
atmosphere = Simulation(nest; Δt, verbose = false) ## the coupled model manages Δt and the stop time
model = EarthSystemModel(; atmosphere, land, ocean, radiation, ocean_fraction)
simulation = Simulation(model; Δt, stop_time=duration)
conjure_time_step_wizard!(simulation, IterationInterval(3); cfl=0.5, max_Δt=Δt)┌ Warning: PrescribedOcean{Float32, GPU, LatitudeLongitudeGrid}(Nt = 7) tracks time as Float32 but the EarthSystemModel clock uses Float64; coercing the component clock to keep components synchronized.
└ @ NumericalEarth.EarthSystemModels /storage5/github-action-runners/actions-runner-3/_work/NumericalEarth.jl/NumericalEarth.jl/src/EarthSystemModels/components.jl:171
Output
Three JLD2Writers save 2-D slices of one shared fields NamedTuple of online diagnostics — never the 3-D fields, which would overflow the disk. Each output is an AbstractOperation (Breeze's diagnostic accessors) that every writer computes and slices at save time via its own indices: horizontal slices at the surface and at k_aloft (the reference level nearest 2 km — on the terrain-following grid a constant reference level ≈ constant height above ground near the surface), and a zonal x-z section at j_section, the latitude row through the ARM SGP site. A fourth writer saves the surface: the land skin temperature, the bucket saturation, and the partition-blended skin temperature Tⁱⁿ the atmosphere sees (2-D already, no slicing needed — the writer stores each output's own grid).
child = nest.child
k_aloft = searchsortedfirst(Array(znodes(grid, Center())), 2000)
φ_centers = Array(φnodes(grid, Center(), Center(), Center()))
j_section = searchsortedfirst(φ_centers, φ₀)
fields = (θᵛ = VirtualPotentialTemperature(child),
U = sqrt(child.velocities.u^2 + child.velocities.v^2),
w = child.velocities.w,
qᵛ = specific_humidity(child),
qʳ = child.microphysical_fields.qʳ)
surface_filename = name * "_surface.jld2"
aloft_filename = name * "_aloft.jld2"
section_filename = name * "_section.jld2"
schedule = TimeInterval(20minutes)
slice_writer(indices, filename) = JLD2Writer(model, fields; schedule, filename, indices,
overwrite_files = true)
simulation.output_writers[:surface] = slice_writer((:, :, 1), surface_filename)
simulation.output_writers[:aloft] = slice_writer((:, :, k_aloft), aloft_filename)
simulation.output_writers[:section] = slice_writer((:, j_section, :), section_filename)
land_filename = name * "_land.jld2"
land_fields = (Tˡᵃ = land.temperature,
𝒮 = land.saturation,
Tⁱⁿ = surface_temperature(model.interfaces))
simulation.output_writers[:land] = JLD2Writer(model, land_fields; schedule,
filename = land_filename,
overwrite_files = true)
function progress(sim)
child = sim.model.atmosphere.model.child
u, v, w = child.velocities
ρ = child.dynamics.total_density
qᵛ = specific_humidity(child)
qʳ = child.microphysical_fields.qʳ
@info @sprintf("iter=%4d, t=%s, Δt=%s, max|u|=(%7.2f, %7.2f, %6.2f), ρ ∈ [%.4f, %.4f], qᵛ ∈ [%.4g, %.4g], qʳ ∈ [%.2g, %.2g]",
sim.model.clock.iteration, prettytime(sim), prettytime(sim.Δt),
maximum(abs, u), maximum(abs, v), maximum(abs, w), minimum(ρ), maximum(ρ),
minimum(qᵛ), maximum(qᵛ), minimum(qʳ), maximum(qʳ))
return nothing
end
add_callback!(simulation, progress, IterationInterval(100))Run
run!(simulation)[ Info: Initializing simulation...
[ Info: time = 0.0, iteration = 0: NaN found in field T_ocean. Stopping simulation.
[ Info: iter= 0, t=0 seconds, Δt=10 seconds, max|u|=( 45.67, 49.52, 0.84), ρ ∈ [0.0959, 1.1871], qᵛ ∈ [2.295e-06, 0.01995], qʳ ∈ [0, 0]
[ Info: ... simulation initialization complete (1.918 minutes)
[ Info: Executing initial time step...
[ Info: ... initial time step complete (2.270 minutes).
Cascade animation
A 2-row × 5-column animation of the downscaling: row 1 the ERA5 parent (dashed rectangle = child extent), row 2 the Breeze child. Columns are near-surface θᵛ′ (referenced pointwise to t=0, so the terrain/stratification background cancels and the cold pool stands out) and wind speed |U|, then w, qᵛ, qʳ at 2 km. The saved slices load straight back as FieldTimeSeries and plot directly — heatmap! reads each 2-D Field's own coordinates and moves it host-side, so there is no manual indexing, and the θᵛ′ anomaly θᵛ[n] - θᵛ[1] is a lazy field operation.
θᵛ_series = FieldTimeSeries(surface_filename, "θᵛ")
U_series = FieldTimeSeries(surface_filename, "U")
w_series = FieldTimeSeries(aloft_filename, "w")
qᵛ_series = FieldTimeSeries(aloft_filename, "qᵛ")
qʳ_series = FieldTimeSeries(aloft_filename, "qʳ")
times = θᵛ_series.times1-element Vector{Float64}:
0.0The parent is prescribed (no output file). Its rows are reconstructed at each frame time from the parent's own raw ERA5 fields — which are full-in-memory FieldTimeSeries — via breeze_prognostic_state, the exported (T, qᵛ, p) → (ρ, θˡⁱ, qᵗ) transform (the same physics the lateral BCs apply). We do NOT read the StateExchanger prognostics here: that FTS is a 2-level window, so post-run per-frame reads would alias to whatever the last exchange_state! left resident. ERA5's w ≈ −ω/(ρg); no rain.
k_parent = searchsortedfirst(Array(znodes(parent.grid, Center())), 2000)
constants = child.thermodynamic_constants
pˢᵗ = child.dynamics.standard_pressure
g = constants.gravitational_acceleration
ε = vapor_gas_constant(constants) / dry_air_gas_constant(constants) - 1 # virtual-temperature coefficient
slice(operation, k) = Field(operation, indices = (:, :, k))
function parent_slices(t)
hydrometeors = parent.microphysical_variables
qˡ = hydrometeors.qᶜˡ[Time(t)] + hydrometeors.qʳ[Time(t)] ## total liquid: cloud + rain
qⁱ = hydrometeors.qᶜⁱ[Time(t)] + hydrometeors.qˢ[Time(t)] ## total ice: cloud ice + snow
(; ρ, θˡⁱ, qᵗ) = breeze_prognostic_state(constants, pˢᵗ, parent.temperature[Time(t)],
parent.specific_humidity[Time(t)],
qˡ, qⁱ, parent.pressure)
u, v = parent.velocities.u[Time(t)], parent.velocities.v[Time(t)]
# `u` and `v` are staggered, so |U| would inherit `u`'s location; force it to centers, where the
# other three frames already live, so every parent panel shares one prototype location.
speed = @at((Center, Center, Center), sqrt(u^2 + v^2))
return (θᵛ = slice(θˡⁱ * (1 + ε * qᵗ), 1),
U = slice(speed, 1),
w = slice(-ω_series[Time(t)] / (ρ * g), k_parent),
qᵛ = slice(qᵗ, k_parent))
end
parent_frames = [parent_slices(t) for t in times]One column each: title, colormap, the child/parent 2-D fields as functions of the frame n, and the parent level k those frames are sliced at. nothing parent ⇒ blank panel (rain). Fixed, illustrative color ranges (this is a demo, not a tuned figure); w alone differs ~10× between parent and child, so it carries a range per row.
g_per_kg(field) = 1f3 * field
columns = [(title = "θᵛ′ₛ (K)", colormap = :balance, child_range = (-6, 6), parent_range = (-6, 6),
k = 1, child_series = θᵛ_series,
child = n -> θᵛ_series[n] - θᵛ_series[1], parent = n -> parent_frames[n].θᵛ - parent_frames[1].θᵛ),
(title = "|U|ₛ (m s⁻¹)", colormap = :speed, child_range = (0, 30), parent_range = (0, 30),
k = 1, child_series = U_series,
child = n -> U_series[n], parent = n -> parent_frames[n].U),
(title = "w₂ₖₘ (m s⁻¹)", colormap = :balance, child_range = (-3, 3), parent_range = (-0.3, 0.3),
k = k_parent, child_series = w_series,
child = n -> w_series[n], parent = n -> parent_frames[n].w),
(title = "qᵛ₂ₖₘ (g kg⁻¹)", colormap = :dense, child_range = (0, 15), parent_range = (0, 15),
k = k_parent, child_series = qᵛ_series,
child = n -> g_per_kg(qᵛ_series[n]), parent = n -> g_per_kg(parent_frames[n].qᵛ)),
(title = "qʳ₂ₖₘ (g kg⁻¹)", colormap = :dense, child_range = (0, 2), parent_range = (0, 2),
k = k_parent, child_series = qʳ_series,
child = n -> g_per_kg(qʳ_series[n]), parent = n -> nothing)]
boxλ = [λ_west, λ_east, λ_east, λ_west, λ_west]
boxφ = [φ_south, φ_south, φ_north, φ_north, φ_south]
fig_cascade = Figure(size = (1500, 700))
cascade_n = Observable(1)
# Each panel plots one plain field (`similar(prototype)`: the prototype's location, grid and indices,
# its own data), refilled per frame and handed back as the *same* object. `heatmap!` reads the field's
# own λ/φ and moves it host-side, so no node arrays and no manual materialization. Reusing one object
# matters twice: Makie's compute graph otherwise compares successive plot inputs elementwise, which on
# the parent's GPU fields is scalar indexing, and `heatmap!` calls `compute!` on what it is handed,
# which on a field carrying an operand would overwrite the frame just copied in.
function panel!(ax, prototype, field_of, colormap, colorrange)
panel = similar(prototype)
frame = Observable(panel)
on(nn -> (set!(panel, compute!(field_of(nn))); frame[] = panel), cascade_n)
set!(panel, compute!(field_of(1)))
return heatmap!(ax, frame; colormap, colorrange)
end
Label(fig_cascade[0, 1:5],
@lift(@sprintf("MC3E 20 May 2011 — ERA5 → 12 km Breeze — t = %.1f h", times[$cascade_n] / 3600)),
fontsize = 20, tellwidth = false)
for (i, column) in enumerate(columns)
parent_ax = Axis(fig_cascade[1, i]; title = column.title, aspect = DataAspect())
child_ax = Axis(fig_cascade[2, i]; aspect = DataAspect())
hmc = panel!(child_ax, column.child_series[1], column.child, column.colormap, column.child_range)
if isnothing(column.parent(1))
text!(parent_ax, 0.5, 0.5; text = "no rain", space = :relative, align = (:center, :center), color = :gray)
Colorbar(fig_cascade[3, i], hmc; vertical = false, flipaxis = false, height = 10)
else
parent_prototype = CenterField(parent.grid, indices = (:, :, column.k))
hmp = panel!(parent_ax, parent_prototype, column.parent, column.colormap, column.parent_range)
lines!(parent_ax, boxλ, boxφ; color = :black, linestyle = :dash, linewidth = 1.5)
if column.parent_range == column.child_range
Colorbar(fig_cascade[3, i], hmc; vertical = false, flipaxis = false, height = 10)
else ## w differs ~10× parent-to-child — a colorbar per row
Colorbar(fig_cascade[3, i], hmp; vertical = false, flipaxis = false, height = 10, label = "ERA5")
Colorbar(fig_cascade[4, i], hmc; vertical = false, flipaxis = false, height = 10, label = "12 km")
end
end
hidedecorations!(parent_ax); hidedecorations!(child_ax)
if i == 1
text!(parent_ax, 0.03, 0.97; text = "ERA5", space = :relative, align = (:left, :top), color = :white, fontsize = 15, font = :bold)
text!(child_ax, 0.03, 0.97; text = "Breeze 12 km", space = :relative, align = (:left, :top), color = :white, fontsize = 15, font = :bold)
end
end
CairoMakie.record(fig_cascade, "era5_cascade_2row.mp4", eachindex(times); framerate = 8) do nn
cascade_n[] = nn ## `record` is also exported by CUDA, so qualify it
endSection animation
The vertical structure along the zonal x-z section through the ARM SGP site: wind speed (the nocturnal Great Plains low-level jet near the surface and the upper-level jet aloft), vertical velocity (the convective updrafts and the squall line's mesoscale circulation), and water vapor (the moist tongue feeding the convection). The section slices load back as FieldTimeSeries of 2-D fields on the terrain-following grid, and heatmap! maps them to physical $(λ, z)$ coordinates directly — one @lift per panel is the whole animation machinery.
U_section = FieldTimeSeries(section_filename, "U")
w_section = FieldTimeSeries(section_filename, "w")
qᵛ_section = FieldTimeSeries(section_filename, "qᵛ")
φ_section = φ_centers[j_section]
# Type-erased observables: the per-frame fields' concrete types can differ in hidden
# parameters, which a `@lift`-typed Observable rejects at the second frame.
section_n = Observable(1)
Uₙ = Observable{Any}(U_section[1])
wₙ = Observable{Any}(w_section[1])
qᵛₙ = Observable{Any}(g_per_kg(qᵛ_section[1]))
on(section_n) do n
Uₙ[] = U_section[n]
wₙ[] = w_section[n]
qᵛₙ[] = g_per_kg(qᵛ_section[n])
end
fig_section = Figure(size = (1000, 900))
Label(fig_section[0, 1:2],
@lift(@sprintf("MC3E 20 May 2011 — vertical structure at %.2f°N — t = %.1f h",
φ_section, times[$section_n] / 3600)),
fontsize = 20, tellwidth = false)
ax_U = Axis(fig_section[1, 1]; ylabel = "z (m)", title = "|U| (m s⁻¹)")
ax_w = Axis(fig_section[2, 1]; ylabel = "z (m)", title = "w (m s⁻¹)")
ax_q = Axis(fig_section[3, 1]; ylabel = "z (m)", xlabel = "longitude (°)", title = "qᵛ (g kg⁻¹)")
hm_U = heatmap!(ax_U, Uₙ; colormap = :speed, colorrange = (0, 40))
hm_w = heatmap!(ax_w, wₙ; colormap = :balance, colorrange = (-3, 3))
hm_q = heatmap!(ax_q, qᵛₙ; colormap = :dense, colorrange = (0, 15))
Colorbar(fig_section[1, 2], hm_U)
Colorbar(fig_section[2, 2], hm_w)
Colorbar(fig_section[3, 2], hm_q)
CairoMakie.record(fig_section, "era5_section_xz.mp4", eachindex(times); framerate = 8) do nn
section_n[] = nn
endSurface response
The coupled surface closes the loop. The partition-blended skin temperature Tⁱⁿ — the one surface the atmosphere and the radiation see — changes over the run only where the land fraction lets it: daytime heating plus cooling under the squall line's cold pool and anvil shading over the plains, next to nothing over the prescribed Gulf, and a muted response along the fractional coast. The final bucket saturation shows where the squall line rained. Both load back as 2-D FieldTimeSeries and plot directly.
Tⁱⁿ_series = FieldTimeSeries(land_filename, "Tⁱⁿ")
𝒮_series = FieldTimeSeries(land_filename, "𝒮")
fig_land = Figure(size = (1100, 420))
ax_T = Axis(fig_land[1, 1]; xlabel = "longitude (°)", ylabel = "latitude (°)",
title = "ΔTⁱⁿ over $(prettytime(duration)) (K)")
ax_𝒮 = Axis(fig_land[1, 3]; xlabel = "longitude (°)", title = "final surface saturation 𝒮")
hm_T = heatmap!(ax_T, Tⁱⁿ_series[end] - Tⁱⁿ_series[1]; colormap = :balance, colorrange = (-8, 8))
hm_𝒮 = heatmap!(ax_𝒮, 𝒮_series[end]; colormap = :dense, colorrange = (0, 1))
Colorbar(fig_land[1, 2], hm_T)
Colorbar(fig_land[1, 4], hm_𝒮)
save("era5_breeze_surface_response.png", fig_land)
fig_landThis page was generated using Literate.jl.