Struct measurements::humidity::Humidity
source · [−]pub struct Humidity { /* private fields */ }
Expand description
The Humidity
struct can be used to deal with relative humidity
in air in a common way. Relative humidity is an important metric used
in weather forecasts.
Relative humidity (as a ratio and percentage) and conversions between relative humidity and dewpoint are supported. It also provides calculations giving vapour pressure and absolute humidity.
Relative humidity gives the ratio of how much moisture the air is holding to how much moisture it could hold at a given temperature. Here we use the technical definition of humidity as ratio of the actual water vapor pressure to the equilibrium vapor pressure (often called the “saturation” vapor pressure).
For dewpoint calculations, we use the algorithm commonly known as the Magnus formula, with coefficients derived by Alduchov and Eskridge (1996), which gives resonable accuracy (vapour pressure error < 0.2%) for temperatures between 0 deg C, and 50 deg C.
Example:
// calculate the dewpoint from the relative humidity
use measurements::{Humidity,Temperature};
let humidity = Humidity::from_percent(85.0);
let temp = Temperature::from_celsius(18.0);
let dewpoint = humidity.as_dewpoint(temp);
println!("At {} humidity, air at {} has a dewpoint of {}", humidity, temp, dewpoint);
Implementations
sourceimpl Humidity
impl Humidity
sourcepub fn from_percent(percent: f64) -> Self
pub fn from_percent(percent: f64) -> Self
Create a new Humidity from a floating point value percentage (i.e. 0.0% to 100.0%)
sourcepub fn from_ratio(relative_humidity: f64) -> Self
pub fn from_ratio(relative_humidity: f64) -> Self
Create a new Humidity from a floating point value ratio (i.e. 0.0 to 1.0)
sourcepub fn as_ratio(&self) -> f64
pub fn as_ratio(&self) -> f64
Convert this relative humidity to a value expressed as a ratio (i.e. 0.0 to 1.0)
sourcepub fn as_percent(&self) -> f64
pub fn as_percent(&self) -> f64
Convert this relative humidty to a value expressed as a percentage (i.e. 0.0% to 100.0%)
sourcepub fn as_dewpoint(&self, temp: Temperature) -> Temperature
pub fn as_dewpoint(&self, temp: Temperature) -> Temperature
Calculates Dewpoint from humidity and air temperature using the Magnus-Tetens approximation, with coefficients derived by Alduchov and Eskridge (1996). The formulas assume
sourcepub fn as_vapor_pressure(&self, temp: Temperature) -> Pressure
pub fn as_vapor_pressure(&self, temp: Temperature) -> Pressure
Calculates the actual vapour pressure in the air, based on the air temperature and humidity at standard atmospheric pressure (1013.25 mb), using the Buck formula (accurate to +/- 0.02% between 0 deg C and 50 deg C)
sourcepub fn as_absolute_humidity(&self, temp: Temperature) -> Density
pub fn as_absolute_humidity(&self, temp: Temperature) -> Density
Calculates the absolute humidity (i.e. the density of water vapor in the air (kg/m3)), using the Ideal Gas Law equation.
sourcepub fn from_dewpoint(dewpoint: Temperature, temp: Temperature) -> Humidity
pub fn from_dewpoint(dewpoint: Temperature, temp: Temperature) -> Humidity
Calculates humidity from dewpoint and air temperature using the Magnus-Tetens Approximation, with coefficients derived by Alduchov and Eskridge (1996). The formulas assume
Trait Implementations
sourceimpl Measurement for Humidity
impl Measurement for Humidity
sourcefn as_base_units(&self) -> f64
fn as_base_units(&self) -> f64
Get this quantity in the base units
sourcefn from_base_units(relative_humidity: f64) -> Self
fn from_base_units(relative_humidity: f64) -> Self
Create a new quantity from the base units
sourcefn get_base_units_name(&self) -> &'static str
fn get_base_units_name(&self) -> &'static str
Return the base unit for this type, as a string. For example “kilograms” Read more
sourcefn get_appropriate_units(&self) -> (&'static str, f64)
fn get_appropriate_units(&self) -> (&'static str, f64)
Returns a string containing the most appropriate units for this quantity, and a floating point value representing this quantity in those units. Useful when, for example, a length might be in millimeters if it is very small, or kilometers when it is very large. Read more
sourceimpl PartialOrd<Humidity> for Humidity
impl PartialOrd<Humidity> for Humidity
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Humidity
impl Eq for Humidity
Auto Trait Implementations
impl RefUnwindSafe for Humidity
impl Send for Humidity
impl Sync for Humidity
impl Unpin for Humidity
impl UnwindSafe for Humidity
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more