# Program for obtaining dew point temperature from T, Tw, and P # Written for Python version 2.7.13. # Add parenthesis around the print statements at the bottom to get it to work for Python version 3.x. import math # First some useful functions are defined. # Function to calculate the saturation vapor pressure over water in mb for temperature T in C. # Relationship is from Bolton as quoted in Grant Petty's Atmospheric Thermo book. def esatWater(T): return 6.112*math.exp(17.67*T/(243.5+T)) # Function to calculate relative humidity, RH, in %, from T and Tdew in C. # This function calls the esatWater function. def RelativeHumidity(Tdew,T): return 100.0*esatWater(Tdew)/esatWater(T) # Function to calculate Latent heat of water to vapor for T in C. def LatentHeat(T): return 1000.0*(2500.8-2.36*T+0.0016*T*T-0.00006*T*T*T) # print "Llv(10C)=",LatentHeat(10),"\n" # Function to get Tdew and RH from To, Po, and Tw in C and mb. def dewPoint(Po,To,Tw): Llv=LatentHeat(To) cp=1004. # J/kg K. eps=0.622 # mw H20/air eo=6.112 # mb H20 at saturation at 0 C. R=esatWater(Tw)/eo - Po*cp*(To-Tw)/(eps*eo*Llv) Tdew=243.5*math.log(R)/(17.67-math.log(R)) # Dewpoint T in C RH=RelativeHumidity(Tdew,To) return Tdew,RH # Main program that calls the functions. # Example calculation of Tdew given Po, To, and Tw. Po=870.0 # mb units To=25.0 # C units Tw=15.0 # C units Tdew,RH = dewPoint(Po,To,Tw) # C and % units. print "INPUT VALUES:" print " Po",Po,"mb" print " To",To,"C" print " Tw",Tw,"C" print "OUTPUT VALUES:" print " Tdew={0:1.2f}".format(Tdew),"C" print " RH={0:1.2f}".format(RH),"%\n"