Skip to main content

pvtend

PyPI Tests Documentation License: MIT

PV tendency decomposition for atmospheric blocking, propagating anticyclones, and all synoptic-scale cyclonic event lifecycle analysis.

pvtend diagnoses the growth, propagation, and decay of mid-latitude weather events by decomposing potential vorticity (PV) tendencies from ERA5 pressure-level data onto physically meaningful components using an orthogonal basis framework. This is the Part I work of Yan et al. (in prep.) about blocking lifecycle analyses on onset, peak, decay stages.

Idealized six-basis reconstruction
Idealized validation — a Gaussian PV anomaly with prescribed propagation, intensification, and deformation is decomposed into six orthogonal bases and reconstructed with near-zero residual.
Real blocking lifecycle decomposition
Real ERA5 blocking event (track 425) — animated lifecycle showing total PV on a cartopy map (left) and the six projected basis components (right) evolving from 13 h pre-onset to 12 h post-onset. The analysis is done on a weighted average surface across 300, 250, 200 hPa levels.
Geopotential-height lifecycle decomposition
Geopotential-height (Z500) variant of the six-basis decomposition (track 425) — animated lifecycle showing Z anomaly from the 1990–2020 hourly climatology, with adaptive prenorm and blockid contour overlay. See notebook 03z_six_basis_projection_geopotential.

Event catalogues

Blocking and PRP-high events are identified as persistent anticyclonic anomalies in 500 hPa geopotential height. We are using TempestExtremes v2.1 to track contiguous Z500 anomaly features that exceed a fixed threshold for ≥5 days, producing CSV catalogues with columns for event ID, centre lat/lon, onset/peak/decay timestamps, and area. Following the threshold as in Drouard et al. (2021), we separate the tracked features into blocking and propagating (prp) high pressure systems.

Sample catalogue (ERA5, 1990–2020 blocking): ERA5_TempestExtremes_z500_anticyclone_blocking.csv

The CSVs are the inputs for pvtend-pipeline compute, which extracts event-centred patches and runs the full PV-tendency decomposition for each event in the blocking/prp catalogue.

Features

  • Helmholtz-first architecture (v2.0): Helmholtz decomposition on the total wind field; climatological Helmholtz pre-computed as 24 monthly NetCDF files; anomaly Helmholtz = total − clim (no separate anomaly solve)
  • 53 cross-term PV tendency budget: 20 primary + 16 alt-vertical + 16 div dry/moist horizontal + Q_LHR, all written per-timestep to NPZ
  • PV tendency computation: RHS has zonal advection, baroclinic counter propagation, vertical advection, and approximated diabatic heating terms.
  • QG omega solver: Hoskins Q-vector formulation with two methods: LOG20/SIP (default, Numba-accelerated 3-D elliptic, Li & O'Gorman 2020) and SP19 (Steinfeld & Pfahl 2019 empirical 1/3 scaling). Optional center_lat for dynamic f₀.
  • Helmholtz decomposition: Spherical vorticity/divergence (with tan φ/a metric), conservative spherical Poisson solver (FFT in lon + tridiagonal in lat), spectral gradient for wind recovery — all on the full NH grid. Since v2.10 a spherical-harmonic backend (pvtend.sh_ops, via pyspharm) is the default (method="spectral"); legacy FFT path remains as method="fft". NH inputs are parity-mirrored to the global sphere, giving a near-zero harmonic residual.
  • Four-way omega decomposition: ω_dry (QG A+B), ω_qg_moist (term C via ∂T/∂t), ω_emanuel_moist (Emanuel LHR), ω_moist (full residual), with corresponding divergent winds recovered by independent spherical Poisson inversion (verified linear to machine precision)
  • Orthogonal basis decomposition: Projects PV tendency onto intensification (β), propagation (αx, αy), and deformation (γ) modes. Built-in temporal down-scaling (bi-linear interpolation, α = 0.75 by default) from hourly to 15-minute evaluation instants via _next keyword arguments. Single-blob selection: when the threshold mask produces multiple disconnected regions, only the connected component enclosing (or nearest to) the patch centre is retained
  • RWB detection: Two classification methods — bay (path-order, recommended with circumpolar-cropped contours) and tilt (centerline slope ±0.15 dead zone). Circumpolar-first contour extraction for robust NH analysis. Each event-stage is labelled AWB / CWB / Omega (both bays) / NEUTRAL. The single-field public API pvtend.classify.classify_z_field(z2d, x_rel, y_rel) + label_from_flags(...) classifies one 2-D Z patch on any grid; pvtend-pipeline classify --patches <.npz|.nc> classifies a pre-extracted patch stack (e.g. CESM f09) to a label CSV (the NPZ tree → PKL stays the default).
  • Composite lifecycle: Multi-stage ensemble averaging with onset/peak/decay staging
  • NaN-safe throughout: All grid, derivative, solver, bootstrap, and plotting routines use nanmean/nanpercentile to handle partial-NaN edge events without corrupting composites or flipping projection signs
  • ω blowup detection (v2.10.8): Per-event NPZ scan via scripts/aggregate_qg_blowup.py. Each event NPZ embeds max_abs_w_{adiabatic,diabatic,qg_diabatic,lhr_moist}_300 scalars; tracks whose any-stage max exceeds 25 Pa/s are flagged. Raw ERA5 ω is observationally bounded (1990-2020 hourly: max=22.4, 99.9th=19.9 Pa/s) so only the QG-solver output ever blows up. Replaces both the silent in-solver ±5 Pa/s clip used in pvtend ≤ 2.9 and the v2.10.1–7 raw-ERA5 glob scan.
  • Per-level piecewise PV inversion (PPVI): Wu/Davis nonlinear-balance inversion (f2py _wuppvi cores: pvpialln → qinvert21 → qinvertp21) decomposing the balanced rotational-wind anomaly into the contribution induced by each pressure level's PV/θ anomaly across 9 levels 1000→100 hPa (the 1000 hPa bottom-θ and 100 hPa top-θ pieces are Bretherton boundary sheets). Per-event NPZ keys u/v_rot_anom_ppvi_{L}(_3d) for L ∈ {1000,…,100}, plus u/v_rot_anom_residual_ppvi and pv_anom_wu. The 9 single-level pieces sum exactly to the full balanced field (linear perturbation balance). Enabled by default in compute (--with-ppvi); migrate existing NPZ with the ppvi subcommand. See the ppvi skill. Grid-agnostic (v2.13): invert_piecewise runs on any regular grid including anisotropic ones (Δlat≠Δlon, e.g. CESM f09 — the zhdr spacings are reordered internally to the Fortran's HDR(5)=Δlon/HDR(6)=Δlat convention) and hydrostatically gap-fills below-ground NaN (fill_below_ground); the ERA5 isotropic path stays byte-identical. The GridProfile config (ERA5_1P5_NH default, CESM_F09) carries the grid + inversion-band metadata.
  • CLI pipeline: End-to-end processing via pvtend-pipeline command (compute, clim-helmholtz, classify, composite, decompose, blowup-scan, ppvi)

Installation

# From PyPI
pip install pvtend

# Or with uv (fast, Rust-based installer)
uv pip install pvtend

# From source (development)
git clone https://github.com/yanxingjianken/pvtend.git
cd pvtend
pip install -e ".[dev]"

# With micromamba
micromamba create -f environment.yml
micromamba activate pvtend_env
pip install -e ".[dev]"

The Helmholtz / QG-ω velocity-potential / mixed-second-derivative operators default to a spherical-harmonic backend (pvtend.sh_ops, built on pyspharm / windspharm). These two packages compile Fortran code at install time, so they are kept as an optional extra:

# conda-forge ships pre-built wheels (recommended)
micromamba install -c conda-forge windspharm pyspharm

# Or via pip with numpy already installed and a Fortran compiler:
pip install --no-build-isolation pyspharm windspharm

