Skip to content

Instantly share code, notes, and snippets.

@vsee
Created January 9, 2021 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsee/a51d2ebc7376bbd38f3d58c87c2b5d1b to your computer and use it in GitHub Desktop.
Save vsee/a51d2ebc7376bbd38f3d58c87c2b5d1b to your computer and use it in GitHub Desktop.
Calculate the absolute humidity based on relative temperature in Celcius and relative humidity in percent.
#!/usr/bin/env python3
"""
Calculate the absolute humidity based on relative temperature in Celcius
and relative humidity in percent.
Based on:
https://carnotcycle.wordpress.com/2012/08/04/how-to-convert-relative-humidity-to-absolute-humidity/
Dry vs. Wet House based on Absolute Humidity:
https://www.youtube.com/watch?v=iiokj5gr4Jw&ab_channel=PeterWard
"""
import sys
import math
relT = float(sys.argv[1])
relH = float(sys.argv[2])
print("Relative Temperature " + str(relT) + " C")
print("Relative Humidity " + str(relH) + " %")
exponent = math.exp( (17.67*relT) / (relT + 243.5) )
absH = (6.112 * exponent * relH * 18.02) / ((273.15+relT)*100*0.08314)
print("Absolute Humidity " + str(absH) + " g/m^3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment