Skip to main content

Rust-powered drop-in replacement for MetPy -- 150/150 calc functions plus 36 extras, 10-93000x faster

Project description

metrust

Drop-in replacement for MetPy's calculation layer, powered by Rust.

150/150 metpy.calc functions implemented natively, plus 36 extras. 6-30x faster on real-world workflows. Verified against MetPy on SounderPy, MetPy Cookbook examples, and synthetic global grids.

# The only change: swap the import
from metrust.calc import cape_cin, potential_temperature, vorticity
from metrust.units import units

Installation

pip install metrust

For plotting, xarray accessor, or Level2File (forwarded to MetPy):

pip install metrust metpy

What It Does

metrust implements every function in metpy.calc with a Rust backend compiled via PyO3. The Python API matches MetPy's signatures, units, and return types:

import numpy as np
from metrust.calc import (
    cape_cin, parcel_profile, bunkers_storm_motion,
    storm_relative_helicity, significant_tornado_parameter,
    vorticity, divergence, advection,
)
from metrust.units import units

# Sounding analysis (same API as MetPy)
p = np.array([1000, 925, 850, 700, 500, 300]) * units.hPa
T = np.array([25, 20, 15, 5, -15, -40]) * units.degC
Td = np.array([20, 15, 10, -5, -25, -50]) * units.degC

prof = parcel_profile(p, T[0], Td[0])
cape, cin = cape_cin(p, T, Td, prof)  # MetPy parcel_profile form works

# Grid kinematics with xarray (dx/dy inferred from lat/lon coords)
vort = vorticity(u_xarray, v_xarray)  # spherical metric corrections included
div = divergence(u_xarray, v_xarray)

Speed

Benchmarked on real-world workflows (v0.3.3, validated by Codex against MetPy):

Workflow Speedup Notes
MetPy Cookbook sounding analysis 6.0x Full severe weather stack
MetPy Cookbook 500 hPa grid 6.1x Vorticity, smoothing, advection
MetPy Cookbook Q-vectors 6.1x Q-vector divergence
SounderPy compute-heavy subset 29.7x Thermo + wind + severe params
MetPy isentropic example 2.3x Isentropic interpolation + Montgomery
Vorticity/divergence (global grid) 2.3x Spherical corrections on 721x1440

Array operations on 1M elements (32-core Ryzen, rayon parallel):

Function Time Throughput
potential_temperature 1.8 ms 550 M/s
wet_bulb_temperature 7.3 ms 137 M/s
wind_speed 1.5 ms 660 M/s

Numerical Parity

Verified on the MetPy OUN 2011-05-22 12Z test sounding:

Metric Difference from MetPy
CAPE +4.0 J/kg
MUCAPE +7.6 J/kg
SRH (0-1 km) +0.3 m^2/s^2
Critical angle +0.2 deg
Bunkers RM +0.02 m/s
STP +0.01
Montgomery streamfunction corr 1.0000
Isentropic pressure 7e-13 hPa diff
Vorticity (global lat/lon) corr 1.0000

Uses MetPy-exact physical constants (Rd, Cp, Lv, epsilon), MetPy's CAPE integration formula (g * dTv/Tv * dz), pressure-weighted Bunkers algorithm, Newton solver for isentropic interpolation, and spherical metric tensor corrections for lat/lon grid kinematics.

Coverage

  • 150/150 metpy.calc functions (100% coverage)
  • 36 extras not in MetPy (grid composites, fire weather indices, etc.)
  • 28 Rust array bindings with rayon parallelism and GIL release
  • Pint application registry shared with MetPy (no cross-registry errors)
  • xarray support with coordinate inference and shape preservation

What's Not Native

These forward to MetPy when installed:

  • metrust.plots (matplotlib-based plotting)
  • metrust.xarray (xarray accessor)
  • metrust.io.Level2File (NEXRAD Level II)

Core metrust.calc is 100% native Rust with no MetPy dependency.

Examples

See examples/ for complete drop-in demos:

  • cookbook_sounding.py — MetPy Cookbook sounding analysis
  • cookbook_500hpa_grid.py — MetPy Cookbook 500 hPa vorticity advection
  • sounderpy_dropin.py — SounderPy-style full sounding pipeline

Testing

cargo test --workspace          # 1,186 Rust tests
python -m pytest tests/ -q      # 20 Python tests (including MetPy drop-in regression)

Documentation