With these installed, method="spectral" (the default) is used. Without them, callers fall back to the legacy FFT path or raise a clear error directing the user to install the SH extras.

Quick Start

import numpy as np
from pvtend import NHGrid, ddx, ddy, compute_orthogonal_basis, project_field

# Grid setup
grid = NHGrid(lat=np.linspace(90, 0, 61), lon=np.linspace(-180, 178.5, 240))
dx_arr = grid.dx_arr  # zonal spacing per latitude [m]
dy = grid.dy           # meridional spacing [m]

# Compute zonal derivative
dfdx = ddx(field, dx_arr, periodic=False)

# Orthogonal basis decomposition
basis = compute_orthogonal_basis(pv_anom, pv_dx, pv_dy, x_rel, y_rel)
result = project_field(tendency, basis)
print(f"β = {result['beta']:.3e}")  # intensification rate

CLI Pipeline

# Step 0a: Pre-compute Helmholtz climatology (once, ~5 min)
pvtend-pipeline clim-helmholtz \
    --clim-dir /data/climatology/ \
    --out-dir /data/climatology/

# Step 1: Compute PV tendencies → per-event NPZ files
pvtend-pipeline compute \
    --event-type blocking \
    --events-csv events.csv \
    --era5-dir /data/era5/ \
    --clim-path /data/climatology/era5_hourly_clim.nc \
    --clim-helmholtz-dir /data/climatology/ \
    --out-dir /data/composite_blocking_tempest/ \
    --dh-range=-49:25 --skip-existing

# Step 2: RWB classification → variant tracksets PKL
#   --levels accepts integer hPa values or 'wavg' (weighted-average Z)
pvtend-pipeline classify \
    --npz-dir /data/composite_blocking_tempest/ \
    --output /data/outputs/rwb_variant_tracksets.pkl \
    --stages onset peak decay \
    --levels 500 400 300 200 --threshold 3

# Step 3: Variant-aware composite accumulation → composite PKL
pvtend-pipeline composite \
    --npz-dir /data/composite_blocking_tempest/ \
    --rwb-pkl /data/outputs/rwb_variant_tracksets.pkl \
    --pkl-out /data/outputs/composite.pkl

# Step 4 (optional): Orthogonal-basis decomposition
pvtend-pipeline decompose \
    --pkl-in /data/outputs/composite.pkl \
    --out-dir /data/outputs/decomp/

Workflow

graph TD
    A[ERA5 Monthly NetCDF] --> B[pvtend.preprocessing]
    B --> C[Regridded NH Grid]
    C --> D[pvtend.climatology]
    D --> E[Monthly Climatology]
    E --> E2[pvtend.climatology — clim-helmholtz]
    E2 --> E3[24 Helmholtz Clim NetCDF]
    C & E & E3 --> F[pvtend.tendency.TendencyComputer]
    F --> G[PV Tendency Terms]
    F --> I[pvtend.helmholtz — Helmholtz on total wind]
    I --> I2[u_rot, u_div, v_rot, v_div]
    I2 & E3 --> I3[Anomaly Helmholtz = total − clim]
    G --> H[pvtend.omega — QG ω solver]
    H & I2 --> J[pvtend.moist_dry — ω splitting + 4 independent Poisson inversions]
    G & J & I3 --> K[Per-event NPZ patches — 53 cross-terms]
    K --> L1[pvtend.classify — RWB Pass 1]
    L1 --> L1a[rwb_variant_tracksets.pkl]
    K & L1a --> L2[pvtend.composite_builder — Pass 2]
    L2 --> L2a[composite.pkl]
    L2a --> W1[website/export_composite_web.py]
    L2a --> W2[website/build_and_export_clusters.py]
    W1 --> W3[blocking_export and prp_export JSON.gz]
    W2 --> W3
    W3 --> W4[blocking-plots viewer with contour and arrow overlays]
    L2a --> M[pvtend.decomposition — Orthogonal basis]
    M --> N[β, αx, αy, γ coefficients]
    N --> O[pvtend.plotting — Publication figures]

