Skip to content

Instantly share code, notes, and snippets.

@Nircek
Last active June 23, 2023 14:29
Show Gist options
  • Select an option

  • Save Nircek/3e8ba766d618ee2bc05d49f7ce625234 to your computer and use it in GitHub Desktop.

Select an option

Save Nircek/3e8ba766d618ee2bc05d49f7ce625234 to your computer and use it in GitHub Desktop.
'''
// SRC: https://klimapoint.pl/kalkulator-wilgotnosci-bezwzglednej/ z htmla po prostu
// temp - temperatura w °C (-20 - 50)
// rh - wilgotność względna w % (1 - 100)
function getDP(temp, rh) {
var h = ((Math.log10(rh)-2)/0.4343) + ((17.62*temp)/(243.12+temp));
h = ((243.12*h)/(17.62-h));
return Math.round(h*100)/100;
}
function getAH(temp, rh) {
var ah = 216.7*(((rh/100)*6.112*Math.exp((17.62*temp)/(243.12+temp)))/(273.15+temp));
return Math.round(ah*100)/100;
}
'''
from math import log10, exp
def dew_point(t, h):
'''
:param t: temperature [°C]
:param h: relative humidity [%]
:return: dew point [°C]
'''
A, B, C = 243.12, 17.62, 0.4343
L = log10(h)-2
X = (L/C + (B*t)/(A+t))
P = (A*X)/(B-X)
return P
def absolute_humidity(t, h):
'''
:param t: temperature [°C]
:param h: relative humidity [%]
:return: absolute humidity [g/m³]
'''
A, B, D, E, K = 243.12, 17.62, 216.7, 6.112, 273.15
H = D*h/100*E*exp(B*t/(A+t))/(K+t)
return H
def air_condition(t, h):
'''
:param t: temperature [°C]
:param h: relative humidity [%]
'''
assert -20 <= t and t <= 50, f'{t=} not in -20÷50'
assert 1 <= h and h <= 100, f'{h=} not in 1÷100'
return f'DP: {dew_point(t, h):.1f} °C; AH: {absolute_humidity(t, h):.1f} g/m³'
if __name__ == '__main__':
import traceback, readline
print('Input temperature [°C] and relative humidity [%]')
print('Example: 27.5 46\n\n')
while True:
try:
print(air_condition(*map(float, input().split())), end='\n\n')
except KeyboardInterrupt:
break
except:
traceback.print_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment