Skip to main content

winds_engine/
lib.rs

1//! Deterministic wind data for trajectory simulation, consumed by
2//! rockets-engine.
3//!
4//! The wind-field types — the [`WindField`] trait, [`ConstantField`],
5//! [`ProfileField`], [`LogProfile`], [`EkmanProfile`] and the [`HeightOffset`]
6//! datum wrapper — are ballistics-engine's (its `wind` module, since
7//! ballistics-engine 0.49.0), re-exported here so this crate's pipelines and
8//! its consumers share one definition. Everything is stateless and
9//! reproducible from inputs: no wall clock or unseeded randomness anywhere,
10//! and no network except the `download` feature.
11//!
12//! - [`sounding`]: radiosonde interchange-format parsing.
13//! - [`validate`]: profile-vs-sounding comparison metrics.
14//! - [`terrain`]: a diagnostic mass-consistent terrain wind.
15//! - `grib` (feature): GRIB2 forecast files into a [`ProfileField`].
16//! - `download` (feature): live GFS/HRRR acquisition, the only networked
17//!   code in the crate.
18
19#[cfg(feature = "download")]
20pub mod download;
21#[cfg(feature = "grib")]
22pub mod grib;
23pub mod sounding;
24pub mod terrain;
25pub mod validate;
26
27pub use ballistics_engine::wind::{
28    ConstantField, EkmanProfile, HeightOffset, LogProfile, ProfileField, ProfileLevel, WindField,
29    WindFieldError, WindFieldParam, WindFieldRule,
30};
31pub use sounding::{Sounding, SoundingLevel};
32pub use terrain::{local_en_m, monitors_from_geo_csv, HeightGrid, Monitor, TerrainFlowField};
33pub use validate::{LayerError, ValidationReport};
34
35/// Crate-wide error: invalid input with a field name and reason.
36#[derive(Debug, Clone, PartialEq)]
37pub struct Error {
38    /// The offending input or field.
39    pub field: &'static str,
40    /// Why it was rejected.
41    pub reason: String,
42}
43
44impl Error {
45    pub(crate) fn invalid(field: &'static str, reason: impl Into<String>) -> Self {
46        Self {
47            field,
48            reason: reason.into(),
49        }
50    }
51}
52
53impl std::fmt::Display for Error {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        write!(f, "{}: {}", self.field, self.reason)
56    }
57}
58
59impl std::error::Error for Error {}
60
61/// Crate-wide result.
62pub type Result<T> = std::result::Result<T, Error>;