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.calcfunctions (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 analysiscookbook_500hpa_grid.py— MetPy Cookbook 500 hPa vorticity advectionsounderpy_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file metrust-0.3.9.tar.gz.
File metadata
- Download URL: metrust-0.3.9.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc56cc21ac5c30303b6e34fe876f18cd9abba974a442eb3386ffe00b15383ac7
|
|
| MD5 |
0e1b8f05da787e4b920e19a7a3666221
|
|
| BLAKE2b-256 |
291e890494c48366148c36f2fa62987ecc4a3693c794f4712c100d66389c05c3
|
File details
Details for the file metrust-0.3.9-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: metrust-0.3.9-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46b4ac467811e57321b504553aff5f509978ff149eda8785e3945ab1af1d8a3f
|
|
| MD5 |
f59e150462c630bde2e0f76902f7b054
|
|
| BLAKE2b-256 |
aca144e16e32f7b8b67fd2ce2848cd0b85f8e47fa00cf92b72191a94eff6a917
|
File details
Details for the file metrust-0.3.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: metrust-0.3.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75dfb964b0ef9324e5975d5ebf4ff9b7b26884ebe9cc670e9a7fcf6ccdfecce7
|
|
| MD5 |
4cf134e45dce08db9ec4d839c81d669a
|
|
| BLAKE2b-256 |
e061961c7b63314730967f2d2a34012a257ec109abff39a42426736ee89fdc0e
|
File details
Details for the file metrust-0.3.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: metrust-0.3.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25e92fb0262a9eef8b87fe3e2fe966c1ef929f9a39e8dff54b290a20fbe55640
|
|
| MD5 |
d12c4129b67c04ff53180194facc2d72
|
|
| BLAKE2b-256 |
752ebf20c2157f63cdcc40bb9e398757efd50a6d3a3686c74e8ba901ee3afd21
|
File details
Details for the file metrust-0.3.9-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: metrust-0.3.9-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
022a81613ef71fd9acccf8bcea9a1e5de442c292ebd793f4cf10a10045acfcc2
|
|
| MD5 |
1cb4ce12387e36e3c37785c92bd67bfe
|
|
| BLAKE2b-256 |
3f37b8bd0c891ff24bc68965baa35498b99b985436971ca990a61fc33e689a07
|
File details
Details for the file metrust-0.3.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: metrust-0.3.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4fd577d79919db66a650629de64f99776dc11d5be09be4cc22a4885e92c6d6f
|
|
| MD5 |
f95426d8758f5830fa25424beac5d8a9
|
|
| BLAKE2b-256 |
ba6741d80fa238872450ade80e9ed3dfa969ce88452e3878ff3aa008a27e4cce
|
File details
Details for the file metrust-0.3.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: metrust-0.3.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92686471bffcaaa1eb3748f2f8c5c63f693f119e3fd5a68bdf537513efb5ac7d
|
|
| MD5 |
8168f9c0bf9e2f6d1b25b497c0b8f2c4
|
|
| BLAKE2b-256 |
a96f0f3e6cf3a9d03821571b4eca12038965a44cffe6a13e4bceccf19335aaa4
|
File details
Details for the file metrust-0.3.9-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: metrust-0.3.9-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d97a8ca316bca6da993bfed05e285a59985a7d9ee9c7e4bf7021825be459990
|
|
| MD5 |
bd0139ed26661b377a06a291b3e87a66
|
|
| BLAKE2b-256 |
9c526dabcdba2d45342c10fa63746c74412e628d1924860d2054f016b2dace7d
|
File details
Details for the file metrust-0.3.9-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: metrust-0.3.9-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5be4912adf08541388ba2bc0da72754844c59eac09976044d98b019891eb47a6
|
|
| MD5 |
6742c4359fc431e6655a2a05132770ce
|
|
| BLAKE2b-256 |
7d24e58b14b194b95698579523a038b62c606e9ebb5b279bd432e8faf37e132a
|
File details
Details for the file metrust-0.3.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: metrust-0.3.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
618a31ef7e6790a159de1e981e41d9676cef43e29d4571dfb384bd97cb256c3f
|
|
| MD5 |
44ba660f92fe13cf21ae9826249a0f9b
|
|
| BLAKE2b-256 |
86e871f72c5d2e8eb51af7f6cbdef148a76bb945c20a4c3b9d58ba87f2c51bbe
|
File details
Details for the file metrust-0.3.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: metrust-0.3.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
649daea90c07fbdfc5bc1859f48f97957ee8f057a1c493ed4890e70f4adc1ef5
|
|
| MD5 |
b9b5c7bc4579b8f1c2c9ab67035c495d
|
|
| BLAKE2b-256 |
68cecd00e7eeef3006ec5d486cf77a4c4d9dd1c6b3902923ee5ab805d0edfd22
|
File details
Details for the file metrust-0.3.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: metrust-0.3.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae223143c8852bd921e8c04a162b6af7a8b14726a9ea76fa47711327f36c20fa
|
|
| MD5 |
dce693b0dc7b5e66628800e570472e18
|
|
| BLAKE2b-256 |
0538f447695114aee6bc6a8482eb1e1104366c99b5a4bfacce86d540adc90e59
|
File details
Details for the file metrust-0.3.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: metrust-0.3.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
284b1dfded75714390ad06f59795604520b0a34195ad72ecc135dc69ce94679c
|
|
| MD5 |
0e5345f080e1976fb9bcf9cc43123997
|
|
| BLAKE2b-256 |
252c568c2b3f90b2c28f67a908e2de52d1f8b9ee90dd224569928eaa0a9dc64d
|