sounding_base/
lib.rs

1#![doc(test(attr(deny(warnings))))]
2#![deprecated]
3/*!
4
5Library to represent an atmospheric sounding with pressure as the vertical coordinate.
6The base crate is meant to be a common base for other crates to build on. These crates may be for
7managing a data-store, displaying data, or saving and loading files.
8
9The emphasis of this crate is data representation and a common type for systems using sounding
10data to build on and use.
11
12# Examples
13```
14use optional::{Optioned, some};
15use metfor::{HectoPascal, Celsius, Feet};
16
17use sounding_base::{Sounding, StationInfo};
18
19fn main() {
20
21    // Create  pressure profile
22    let pressure_profile: Vec<Optioned<HectoPascal>> =
23        vec![1000.0, 925.0, 850.0, 700.0, 500.0, 300.0, 250.0, 100.0]
24            .into_iter()
25            .map(HectoPascal)
26            .map(some)
27            .collect();
28
29    // Create a temperature profile
30    let temperature_profile: Vec<Optioned<Celsius>> =
31        vec![13.0, 7.0, 5.0, -4.5, -20.6, -44.0, -52.0, -56.5]
32            .into_iter()
33            .map(Celsius)
34            .map(some)
35            .collect();
36
37    // Create some station info
38    let stn = StationInfo::new_with_values(None, (45.6789, -115.6789), Feet(992.0));
39
40    // Create a valid time. This uses a `chrono::NaiveDateTime`, and you should always assume
41    // that valid times are in UTC.
42    let vt = chrono::NaiveDate::from_ymd(2018,3,8).and_hms(12,0,0);
43
44    // Use the builder pattern to construct a sounding.
45    let snd = Sounding::new()
46        .with_station_info(stn)
47        .with_valid_time(vt)
48        .with_lead_time(24)  // Lead time in hours for forecast soundings.
49        .with_pressure_profile(pressure_profile)
50        .with_temperature_profile(temperature_profile)
51        .with_station_pressure(some(HectoPascal(1013.25)))
52        .with_sfc_temperature(some(Celsius(15.0)));
53
54    // Top down and bottom up iterators are provided. If surface data is available, it is
55    // inserted into the profile.
56    let mut iter = snd.top_down();
57
58    let mut data_row = iter.next().unwrap();
59    assert_eq!(data_row.pressure, some(HectoPascal(100.0)));
60    assert_eq!(data_row.temperature, some(Celsius(-56.5)));
61
62    data_row = iter.next().unwrap();
63    assert_eq!(data_row.pressure, some(HectoPascal(250.0)));
64    assert_eq!(data_row.temperature, some(Celsius(-52.0)));
65
66    data_row = iter.next().unwrap();
67    assert_eq!(data_row.pressure, some(HectoPascal(300.0)));
68    assert_eq!(data_row.temperature, some(Celsius(-44.0)));
69
70    data_row = iter.next().unwrap();
71    assert_eq!(data_row.pressure, some(HectoPascal(500.0)));
72    assert_eq!(data_row.temperature, some(Celsius(-20.6)));
73
74    data_row = iter.next().unwrap();
75    assert_eq!(data_row.pressure, some(HectoPascal(700.0)));
76    assert_eq!(data_row.temperature, some(Celsius(-4.5)));
77
78    data_row = iter.next().unwrap();
79    assert_eq!(data_row.pressure, some(HectoPascal(850.0)));
80    assert_eq!(data_row.temperature, some(Celsius(5.0)));
81
82    data_row = iter.next().unwrap();
83    assert_eq!(data_row.pressure, some(HectoPascal(925.0)));
84    assert_eq!(data_row.temperature, some(Celsius(7.0)));
85
86    data_row = iter.next().unwrap();
87    assert_eq!(data_row.pressure, some(HectoPascal(1000.0)));
88    assert_eq!(data_row.temperature, some(Celsius(13.0)));
89
90    // THIS ONE IS THE SURFACE DATA!
91    data_row = iter.next().unwrap();
92    assert_eq!(data_row.pressure, some(HectoPascal(1013.25)));
93    assert_eq!(data_row.temperature, some(Celsius(15.0)));
94
95    assert_eq!(iter.next(), None);
96
97    // Profiles and surface values can also be accessed via getter methods. Read the docs!
98}
99```
100
101You probably noticed a lot of `optional::Optioned`s in the example. Basically, anything can be
102missing, and missing values are common in upper air soundings. For example, at high altitude the
103dew point or humidity are often missing (if not totally inaccurate).
104
105*/
106#![deny(missing_docs)]
107
108//
109// API
110//
111pub use crate::data_row::DataRow;
112pub use crate::sounding::Sounding;
113pub use crate::station_info::StationInfo;
114
115//
116// Internal use only
117//
118
119mod data_row;
120mod sounding;
121mod station_info;
122
123#[doc(hidden)]
124pub use crate::sounding::doctest;