Forked from
MetObs / MetObsSite
44 commits behind the upstream repository.
-
David Hoese authoredDavid Hoese authored
dewpoint.py 1.17 KiB
# Functions for calculating the dewpoint.
# $Id: dewpoint.py,v 1.1 2003/04/16 19:38:48 maciek Exp $
import math
def dewpoint(tempC, relhum):
""" algorithm from Tom Whittaker
tempC is the temperature in degrees Celsius,
relhum is the relative humidity as a percentage"""
gasconst = 461.5
latheat = 2500800.0
dp = 1.0 / ( 1.0 / ( 273.15 + tempC ) - gasconst * math.log( (0.0 + relhum) / 100 ) / \
( latheat - tempC * 2397.5 ))
return min(dp - 273.15, tempC)
def awips_dewpoint(tempC, relhum):
""" algorithm taken from http://meted.ucar.edu/awips/validate/dewpnt.htm
tempC is the temperature in degrees Celsius,
relhum is the relative humidity as a percentage"""
C15 = 26.66082
C1 = 0.0091379024
C2 = 6106.396
C3 = 223.1986
C4 = 0.0182758048
t = tempC + 273.15 # convert temperature to Kelvin
rh = relhum / 100 # convert relative humidity to ratio
es = math.exp( C15 - C1 * t - C2 / t ) # saturation vapor pressure
e = rh * es
b = C15 - math.log(e)
td = ( b - math.sqrt( b * b - C3 ) ) / C4
return min(td - 273.15, tempC)