TN01 Three-Dimensional Wave Activity Flux

easyclimate.calc_TN_wave_activity_3D_flux() calculates the zonal, meridional and upward components of stationary TN01 wave activity flux together. A pressure-level map combines horizontal vectors with vertical-flux shading; a longitude–height section then shows zonal and vertical propagation.

The ERA5 sample data contains February 2025 height anomalies and the February 1991–2020 basic-state winds and temperature. Height anomalies are already in metres and temperature is in kelvin.

Only the four required fields and a buffered domain are stored. The sample retains native grid spacing: 25 pressure levels, 67 Gaussian latitudes and 320 global longitudes. Derivatives are calculated before any interpolation for plotting. The supplied ERA5 winds approximate the geostrophic basic state assumed by TN01.

import cartopy.crs as ccrs
import easyclimate as ecl
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import xarray as xr

Load the local data and calculate every component

Keep all neighbouring levels and horizontal points until the calculation has finished. The longitudes are global, uniform, and have no repeated endpoint, so cyclic differences are enabled. Regional grids use cyclic_lon=False. The default 1 m/s wind cutoff follows the Fortran reference; set min_westerly=5.0 for the monthly NCL mask, or None to disable it.

sample = ecl.open_tutorial_dataset("tn_waf_era5_202502_sample")
sample
/home/docs/checkouts/easyclimate/checkouts/latest/src/easyclimate/core/tutorial.py:358: UserWarning: Tutorial dataset checksum for 'tn_waf_era5_202502_sample.nc' is not recorded in tutorial_data.toml; fetching 'https://github.com/easyatmos/easyclimate-tutorial/raw/main/tn_waf_era5_202502_sample.md5'. Run `python scripts/update_tutorial_config.py` to update the local tutorial dataset registry.
  known_hash = _get_known_hash(path, url, cache_dir)
tn_waf_era5_202502_sample.nc ━━━━━━━━━━ 100.0% | 7.8/7.8   | 77.1 MB/s | 0:00:00
                                                 MB
<xarray.Dataset> Size: 11MB
Dimensions:  (time: 1, level: 25, lat: 67, lon: 320)
Coordinates:
  * time     (time) datetime64[ns] 8B 2025-02-01
  * level    (level) float64 200B 70.0 100.0 125.0 150.0 ... 875.0 900.0 925.0
  * lat      (lat) float64 536B 10.65 11.78 12.9 14.02 ... 82.43 83.55 84.67
  * lon      (lon) float64 3kB 0.0 1.125 2.25 3.375 ... 355.5 356.6 357.8 358.9
Data variables:
    z_prime  (time, level, lat, lon) float64 4MB ...
    u_basic  (time, level, lat, lon) float32 2MB ...
    v_basic  (time, level, lat, lon) float32 2MB ...
    t_basic  (time, level, lat, lon) float32 2MB ...