Website Export

The repository also contains a lightweight website export pipeline for the blocking/PRP composite viewer. The JSON exports under website/blocking_export/ and website/prp_export/ are built from the latest per-event NPZ patches, RWB trackset pickles, and blowup-exclusion CSVs. The exports include grouped field metadata, basis payloads, and vector-overlay definitions so the viewer can switch between scalar contours and wind-arrow overlays.

website/build_and_export_clusters.py prefers rwb_variant_tracksets_wavg.pkl and applies outputs/blowup_scan/exclude_tracks_{event_type}.csv by default when the file exists. This keeps the web viewer's All Events count and fields consistent with the screened production composites and avoids uploading composites contaminated by QG-omega blowup tracks. The clustered export also writes parent total variants (awb, cwb, and rwb) for all events with anticyclonic, cyclonic, or either type of wave breaking, alongside the regional sub-clusters. website/upload_to_hf.py --clean-figures uploads the refreshed blocking/ and prp/ JSON trees, removes stale remote JSONs, deletes the old Hugging Face figures/ folder, and uploads website/README.md as the dataset card.

cd /net/flood/data2/users/x_yan/pvtend
micromamba run -n blocking python website/build_and_export_clusters.py --event-type blocking
micromamba run -n blocking python website/build_and_export_clusters.py --event-type prp
micromamba run -n blocking python website/upload_to_hf.py --clean-figures
graph TD
    A[outputs/blocking and outputs/prp NPZ patches] --> B[outputs/blowup_scan exclude CSVs]
    A --> C[rwb_variant_tracksets_wavg.pkl]
    B --> D[website/build_and_export_clusters.py]
    C --> D
    A --> D
    D --> E[website/blocking_export JSON.gz with total and clustered variants]
    D --> F[website/prp_export JSON.gz with total and clustered variants]
    E --> G[website/upload_to_hf.py --clean-figures]
    F --> G
    G --> H[Hugging Face dataset blocking-composites]
    H --> I[blocking-plots viewer]

Publication Figures

The paper/generals_paper_1/scripts/ directory contains the current paper Figure 5-8 generation workflow. Shared budget definitions live in _paper_budget.py, which centralizes the Eq. 11 term mapping, the pressure-weighted wavg level, the q'<0 projection basis, p99.9 track-exclusion lists, and the Figure 7 bootstrap cache location.

  • fig5_beta_closure_qg_onset_wavg.py renders the blocking-onset raw PV-tendency closure and corresponding beta*Phi_1 projections in two four-column blocks. The stationary-flow and baroclinic advection terms are split into separate columns, with term subtitles, panel-specific colorbars, a shared range for the six process-projection colorbars, total-PV contours on the LHS panel, and wind arrows on the other raw-term panels.
  • fig6_beta_stacked_qg_wavg.py renders the wavg-only onset lifecycle stacked-bar budget for beta, with the direct partial q / partial t projection overlaid as a black step curve and colors matched to examples/05_stacked_bar_beta.ipynb cell 14.
  • fig7_ax_bootstrap_blocking_vs_prp_qg_wavg.py renders peak-stage blocking versus propagating-anticyclone alpha_x bootstrap bars from event NPZs after excluding p99.9 blowup tracks. Projections use the full event fields without a pre-projection significance mask, the pv_dt bars include simple mean-value labels, and repeated runs reuse paper/generals_paper_1/scripts/cache/ when the inventory and settings match.
  • fig8_gamma_rwb_awb_cwb_onset_wavg.py renders AWB/CWB onset raw maps and -gamma_1*Phi_4 - gamma_2*Phi_5 deformation projections for four selected Eq. 11 terms. It uses QG-diabatic paper definitions, one colorbar per panel, and Figure-2-style arrows oriented along the negative PV-tendency dipoles of the blocking anomaly.

All four scripts write PNG and PDF files into paper/generals_paper_1/figures/, and paper/generals_paper_1/main.tex includes the generated PNGs.

