Skip to content

Instantly share code, notes, and snippets.

@sourceperl
Last active July 12, 2024 14:58
Show Gist options
  • Save sourceperl/45587ea99ff123745428 to your computer and use it in GitHub Desktop.
Save sourceperl/45587ea99ff123745428 to your computer and use it in GitHub Desktop.
Compute frost and dew point (Python function)
import math
def get_frost_point_c(t_air_c, dew_point_c):
"""Compute the frost point in degrees Celsius
:param t_air_c: current ambient temperature in degrees Celsius
:type t_air_c: float
:param dew_point_c: current dew point in degrees Celsius
:type dew_point_c: float
:return: the frost point in degrees Celsius
:rtype: float
"""
dew_point_k = 273.15 + dew_point_c
t_air_k = 273.15 + t_air_c
frost_point_k = dew_point_k - t_air_k + 2671.02 / ((2954.61 / t_air_k) + 2.193665 * math.log(t_air_k) - 13.3448)
return frost_point_k - 273.15
def get_dew_point_c(t_air_c, rel_humidity):
"""Compute the dew point in degrees Celsius
:param t_air_c: current ambient temperature in degrees Celsius
:type t_air_c: float
:param rel_humidity: relative humidity in %
:type rel_humidity: float
:return: the dew point in degrees Celsius
:rtype: float
"""
A = 17.27
B = 237.7
alpha = ((A * t_air_c) / (B + t_air_c)) + math.log(rel_humidity/100.0)
return (B * alpha) / (A - alpha)
@iamz33
Copy link

iamz33 commented Nov 12, 2019

Thanks a lot for the code. Can you please tell the reference where you got the frost point formula? Would be really helpful. Thanks

@euxoa
Copy link

euxoa commented Sep 14, 2022

@jago-scolab
Copy link

This code uses the Tetens coefficients in a Magnus-type equation for T_d over a water surface. Alduchov and Eskridge recommend in their paper other coefficients, though differences are small. For upper levels, it would be more appropriate to complete this with the coefficients when over an icy surface

@themeadery
Copy link

Nice formula. I've slightly rewritten it for my purposes and used the constants that are generally accepted as more accurate from the paper by Alduchov and Eskridge, also taking some inspiration from the wikipedia article. Cross-checked with the previously mentioned omni calculator and it seems to work well. This was the best example I found in my google searches, so thank you for the information! I was trying to convert some other formula written in C and was not getting correct results.

def calc_dewpoint(humidity, temp_c):
    a = 17.625
    b = 243.04
    alpha = math.log(humidity/100.0) + ((a * temp_c) / (b + temp_c))
    return (b * alpha) / (a - alpha)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment