Snapshot of top-of-atmosphere outgoing longwave radiation (W m−2) in the Trappist-1e simulation at 102 d: from the global model (a) over the whole planet, (b) zoomed in on the HighRes domain; and (c) from the HighRes simulation. The dark blue box in (a) shows the location of the HighRes domain.
Import the necessary libraries.
import warnings
warnings.filterwarnings("ignore")
Progress bar
from fastprogress import progress_bar
from datetime import datetime, timedelta
Scientific stack
import cartopy.crs as ccrs
import iris
import numpy as np
from matplotlib import gridspec
import matplotlib.pyplot as plt
from aeolus.coord_utils import UM_LATLON
from aeolus.core import Run
from aeolus.plot import GeoAxesGrid, label_global_map_gridlines
from aeolus.region import Region
from aeolus.util import fmt_lonlat, subplot_label_generator
Local modules
from commons import (
DT_FMT,
FCST_DIM_CNSTR,
FCST_PRD_CNSTR,
GLM_RUNID,
NS_COLORS,
NS_MODEL_TYPES,
NS_RUN_ALIASES,
NS_RUNID,
PLANET_ALIASES,
)
import mypaths
from plot_func import use_style, CART_KW
from proc_um_output import process_cubes
Global stylesheet for figures.
use_style()
A few local definitions
planet = "trap1e"
run_key = "grcs"
OUTPUT_NAME_PREFIX = f"{planet}_{run_key}"
Define the region to zoom in to in the figure.
ss_region = Region(-10, 30, -20, 20, "HighRes domain")
extent = [i["value"] for i in ss_region]
Set metadata for the variable.
varname = "toa_outgoing_longwave_flux"
short_name = "TOA OLR"
tex_units = "$W$ $m^{-2}$"
plt_kw = dict(cmap="Greys", vmin=60, vmax=270)
Change file mask to load only the files with TOA radiation data.
NS_MODEL_TYPES["global"]["path"] = (
NS_MODEL_TYPES["global"]["path"].parent / f"{GLM_RUNID}_pd*"
)
NS_MODEL_TYPES["lam"]["path"] = NS_MODEL_TYPES["lam"]["path"].parent / f"{NS_RUNID}_pa*"
Create a dictionary of Run
objects with UM data.
runs = {}
for model_type, model_specs in progress_bar(NS_MODEL_TYPES.items()):
subdir = f"{planet}_{run_key}"
label = f"{planet}_{run_key}_{model_type}"
fpath = mypaths.nsdir / subdir / "*" / model_specs["path"]
# Load data
run = Run(
files=fpath,
name=label,
planet=planet,
model_type=model_type,
timestep=model_specs["timestep"],
)
# Regrid & interpolate data
run.proc_data(
process_cubes,
timestep=run.timestep,
extract_mean=False,
regrid_multi_lev=False,
)
# Select domain
run.proc = run.proc.extract(FCST_PRD_CNSTR)
# Save to dict
runs[label] = run
Extract cubes of TOA OLR along with longitude and latitude from the global and HighRes simulations.
cubes = {}
lats = {}
lons = {}
for model_type in NS_MODEL_TYPES.keys():
cubes[model_type] = runs[f"{planet}_{run_key}_{model_type}"].proc.extract_strict(varname)
lats[model_type] = cubes[model_type].coord(UM_LATLON[0]).points
lons[model_type] = cubes[model_type].coord(UM_LATLON[1]).points
Choose the time slice.
hour0 = cubes["lam"].coord("time").points[0]
FCST_TIME_CNSTR = iris.Constraint(
forecast_reference_time=lambda x: (x.point.day == 28) & (x.point.month == 7)
) # 102 days
ndays = (
cubes["lam"].extract(FCST_TIME_CNSTR).coord("time").points[0]
- hour0
) / 24
ndays
102.0
Set axes tick locations.
xlocs_ss = np.arange(-20, 50, 10)
ylocs_ss = np.arange(-30, 40, 10)
xlocs = np.arange(-180, 181, 60)
ylocs = np.arange(-90, 91, 30)
Set title styles.
ttl_kw = dict(fontsize="small", pad=5, loc="left")
cb_ttl_kw = dict(fontsize="x-small", pad=5)
Assemble the plot.
ncols = 3
nrows = 1
iletters = subplot_label_generator()
fig = plt.figure(figsize=(ncols * 8, nrows * 6),)
gs = gridspec.GridSpec(1, 4)
axs = []
model_type = "global"
ax = fig.add_subplot(gs[:2], projection=ccrs.Robinson())
axs.append(ax)
ax.pcolormesh(
lons[model_type],
lats[model_type],
cubes[model_type].extract(FCST_TIME_CNSTR).data,
**plt_kw,
**CART_KW,
)
ss_region.add_to_ax(
ax, edgecolor=NS_COLORS[run_key]["lam"], facecolor="none", linewidth=5, **CART_KW
)
label_global_map_gridlines(
fig, ax, xlocs[1:-1], ylocs[1:-1], degree=True, size="x-small", xoff=-15
)
ax.gridlines(xlocs=xlocs, ylocs=ylocs, crs=ccrs.PlateCarree())
ax.set_title(
f"{NS_MODEL_TYPES[model_type]['title']} model, full domain ({PLANET_ALIASES[planet]})",
fontsize="medium",
pad=5,
loc="center",
)
ax = fig.add_subplot(gs[2], projection=ccrs.PlateCarree())
axs.append(ax)
ax.pcolormesh(
lons[model_type],
lats[model_type],
cubes[model_type].extract(FCST_TIME_CNSTR).data,
**plt_kw,
**CART_KW,
)
ax.set_title(
f"{NS_MODEL_TYPES[model_type]['title']} model, zoomed in",
fontsize="medium",
pad=5,
loc="center",
)
model_type = "lam"
ax = fig.add_subplot(gs[3], projection=ccrs.PlateCarree())
axs.append(ax)
h = ax.pcolormesh(
lons[model_type],
lats[model_type],
cubes[model_type].extract(FCST_TIME_CNSTR).data,
rasterized=True,
**plt_kw,
**CART_KW,
)
ax.set_title(
f"{NS_MODEL_TYPES[model_type]['title']} model",
fontsize="medium",
pad=5,
loc="center",
)
for ax in fig.axes[1:]:
ax.set_extent(extent)
ax.gridlines(xlocs=xlocs_ss, ylocs=ylocs_ss, crs=ccrs.PlateCarree())
label_global_map_gridlines(
fig, ax, xlocs_ss[1:-1], ylocs_ss[1:-1], degree=True, size="x-small", xoff=-15
)
for ax in fig.axes:
ax.set_title(f"({next(iletters)})", **ttl_kw)
cb = fig.colorbar(h, ax=axs, orientation="vertical", shrink=0.82, pad=0.02)
cb.ax.set_ylabel(f"{short_name} [{tex_units}]")
plt.close() # Show the figure in a separate cell
fig
And save it.
imgname = mypaths.plotdir / f"{planet}__{run_key}__toa_olr_map__{ndays:.0f}d.png"
fig.savefig(imgname, dpi=200)
print(f"Saved to ../{imgname.relative_to(mypaths.topdir)}")
Saved to ../plots/trap1e__grcs__toa_olr_map__102d.png