Attributes:
    title:                    ERA5 TN01 example inputs with native grid spacing
    target_month:             2025-02
    basic_state:              February climatology, 1991-2020
    source:                   User-supplied ERA5 monthly fields remapped to a...
    geopotential_conversion:  z_prime=(target_geopotential-basic_geopotential...
    sampling:                 Native 1.125-degree global longitudes and Gauss...
    purpose:                  Four required input fields. Pressure and latitu...
    winds:                    Provided ERA5 basic-state winds; no geostrophic...


Configure scientific notation for the contour-plot colorbars.

formatter = ticker.ScalarFormatter(useMathText=True, useOffset=True)
formatter.set_powerlimits((0, 0))
flux_3d = ecl.calc_TN_wave_activity_3D_flux(
    z_prime_data=sample.z_prime,
    u_climatology_data=sample.u_basic,
    v_climatology_data=sample.v_basic,
    temper_climatology_data=sample.t_basic,
    temper_climatology_data_units = "degK",
    vertical_dim="level",
    vertical_dim_units="hPa",
    cyclic_lon=True,
    min_westerly=1.0,
    min_latitude=10.0,
    output_dtype="float64",
)
flux_3d
<xarray.Dataset> Size: 21MB
Dimensions:  (time: 1, level: 25, lat: 67, lon: 320)
Coordinates:
  * time     (time) datetime64[ns] 8B 2025-02-01
  * level    (level) float64 200B 70.0 100.0 125.0 150.0 ... 875.0 900.0 925.0
  * lat      (lat) float64 536B 10.65 11.78 12.9 14.02 ... 82.43 83.55 84.67
  * lon      (lon) float64 3kB 0.0 1.125 2.25 3.375 ... 355.5 356.6 357.8 358.9
Data variables:
    psi_p    (time, level, lat, lon) float64 4MB 2.539e+07 ... 5.834e+05
    fz       (time, level, lat, lon) float64 4MB 0.0007387 nan nan ... nan nan
    N2       (time, level, lat, lon) float64 4MB 0.0002553 ... 0.0003943
    fx       (time, level, lat, lon) float64 4MB 0.7236 nan nan ... nan nan nan
    fy       (time, level, lat, lon) float64 4MB -1.4 nan nan ... nan nan nan
Attributes:
    title:                   Takaya and Nakamura three-dimensional wave activ...
    reference:               Takaya and Nakamura (2001), equation (38); Nishi...
    vertical_coordinate:     z = -scale_height * log(p / p_0)
    scale_height:            8000.0
    reference_pressure_hPa:  1000.0


fx, fy and fz are all in m²/s². fz is positive upward in log-pressure height, not in pressure coordinates. psi_p and N2 are also returned. All intermediate operations use float64; set output_dtype="float32" if single-precision output is sufficient.

The three-dimensional function uses the same vertical expression as easyclimate.calc_TN_wave_activity_vertical_flux(). Its horizontal differences correspond to the horizontal function with finite_difference="ncl" and the same cyclic-longitude choice. Default weak/easterly-wind and tropical masks apply to the three flux components; nonpositive stability only masks fz.

Horizontal and vertical propagation at 250 hPa

Literature examples combine horizontal-flux arrows with perturbation contours and upward-flux shading (e.g. Nishii and Nakamura, 2004, Figure 2). Here all fields are shown at 250 hPa: shading is fz, contours are psi_p in millions of m²/s, and arrows are (fx, fy).

Scalar shading stays on the native grid. For evenly placed arrows, interpolate the already calculated horizontal flux onto a regular display grid. Do not interpolate or thin the inputs before differentiating. White cells remain where the flux is undefined or masked; they are not replaced by zeros.

pressure_level = flux_3d.isel(time=0, drop=True).sel(level=250)
shading = ecl.plot.add_lon_cyclic(
    pressure_level.fz, inter=float(sample.lon.diff("lon").isel(lon=0))
)
psi_contours = ecl.plot.add_lon_cyclic(
    pressure_level.psi_p / 1e6, inter=float(sample.lon.diff("lon").isel(lon=0))
)
vectors = pressure_level[["fx", "fy"]].interp(
    lon=np.arange(0, 360, 10), lat=np.arange(20, 81, 5)
)
fig, ax = plt.subplots(
    figsize=(9, 4),
    subplot_kw={"projection": ccrs.Mercator(central_longitude=180)},
    layout="constrained",
)
ecl.plot.set_geoextent([0, 360, 20, 80], ax=ax)
ax.coastlines(linewidth=0.6)
ax.gridlines(draw_labels=["bottom", "left"], alpha=0.3)
shading.plot.contourf(
    ax=ax,
    levels = np.linspace(-0.05, 0.05, 21),
    cmap="RdBu_r",
    extend="both",
    transform=ccrs.PlateCarree(),
    cbar_kwargs={
        "label": r"Upward WAF $F_z$ (m$^2$ s$^{-2}$)",
        "orientation": "horizontal",
        "pad": 0.09,
        "aspect": 60,
        "shrink": 0.8,
    },
)
psi_contours.plot.contour(
    ax=ax,
    x="lon",
    y="lat",
    levels=[-12, -8, -4, 4, 8, 12],
    colors="grey",
    transform=ccrs.PlateCarree(),
)
arrows = vectors.plot.quiver(
    ax=ax,
    x="lon", y="lat", u="fx", v="fy",
    transform=ccrs.PlateCarree(),
    scale=300,
    width=0.004,
    pivot="middle",
    add_guide=False,
)
ax.quiverkey(
    arrows,
    0.9, 1.04,
    10, "10 m$^2$ s$^{-2}$",
    coordinates="axes"
)
ax.set_title("TN01 WAF at 250 hPa: February 2025", size = 16, pad=25)
TN01 WAF at 250 hPa: February 2025
Text(0.5, 1.0, 'TN01 WAF at 250 hPa: February 2025')

Zonal and vertical propagation on a uniform display grid

Extract a latitude section after the full calculation. The pressure levels are irregular, and a log-pressure axis makes even pressure increments look uneven. Interpolate the flux in log(p), not pressure, so the arrow rows are evenly spaced on the displayed log-pressure axis. Longitude positions are also regularly spaced. This interpolation only affects the plotted arrows. The scalar shading below retains the original grid.

angles="uv" expresses directions in display coordinates: positive fz points upward even though pressure increases downward. Using angles="xy" with raw fz on a pressure axis would give the wrong coordinate interpretation. For legibility fz is multiplied by an explicitly stated factor of 100 only in the quiver dataset; the calculated fz and its units remain unchanged. The reference arrow states the equivalent horizontal and vertical magnitudes.

section = flux_3d.isel(time=0, drop=True).sel(lat=35, method="nearest")
section_latitude = section.lat
shaded_section_vertical = section.sel(level=slice(100, 850))
pressure = np.geomspace(850, 100, 12)

vectors_vertical = (
    section[["fx", "fz"]]
    .assign_coords(level=np.log(section.level.values))
    .interp(level=np.log(pressure), lon=np.linspace(0, 360, 41))
    .assign_coords(level=pressure)
)
vectors_vertical["fz_display"] = vectors_vertical.fz * 100
vectors_vertical
<xarray.Dataset> Size: 12kB
Dimensions:     (level: 12, lon: 41)
Coordinates:
  * level       (level) float64 96B 850.0 699.7 576.0 ... 147.6 121.5 100.0
  * lon         (lon) float64 328B 0.0 9.0 18.0 27.0 ... 333.0 342.0 351.0 360.0
    lat         float64 8B 35.33
Data variables:
    fx          (level, lon) float64 4kB -2.568 1.741 10.94 ... 0.5008 1.081 nan
    fz          (level, lon) float64 4kB -0.01725 0.1401 ... -0.004719 nan
    fz_display  (level, lon) float64 4kB -1.725 14.01 7.488 ... -0.4719 nan
Attributes:
    title:                   Takaya and Nakamura three-dimensional wave activ...
    reference:               Takaya and Nakamura (2001), equation (38); Nishi...
    vertical_coordinate:     z = -scale_height * log(p / p_0)
    scale_height:            8000.0
    reference_pressure_hPa:  1000.0


fig, ax = plt.subplots(figsize=(10, 5), layout="constrained")

(shaded_section_vertical.psi_p).plot.contourf(
    ax=ax,
    x="lon",
    y="level",
    levels=np.linspace(-2e7, 2e7, 21),
    cmap="RdBu_r",
    extend="both",
    cbar_kwargs={
        "label": r"Streamfunction anomaly (m$^2$ s$^{-1}$)",
        "pad": 0.03,
        "format": formatter
    },
)

arrows = vectors_vertical.plot.quiver(
    ax=ax,
    x="lon", y="level", u="fx", v="fz_display",
    angles="uv",
    scale=200,
    width=0.003,
    pivot="middle",
    add_guide=False,
)
ax.quiverkey(
    arrows,
    0.72, 1.035,
    5, "$F_x=5$ or $F_z=0.05$ m$^2$ s$^{-2}$",
    coordinates="axes",
    labelpos="E",
    fontproperties={"size": 12},
)

ecl.plot.set_p_format_axis(ax=ax, axis="y", axis_limits=(850, 100), ticker_step=100)
ecl.plot.set_lon_format_axis(ax = ax, axis = "x")

ax.set_xlim(0, 360)
ax.set_xticks(np.arange(0, 361, 60))
ax.set_xlabel("Longitude (degrees east)")
ax.set_ylabel("Pressure (hPa)")
ax.set_title(
    f"TN01 zonal–vertical WAF at {section_latitude:.1f}°N (vertical arrows ×100)",
    pad=40, size = 16
)
TN01 zonal–vertical WAF at 35.3°N (vertical arrows ×100)
Text(0.5, 1.0, 'TN01 zonal–vertical WAF at 35.3°N (vertical arrows ×100)')

Total running time of the script: (0 minutes 9.147 seconds)