-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUnitConversions.py
149 lines (133 loc) · 3.16 KB
/
UnitConversions.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import math
# FIXME: absolute vs specific conductivity - check with Ben
def identity(x):
x = str(x)
x = x.replace(" ","")
return x
def luxToLumens(x):
# formula: c * lux * A^2 = lumens
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = x.replace(",","")
x = float(x)
c = 0.09290304 # conversion constant
A = 1
Asqr = A * A
return c * x * Asqr
def lumensToLux(x):
# forumula: (10.76391 * x) / A^2
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = x.replace(",","")
x = float(x)
c = 10.76391 # conversion constant
A = 1
Asqr = A * A
return (c * x) / Asqr
def kpaTommHg(x):
x = str(x)
x = x.replace(" ","")
# formulat: kpa / .1333223684 = mmHg
if x == "":
return ""
x = float(x)
c = 0.1333223684 # conversion constant
return (x / c)
def mmHgTokpa(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c = 0.1333223684 # conversion constant
return (x * c)
def mmHgToatm(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c = 760 # conversion constant
return (x / c)
def psiTommHg(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c = 51.715 # conversion constant
return x * c
def mmHgTopsi(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c = 51.715 # conversion constant
return x / c
def celciusToKelvin(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c = 273.15 # conversion constant
return x + c
def calculateCp(mmHgPres, tempC):
# declare variables
pAtm = mmHgToatm(mmHgPres)
tempK = celciusToKelvin(tempC)
pwv = math.exp(11.8571 - (3840.70 / tempK) - (216961 / math.pow(tempK, 2)))
cStar = math.exp(7.7117 - (1.31403 * math.log(tempC + 45.93)))
theta = 9.75e-4 - (1.426e-5 * tempC) + (6.436e-8 * math.pow(tempC, 2))
# run the first equation
numerator = ((1 - (pwv / pAtm)) * (1 - theta * pAtm))
denominator = ((1 - pwv) * (1 - theta))
cp = cStar * pAtm * (numerator / denominator)
return cp
def doPercentTomgL(x, mmHgPres, tempC):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
cp = calculateCp(mmHgPres, tempC)
domgL = (cp * x) / 100
return domgL
def domgLToPercent(x, mmHgPres, tempC):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
cp = calculateCp(mmHgPres, tempC)
percentDo = (100 * x) / cp
return percentDo
def farenheitToCelcius(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c1 = (5.0 / 9.0)
c2 = 32
return (x - c2) * c1
def celciusToFarenheit(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c1 = (9.0 / 5.0)
c2 = 32
return ((x * c1) + c2)
def ppmTomgL(x):
x = str(x)
x = x.replace(" ","")
if x == "":
return ""
x = float(x)
c = 0.998859 # conversion constant (1 mg/L = 1ppm * .998859)
return x * c