Skip to content

Add WRF diagnostics accessor plugin#238

Open
decadeneo wants to merge 3 commits intoxarray-contrib:mainfrom
decadeneo:main
Open

Add WRF diagnostics accessor plugin#238
decadeneo wants to merge 3 commits intoxarray-contrib:mainfrom
decadeneo:main

Conversation

@decadeneo
Copy link

@decadeneo decadeneo commented Jan 5, 2026

Pull Request: Add WRF Diagnostics Accessor Plugin

Summary

This PR adds a comprehensive WRF diagnostics accessor plugin that bridges xwrf/xarray with wrf-python's raw computational APIs, providing seamless integration for calculating diagnostic variables from WRF model output.

Features

  • Comprehensive diagnostics: Thermodynamic, dynamic, and surface variables
  • xarray integration: Seamless use via accessor pattern (ds.wrf_diag.*)
  • Automatic variable mapping: Handles WRF variable naming conventions
  • Staggered grid support: Automatic destaggering for mass grid calculations
  • Unit conversions: Built-in unit conversion support (K/°C, Pa/hPa)
  • Dask support: Parallel processing for large datasets

Available Diagnostics

Thermodynamic Variables

  • slp() - Sea level pressure
  • rh() - Relative humidity
  • tk() / tc() - Temperature (Kelvin/Celsius)
  • eth() - Equivalent potential temperature
  • td() - Dewpoint temperature
  • pw() - Precipitable water

Dynamic Variables

  • avo() - Absolute vorticity
  • omega() - Omega (vertical pressure velocity)
  • udhel() - Updraft helicity

Advanced Diagnostics

  • dbz() - Radar reflectivity
  • cape_2d() - CAPE, CIN, LCL, LFC
  • cloudfrac() - Low/mid/high cloud fractions
  • ctt() - Cloud top temperature

Surface Variables (2m and 10m)

  • t2() / t2c() - 2m temperature (K/°C)
  • rh2() - 2m relative humidity
  • td2() - 2m dewpoint temperature
  • q2() - 2m specific humidity
  • psfc() - Surface pressure
  • u10() / v10() - 10m U/V wind components
  • wspd10() - 10m wind speed
  • wdir10() - 10m wind direction

Usage Example

import xarray as xr
import xwrf  # Automatically registers wrf_diag accessor

# Load WRF output
ds = xr.open_dataset("wrfout_d01_2022-07-14_00:00:00")

# Calculate diagnostics
slp = ds.wrf_diag.slp()          # Sea level pressure
rh = ds.wrf_diag.rh()             # Relative humidity
t2 = ds.wrf_diag.t2()             # 2m temperature
rh2 = ds.wrf_diag.rh2()           # 2m relative humidity
wspd10 = ds.wrf_diag.wspd10()     # 10m wind speed
cape = ds.wrf_diag.cape_2d()      # CAPE and CIN (returns Dataset)

Changes

  • Added xwrf/xwrf_diagnostics.py - New module with WRFDiagnosticsAccessor class
  • Modified xwrf/__init__.py - Import xwrf_diagnostics to auto-register accessor

Dependencies

  • Requires wrf-python >= 1.3 (soft dependency, graceful warning if not installed)
  • Maintains compatibility with existing xwrf functionality

Testing

The plugin has been tested with WRF output files and handles:

  • Variable name variations (WRF standard vs CF conventions)
  • Staggered grid variables
  • Missing optional variables
  • Unit conversions
  • Multi-file processing with dask

Notes

  • The accessor is automatically available after importing xwrf
  • All diagnostic methods return xarray DataArrays or Datasets with proper metadata
  • Follows xwrf conventions for variable naming and attributes

decadeneo and others added 3 commits January 5, 2026 11:10
Add xwrf_diagnostics.py module with comprehensive diagnostic calculations
including thermodynamic, dynamic, and surface variables using wrf-python
APIs. The accessor is automatically registered via __init__.py import.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments