forked from hnrkp/pyWeatherLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversions.py
More file actions
50 lines (36 loc) · 1.25 KB
/
conversions.py
File metadata and controls
50 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
This file is part of the pyWeatherLink package,
Copyright 2008 by Henrik Persson <root@fulhack.info>.
pyWeatherLink is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
pyWeatherLink is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pyWeatherLink. If not, see <http://www.gnu.org/licenses/>.
"""
import math
def f2c(f):
c = (f-32) * (5.0/9.0)
return round(c, 1)
def mph2kts(mph):
kts = mph * 0.868976242
return int(round(kts, 0))
def mph2ms(mph):
ms = mph * 0.44704
return round(ms, 1)
def inHg2hPa(inHg):
return round(inHg * 33.8638816, 1)
# constants
a = 17.271
b = 237.7 # degC
def gamma(T,RH):
g = (a * T / (b + T)) + math.log(RH/100.0)
return g
def dewpoint_approximation(T, RH):
gm = gamma(T,RH)
Td = (b * gm) / (a - gm)
return round(Td, 1)