Crate metfor

source ·
Expand description

Meteorological constants and formulas.

This library includes wrapper types, or unit types, to help with using the proper units when doing calculations, some common meteorological constants, and some functions for basic calculations. It has thus far been developed to support libraries and an application used for displaying and analyzing skew-t data. So you will find the functions and variables are mostly things that would typically be used on a skew-t. Future versions may expand the intended use cases.

I investigated using some sort of dimensional analysis via types with a crate like uom or dimensioned instead of making my own newtype types. However after experimentation, I decided I did not want to make another crate part of the API since choosing to use one would force that library on the users of this library.

I’ve found the [optional] optional crate to be very useful when dealing with f64 types in situations where there may be missing values, so I included a feature use_optional that enables the newtypes in this crate to be used in the same manner as an f64 is with optional.

Examples

use metfor::{Kelvin, Celsius, HectoPascal, Millibar, theta};

let t1 = Kelvin(300.0);
let p1 = HectoPascal(1000.0);
let theta1 = theta(p1, t1);

let t2 = Celsius(0.0);
let p2 = Millibar(700.0);
let theta2 = theta(p2, t2);

println!("theta1 = {} and theta2 = {}", theta1, theta2);

Re-exports

pub use crate::constants::*;

Modules

Meteorlogical constants.

Structs

Temperature in Celsius units.
Temperature difference in Celsius units.
Temperature lapse rate in Celsius per kilometer.
Length in centimeters, usually used for precipitation depth or precipitable water.
Length in decameters, usually used for geopotential height.
Temperature in Fahrenheit units.
Temperature difference in Fahrenheit units.
Temperature lapse rate in Fahrenheit per thousand feet (kft).
Length in feet, usually used for geopotential height and elevation.
Pressure in hPa units.
Length in inches, usually used for precipitation depth or precipitable water.
Specific energy in J kg-1 units. Used for CAPE, CIN, latent heat, etc.
Specific energy per Kelvin in J K-1 kg-1. Used for gas constants and specific heat valus.
Temperature in Kelvin units.
Length in kilometers, usually used for geopotential height above ground level.
Length in meters, usually used for geopotential height and elevation.
Pressure vertical velocity in microbar/s
Pressure in mb units.
Length in millimeters, usually used for precipitation depth or precipitable water.
Pressure vertical velocity in Pa/s
Wind direction and speed in knots.
Wind in U and V components in m/s.

Traits

Marker trait for elevation/height types.
Marker trait for pressure vertical veclocity types.
Marker trait for Pressure types.
A quantity is a common super trait for types that represent units of measurement.
Marker trait for specific energy types.
Marker trait for specific energy per Kelvin types
Marker trait for temperature differences.
Marker trait for temperature lapse rate types.
Marker trait for temperature types.
A version of Quantity for vectors.
Marker trait for Wind types.

Functions

Given a mixing ratio and pressure, calculate the dew point temperature. If saturation is assumed this is also the temperature.
Get the frost point given the vapor pressure of water over ice. This function is the inverse of vapor_pressure_ice.
Latent heat of condensation for water.
Calculate the mixing ratio of water.
Calculate the temperature and pressure at the lifting condensation level (LCL).
Approximate pressure of the Lifting Condensation Level (LCL).
Calculate the relative humidity with respect to liquid water.
Calculate the relative humidity with respect to ice.
Calculate the specific humidity.
Given a potential temperature and pressure, calculate the temperature.
Given the pressure and equivalent potential temperature, assume saturation and calculate the temperature.
Calculate potential temperature assuming a 1000 hPa reference level.
Calculate equivalent potential temperature.
Get the vapor pressure over ice.
Get the vapor pressure over liquid water.
Virtual temperature.
Calculate the web bulb temperature.

Type Definitions

Temperature difference in Kelvin units.
Temperature lapse rate in Kelvin per kilometer.