1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Humidity-derived values: the dew point.
use log;
/// Magnus coefficient (dimensionless), for the range about -45 to 60 C.
const MAGNUS_B: f64 = 17.62;
/// Magnus coefficient, in degrees Celsius.
const MAGNUS_C: f64 = 243.12;
/// Computes the dew point from temperature and relative humidity (Magnus formula).
///
/// The dew point is the temperature to which air must cool for its moisture to begin to
/// condense; it is the practical signal behind condensation, fog, and frost. This uses the
/// Magnus-Tetens approximation with the WMO coefficients (b = 17.62, c = 243.12 C), accurate
/// from roughly -45 to 60 C: with `gamma = ln(rh / 100) + b * t / (c + t)`, the dew point is
/// `c * gamma / (b - gamma)`. A dew point at or below 0 C means any condensation forms as
/// frost, the basis of an overnight frost warning for a crop.
///
/// # Arguments
///
/// * `celsius` - the air temperature in degrees Celsius.
/// * `humidity_percent` - the relative humidity in percent, in `(0, 100]`. A value at or
/// below zero is treated as a tiny positive value so the logarithm stays defined.
///
/// # Returns
///
/// The dew point in degrees Celsius.
///
/// # Examples
///
/// ```
/// use pamoja_kit::weather::dew_point;
///
/// // 20 C air at 50% relative humidity dews near 9.3 C.
/// assert!((dew_point(20.0, 50.0) - 9.3).abs() < 0.2);
///
/// // Saturated air: the dew point equals the temperature.
/// assert!((dew_point(15.0, 100.0) - 15.0).abs() < 1e-6);
/// ```