Dewpoint calculation script in Python

Using the well-known approximation to calculate the dew point temperature from the actual temperature and the relative humidity, it is very easy to write a small script that can do this calculation for us.

I choosed Python to do this job. Feel free to use this script for your own purposes:

import sys
import numpy as np
# approximation valid for
# 0 degC < T < 60 degC
# 1% < RH < 100%
# 0 degC < Td < 50 degC 
# constants
a = 17.271
b = 237.7 # degC
# sys.argv[0] is program name
def dewpoint_approximation(T,RH):
    Td = (b * gamma(T,RH)) / (a - gamma(T,RH))
    return Td
def gamma(T,RH):
    g = (a * T / (b + T)) + np.log(RH/100.0)
    return g
Td = dewpoint_approximation(T,RH)
print 'T, RH',T,RH
print 'Td=',Td

The script expects two input parameters. First the temperature (in °C) and second the relative humidity (in %).

You like this article? Then you may want to subscribe to our RSS-Feed.

Add a comment


  1. Simon, May 18, 2014:

    Just wanted to thank you for your script. I implemented it to my home automation system to calculate when to ventilate my basement to reduce humidity.

  2. huda, March 4, 2020:

    Thank you for your post.
    I want to know how you obtain the constant value of a and b? or what is your reference? Thank you

  3. hans, March 12, 2020:

    Thanks so much for sharing!

Subscribe to Comments (RSS-Feed)

0 Trackbacks/Pingbacks

No Trackbacks yet.