Skip to content

Commit 12ec00e

Browse files
committed
fix(wsen-hids): added minimum humidity to ensure math
+ added lint style space
1 parent 6b5d47d commit 12ec00e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/wsen-hids/examples/dew_point.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
i2c = I2C(1)
99
sensor = WSEN_HIDS(i2c)
1010

11+
1112
def dew_point_celsius(temperature_c, humidity):
1213
# Magnus formula
1314
a = 17.62
1415
b = 243.12 # °C
1516

16-
gamma = (a * temperature_c / (b + temperature_c)) + log(humidity / 100.0)
17+
# Clamp humidity to a small positive value to avoid log(0) when humidity is 0.0
18+
safe_humidity = max(humidity, 0.01)
19+
gamma = (a * temperature_c / (b + temperature_c)) + log(safe_humidity / 100.0)
1720
dp = (b * gamma) / (a - gamma)
1821
return dp
1922

0 commit comments

Comments
 (0)