58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
LAPSE_RATE_DRY = 9.8 / 1000 # degrees C per km
|
|
LAPSE_RATE_MOIST = 4.0 / 1000
|
|
|
|
def vapor_pressure(dewpoint: float) -> float:
|
|
"""
|
|
Return the pressure of vapor in a parcel of a given dewpoint.
|
|
"""
|
|
return 6.11 * 10 ** (
|
|
(7.5 * dewpoint) / (237.3 * dewpoint)
|
|
)
|
|
|
|
def saturated_vapor_pressure(temp: float) -> float:
|
|
"""
|
|
Return the pressure at which the vapor and condensation of a parcel of a
|
|
given temperature are at equilibrium.
|
|
"""
|
|
return 6.11 * 10 ** (
|
|
(7.5 * temp) / (237.3 * temp)
|
|
)
|
|
|
|
def mixing_ratio(dewpoint: float, pressure: float) -> float:
|
|
"""
|
|
Return the amount, in grams, of water vapor versus dry air in a parcel of
|
|
a given dewpoint and pressure.
|
|
"""
|
|
e = vapor_pressure(dewpoint)
|
|
|
|
return 621.97 * (e / (pressure - e))
|
|
|
|
def saturated_mixing_ratio(temp: float, pressure: float) -> float:
|
|
"""
|
|
Return the maximum amount, in grams, of water vapor a parcel of a given
|
|
temperature and pressure can hold.
|
|
"""
|
|
es = saturated_vapor_pressure(temp)
|
|
|
|
return 621.97 * (es / (pressure - es))
|
|
|
|
def lcl(temp: float, dewpoint: float) -> float:
|
|
"""
|
|
Return the height, in meters, at which a parcel of the given temperature
|
|
is cooled to the given dewpoint.
|
|
"""
|
|
return (temp - dewpoint) / 0.008
|
|
|
|
def pressure_height(pressure: float) -> float:
|
|
"""
|
|
Return the approximate altitude, in meters, for a given pressure in
|
|
millibar.
|
|
"""
|
|
return (1 - (pressure / 1013.25) ** 0.190284) * 145366.45 * 0.3048
|
|
|
|
def lapse(temp: float, delta: float) -> float:
|
|
"""
|
|
Return the temperature of a parcel cooled at the dry lapse rate for a
|
|
given increase in height (in meters).
|
|
"""
|
|
return temp - (LAPSE_RATE_DRY * delta)
|