sounding_analysis/layers/
height_pressure.rs1use super::Layer;
2use crate::{
3 error::{AnalysisError::MissingValue, Result},
4 interpolation::linear_interpolate_sounding,
5 levels::height_level,
6 sounding::{DataRow, Sounding},
7};
8use metfor::{HectoPascal, Meters};
9
10#[inline]
12pub fn layer_agl(snd: &Sounding, meters_agl: Meters) -> Result<Layer> {
13 let tgt_elev = snd
14 .station_info()
15 .elevation()
16 .map(|e| e + meters_agl)
17 .ok_or(MissingValue)?;
18
19 let mut bottom = snd.data_row(0).unwrap_or_else(DataRow::default);
21
22 if bottom.pressure.is_none()
23 || bottom.temperature.is_none()
24 || bottom.dew_point.is_none()
25 || bottom.wind.is_none()
26 {
27 bottom = snd.data_row(1).unwrap_or_else(DataRow::default);
28 }
29
30 let top = height_level(tgt_elev, snd)?;
31 Ok(Layer { bottom, top })
32}
33
34#[inline]
36pub fn pressure_layer(snd: &Sounding, bottom_p: HectoPascal, top_p: HectoPascal) -> Result<Layer> {
37 debug_assert!(bottom_p > top_p);
38
39 let bottom = linear_interpolate_sounding(snd, bottom_p)?;
40 let top = linear_interpolate_sounding(snd, top_p)?;
41
42 Ok(Layer { bottom, top })
43}