graph TD
    A[outputs/blocking/composite_blocking.pkl] --> B[_paper_budget.py]
    B --> C[fig5_beta_closure_qg_onset_wavg.py]
    B --> D[fig6_beta_stacked_qg_wavg.py]
    B --> M[fig8_gamma_rwb_awb_cwb_onset_wavg.py]
    E[outputs/blocking and outputs/prp event NPZs] --> B
    F[p99.9 exclude CSVs] --> B
    B --> G[fig7_ax_bootstrap_blocking_vs_prp_qg_wavg.py]
    G --> H[scripts/cache/bootstrap NPZ]
    C --> I[figures/fig5_beta_closure_qg_onset_wavg PNG/PDF]
    D --> J[figures/fig6_beta_stacked_qg_wavg PNG/PDF]
    G --> K[figures/fig7_ax_bootstrap_blocking_vs_prp_qg_wavg PNG/PDF]
    M --> N[figures/fig8_gamma_rwb_awb_cwb_onset_wavg PNG/PDF]
    I & J & K & N --> L[paper/generals_paper_1/main.tex]

Package Structure

src/pvtend/
├── __init__.py          # Public API
├── _version.py          # Version
├── cli.py               # CLI entry point (clim-helmholtz, compute, classify, composite, decompose)
├── constants.py         # Physical constants
├── grid.py              # NH grid & event patches
├── preprocessing.py     # ERA5 loading & regridding
├── derivatives.py       # Finite difference operators
├── climatology.py       # Fourier-filtered climatology + Helmholtz climatology (compute/load)
├── omega.py             # QG omega solver (LOG20/SIP or SP19)
├── helmholtz.py         # Helmholtz decomposition (spherical Poisson + spectral gradient + laplacian_spherical_fft)
├── moist_dry.py         # Moist/dry omega split & independent Poisson wind recovery (solve_chi_from_omega, verify_div_additivity)
├── isentropic.py        # Isentropic PV-tendency diagnostics
├── tendency.py          # Main pipeline: Helmholtz-first, 53 cross-terms, data loading, derivatives, NPZ output
├── classify.py          # RWB classification Pass 1 (AWB/CWB/Omega/NEUTRAL → variant PKL; classify_z_field single-field API)
├── composite_builder.py # Variant-aware composite accumulation Pass 2
├── rwb.py               # RWB detection (bay & tilt methods, circumpolar-first)
├── composites.py        # Legacy composite lifecycle
├── data/                # Bundled sample data
│   ├── __init__.py      # load_idealized_pv() loader
│   └── idealized_pv.npz # Synthetic Gaussian PV evolution
├── decomposition/       # Orthogonal six-basis framework
│   ├── __init__.py
│   ├── smoothing.py
│   ├── basis.py
│   ├── interpolation.py # Temporal bi-linear interpolation (lerp_fields)
│   └── projection.py
├── plotting/            # Visualization
│   ├── __init__.py
│   ├── basis_plots.py
│   ├── coefficient_plots.py
│   ├── field_plots.py
│   ├── composite_explorer.py  # plot_var: single-variable composite explorer with bootstrap
│   └── baroclinic.py          # plot_baroclinic_tilt: two-level v′ overlay
└── io/                  # File I/O
    ├── __init__.py
    ├── era5.py
    ├── npz.py
    └── pkl.py

website/
├── export_composite_web.py   # JSON.gz export for the blocking/PRP web viewer
├── build_and_export_clusters.py # Cluster-aware export and diagnostics generation
├── upload_to_hf.py           # Sync local website exports to Hugging Face
├── blocking_export/          # Exported blocking viewer payloads
├── prp_export/               # Exported PRP viewer payloads
└── cluster_diagnostics/      # Cluster composite diagnostics used for QA

Example Notebooks

Notebooks using real ERA5 blocking event data from the composite_blocking_tempest, composite_prp_tempest (single event npz), tempest_extreme_4_basis/outputs, and tempest_extreme_4_basis/outputs_prp (composite pkl) pipeline:

Notebook Description
00_idealized_6basis Idealized Gaussian PV anomaly: prescribed β/αx/αy/γ₁/γ₂/σ at two timesteps, 6-basis visualisation, Gram-Schmidt, projection & reconstruction
00_idealized_5basis Idealized single negative Gaussian PV anomaly matching paper Figure 3: prescribed β/αx/αy/γ₁/γ₂, 5-basis visualisation, projection & reconstruction
01_rwb_and_derivatives Grid setup, ddx/ddy/ddp derivatives, RWB detection on a real event
02_helmholtz_and_qg_omega 3-D Helmholtz decomposition, QG omega (LOG20 vs SP19), moist/dry ω split
03_six_basis_projection Orthogonal 6-basis (Φ₁–Φ₆), project dq'/dt → β/αx/αy/γ₁/γ₂/σ, lifecycle curves
03_six_basis_projection_composite ↳ Composite variant: 6-basis projection averaged across multiple events
03c_six_basis_cyclone ↳ Cyclone variant: 6-basis projection for a 300 hPa cyclone (PV > 0), lifecycle + budget closure
03prp_six_basis_anticyclone_timed_bases ↳ Anticyclone variant: 6-basis projection for a 300 hPa anticyclone (PV < 0, mask="< -2e-7"), current-time basis
03z_six_basis_projection_geopotential ↳ Supplement: same 6-basis projection using geopotential height Z instead of PV
04_single_var_composite Single-variable composite explorer on pressure levels using pvtend.plotting.plot_var
04i_single_var_isentropic_composite ↳ Supplement: same as 04 but on isentropic (θ) surfaces
05_stacked_bar_beta Stacked-bar β decomposition by PV-tendency term across lifecycle hours
05b_grouped_terms_bootstrap ↳ Supplement: grouped PV-tendency terms with bootstrap resampling & significance
06_baroclinic_structure 3-D composite PV anomaly, lon–p cross-sections, 2-PVU tropopause, v′ tilt via plot_baroclinic_tilt
07_facet_blocking_vs_prp Facet comparison of blocking vs PRP: bar charts with bootstrap significance, shared-cbar spatial maps, baroclinic tilt

Testing

pytest tests/ -v

Documentation

Full documentation at pvtend.readthedocs.io.

Build locally:

cd docs && make html

Citation

If you use this package in your research, please cite:

@software{yan2025pvtend,
  author = {Yan, Xingjian and Tamarin-Brodsky, Talia},
  title = {pvtend: PV tendency decomposition for atmospheric blocking},
  year = {2025},
  url = {https://github.com/yanxingjianken/pvtend}
}

License

MIT — see LICENSE.

Metadata

Release files for pvtend 2.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pvtend 2.14.0
File Size Uploaded Provenance Actions
pvtend-2.14.0.tar.gz 560.4 kB Without provenance Details for pvtend-2.14.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pvtend 2.14.0
File Interpreter ABI Platform Actions
pvtend-2.14.0-py3-none-any.whl Python 3 none any Details for pvtend-2.14.0-py3-none-any.whl

Total release size: 1.1 MB

Release files / pvtend-2.14.0.tar.gz

Download URL pvtend-2.14.0.tar.gz
Size 560.4 kB
Tags Source
SHA-256 checksum
How to use checksums
13275233a5eb7e434d26691d229372237bc0e137578798e7cdc3a81a150c81b5
BLAKE2b-256 checksum
How to use checksums
1d59572edc92690ab5dc74a63f4c578b527db34f6d1c957774e89ba65e07b9e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pvtend-2.14.0-py3-none-any.whl

Download URL pvtend-2.14.0-py3-none-any.whl
Size 546.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
006852988bdbe9568b7065bcd03cd2bf45e67828543e514fd99364b9b670261e
BLAKE2b-256 checksum
How to use checksums
f7b6b0d8a90b80157fcf668e5efc878ec41ff17cd85faeab0a9ac5e3c5f39f89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for pvtend 2.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.14.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page