winds-engine v0.9.2
Deterministic wind fields for trajectory simulation — profiles, forecast and terrain — in Rust.
winds-engine = "0.9"
What it does
WindField— one trait,wind(time_s, position_m). Stateless and deterministic: the same time and position always give the same wind, so integrator substeps and seeded reruns reproduce exactly.ConstantField— uniform wind everywhere.ProfileField/ProfileLevel— a piecewise-linear vertical profile. Speed interpolates linearly with height and direction along the shortest arc (350° to 10° passes through 0°); the nearest level holds above and below. Levels are checked and sorted.LogProfile— log-law boundary layer from a reference speed, a reference height and a roughness length; calm at and below the roughness length, constant direction.EkmanProfile— the Ekman spiral for constant eddy viscosity, from a geostrophic speed and direction, a latitude and an eddy viscosity: calm at the ground, turning toward the geostrophic wind aloft. The constructor rejects the equator (latitude 0), where the solution has no boundary layer.HeightOffset— reads any field at a shifted height, so a ground-relative profile (log, Ekman) drops into a sea-level frame: convert the datum in one place, once.Sounding— parses a deliberately trivial line format (altitude_m speed_mps direction_from_deglines, plus#comments, where# station:and# valid:set the header fields), so radiosonde archives convert offline. Tested against a real 115-level KMPX sounding from the Iowa State IEM RAOB archive.validate— scores aProfileFieldagainst a sounding at the sounding's own levels: speed RMSE, circular direction RMSE, and mean absolute speed error per layer (0–1, 1–3, 3–6, 6–10 km, then the rest).grib(feature) — decode GRIB2 forecast files (GFS isobaric HGT/UGRD/VGRD) into aProfileFieldat a point, bilinear-interpolated; offline and deterministic.download(feature) — fetch live forecasts: GFS via the NOAA NOMADS subset script, or HRRR's 3 km CONUS grids by byte-range requests against the AWS mirror. The only networked code in the crate.TerrainFlowField/HeightGrid— a diagnostic mass-consistent terrain wind: adjust a base field so flow is deflected over and around a DEM, satisfying 2-D horizontal mass conservation.Monitor— surface wind observations fed as soft constraints:from_geoandmonitors_from_geo_csvproject GPS lat/lon into the field's frame and rotate compass directions, so a distributed sensor network slots straight in.
Built on ballistics-engine's wind-field core (re-exported) and nalgebra; the only optional extras are grib and download. No network, no wall clock, no unseeded randomness.
Conventions
- Frame — x downrange, y up, z to the right: right-handed, the frame ballistics-engine uses.
- Directions — where the wind comes from, degrees clockwise: 0° is a headwind, 90° is from the right.
- Units — m/s for wind, metres for heights and positions, seconds for time. These horizontal fields have no vertical wind.
Heights
Sounding heights are metres above sea level, and to_profile_field() keeps them there, so the profile reads directly in a frame whose y is altitude above sea level, like rockets-engine's. The layers in validate use the same sea-level heights.
LogProfile and EkmanProfile take y as height above the ground, where they are calm. In a sea-level frame, wrap them in HeightOffset with offset −ground elevation — convert in one place only: shifting the sounding too would move every wind by the site elevation.
Example
use nalgebra::Vector3;
use winds_engine::{validate, HeightOffset, LogProfile, ProfileField, ProfileLevel, Sounding, WindField};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// altitude_m speed_mps direction_from_deg; heights above sea level
let sounding = Sounding::parse("287 0.0 0\n305 3.09 125\n610 3.60 145\n")?;
// The profile keeps those heights: read it at y = altitude above sea level.
let measured = sounding.to_profile_field()?;
let wind = measured.wind(0.0, Vector3::new(0.0, 500.0, 0.0));
println!("{:.2} m/s", wind.x.hypot(wind.z));
// Score a candidate profile, on the same sea-level heights, against it.
let candidate = ProfileField::new(vec![
ProfileLevel { altitude_m: 287.0, speed_mps: 0.0, direction_from_deg: 0.0 },
ProfileLevel { altitude_m: 610.0, speed_mps: 4.0, direction_from_deg: 140.0 },
])?;
let report = validate::validate(&candidate, &sounding);
println!("speed RMSE {:.2} m/s", report.speed_rmse_mps);
// A log law measures height from the ground: HeightOffset reads it in the
// sea-level frame (offset = minus the ground elevation), converting once.
let log = HeightOffset::new(LogProfile::new(8.0, 10.0, 0.03, 270.0)?, -287.0)?;
let low = log.wind(0.0, Vector3::new(0.0, 500.0, 0.0));
println!("{:.2} m/s", low.x.hypot(low.z));
Ok(())
}
Needs Rust 1.89 or newer. The README walks through the same sounding.
Where it fits
- ballistics-engine — the trajectory kernel, and since winds-engine 0.6.0 the source of the wind-field core itself:
WindField, the profile types,HeightOffsetandWindFieldErrorare ballistics-engine'swindmodule (released in ballistics-engine 0.49.0), re-exported here so the pipelines and their consumers share one definition. The kernel owns gravity, drag, the ICAO atmosphere and the integrator; winds-engine owns the wind data: soundings, forecast ingestion, terrain flow. - rockets-engine — the consumer it is built for: sounding profiles keep sea-level heights, the same height datum as rockets-engine's frame.
BallisticForces, the weathercock and the recovery descent share anArc<dyn WindField>, and the CLI flies--wind-profile,--wind-sounding,--wind-grib(forecast wind) and--wind-dem/--wind-monitors(terrain-adjusted wind from distributed sensors). rockets-engine tracks the kernel-field API in lockstep with winds-engine 0.6.
Status
Version 0.6.0, published on crates.io; API docs at docs.rs/winds-engine. It is a library only, with no CLI and no browser terminal.
Planned, not built: more sounding validation days (one KMPX profile is checked in), and a full 3-D terrain mesh — the diagnostic 2-D-per-level adjustment above is the cheap first tier.