Full docs at fahrenheitresearch.github.io/metrust-py, including:

  • API reference for all 186 functions
  • Beginner tutorials (Weather 101, soundings, grids, recipes)
  • Migration guide from MetPy
  • Performance benchmarks

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metrust-0.3.4.tar.gz (621.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

metrust-0.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

metrust-0.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

metrust-0.3.4-cp312-cp312-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.12Windows x86-64

metrust-0.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

metrust-0.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

metrust-0.3.4-cp312-cp312-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

metrust-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

metrust-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

metrust-0.3.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

metrust-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

metrust-0.3.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

Details for the file metrust-0.3.4.tar.gz.

File metadata

  • Download URL: metrust-0.3.4.tar.gz
  • Upload date:
  • Size: 621.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for metrust-0.3.4.tar.gz
Algorithm Hash digest
SHA256 a6b3dc81da825278904d0b829c44474ccbddcba875db139d30ba7b6575833e8b
MD5 954f381a52f0da7f8f3f3add53c045de
BLAKE2b-256 03251f1d701a396134172b8a61ddd0141331d1e441fb401dab93369917ab7e24

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2384698b34f57dc72381c4e911b3d1aea5dd6530e1d0cbff6a1666cb8ec26a26
MD5 a432835e3707560dd310196e8339f9f8
BLAKE2b-256 cff8628251983b4c69cf6cdbda8b38728c6b1ce02d2a7fd8f142c9077375470d

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4850cd98509fa016696063b66f2a05cf541260ca78103db0ac8b28c96c6409dd
MD5 4ebc40cdc2cfa9cc81bfe3d98277d2e1
BLAKE2b-256 0464278189bce008d164389dceca99d4fd7f953603285427fa0c6914be6cb5f5

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: metrust-0.3.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for metrust-0.3.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 891f44e80175e6afec061f57102f80a2855fd9c17a5761b4c51adc6be9fea1ac
MD5 b79290e6f84aa3e1fa66ae3285f85bda
BLAKE2b-256 3adaa04f3c55d513a7c83263159add420fbf610e474728540c8ae7f43d23d7a5

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56cebcee7bd712d1a769186effd1f31190ce85bf0630949eb90ca2239e6d0a89
MD5 f00c40a6ec3a9884eff945a7ebef34b2
BLAKE2b-256 7d3ad317bbc2a838047fb90e311f3655945130a937072ee2c6e29c7d008463f4

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bad85978f8c083486fb888673d3cfef33f2d7204ec957054044fc83baedc907f
MD5 33f9f550f9a24f30d0439ed3158e447c
BLAKE2b-256 747918a73237ea4bf624113122c2e2e688e8b4597580ffe0afce74dec4beacda

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5fa515081a632e3e7cd499623b3522f4237ab04a4724ddd5625706e4c90b5528
MD5 ac82987a1f46f21b8a3bc3869b53ffc9
BLAKE2b-256 a4a96ec530d4cf976f69fd575bab47d9f69ffa6fc78ea507b977265cf342542d

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 35f917b7c0cfde06025250182a3abf4bbcfee0e034e8ed2837292c7cccdbaa51
MD5 526a09537b9350db86f2bd734cdecd74
BLAKE2b-256 0e09d58c0e327e319316d0c6a8f1651c2154e1bd18e1d9924bf6607e69d2aee4

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f650ad2db6fe4c895b108bb4505e1b4e473b1dd7b4c34135a762da3df07dd09
MD5 7c93b1f4edd98ad2929b4c5835b2c207
BLAKE2b-256 574e2100f8d197e39a10ddfa3de4273ae20ff5310f45d5ee4ae70f325b82ec3d

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a3b4a8ea80583146dff6fa1856140efa05b0f94d976a654a328e1a8320131ced
MD5 bacfb588de24effe622583fdf940749f
BLAKE2b-256 5beb4e5cb137842df050c05ce724ceef92253ca0a669a486fd65f4b1e09b478d

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc957b24c9e327817f50a0cbed91b8aa5051fa7bcba8047db2361d807e623eae
MD5 0b8a8ccefe5690dbdca8cd764ecc2418
BLAKE2b-256 2991683dd96d82b389b0d2600ba4b2e72d5826dcc7cecb21ed28d81f49d07fde

See more details on using hashes here.

File details

Details for the file metrust-0.3.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for metrust-0.3.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b4958b5cc1b1ef20262fcdd08e77aa29dc0f736936193098acc73c3dd81b48c7
MD5 0fdb1f20f8b15d5e3b1bf8d1ec82d78d
BLAKE2b-256 4377065adc08bae02c658824cb020166d656491761ba3331b4e62b1ec9714b16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page