-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairupindex.py
74 lines (61 loc) · 2.2 KB
/
airupindex.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
tableAqiIndex = [ range(0, 50, 1),range(51, 100, 1),range(101, 150, 1),range(151, 200, 1),range(201, 300, 1),range(301, 400, 1),range(401, 500, 1) ]
tableCo = [ range(0, 44, 1),range(45, 94, 1),range(95, 124, 1),range(125, 154, 1),range(155, 304, 1),range(305, 404, 1),range(405, 504, 1) ]
tableNo2 = [ range(0, 53, 1),range(54, 100, 1),range(101, 360, 1),range(361, 640, 1),range(650, 1240, 1),range(1250, 1640, 1),range(1650, 2040, 1) ]
tablePm10 = [ range(0, 54, 1),range(55, 154, 1),range(155, 254, 1),range(255, 354, 1),range(355, 424, 1),range(425, 504, 1),range(505, 604, 1) ]
#Verify pm25 and o3
tablePm25 = [ range(0, 54, 1),range(55, 154, 1),range(155, 254, 1),range(255, 354, 1),range(355, 424, 1),range(425, 504, 1),range(505, 604, 1) ]
table=3 = [ range(0, 44, 1),range(45, 94, 1),range(95, 124, 1),range(125, 154, 1),range(155, 304, 1),range(305, 404, 1),range(405, 504, 1) ]
def index(table, v, fac):
row = [i for i,l in enumerate(table) if int(v*fac) in l][0]
bpLow = float(table[row][0])/fac
bpHigh = (float(table[row][len(table[row])-1]+1)/fac)
iLow = tableAqiIndex[row][0]
iHigh = tableAqiIndex[row][len(tableAqiIndex[row])-1]+1
index = (
(float(iHigh) - float(iLow)) /
(float(bpHigh) - float(bpLow))
) * (float(v)-(float(bpLow))) + float(iLow)
return int(index)
def aqi(values):
print "---------------------------------"
co=values["co"]
pm10=values["pm10"]
pm25=values["pm25"]
o3=values["o3"]
no2=values["no2"]
f = 0
coIndex = 0
pm10Index = 0
pm25Index = 0
o3Index = 0
no2Index = 0
if co:
coIndex = index(tableCo, co, 10)
f = f+1
print coIndex
if pm10:
pm10Index = index(tablePm10, pm10, 1)
f = f+1
print pm10Index
if pm25:
pm25Index = index(tablePm25, pm25, 1)
f = f+1
print pm25Index
if o3:
o3Index = index(tableO3, o3, 1)
f = f+1
print o3Index
if no2:
no2Index = index(tableNo2, no2, 1000)
f = f+1
print no2Index
if f > 0:
return (coIndex + pm10Index + pm25Index + o3Index + no2Index)/f
#Examples
#co(ppm)0-50.4(GBG-ex:3.86)
#pm10(micro-g/m3)
#no2(ppm) 0-2.4
print aqi({"co":50,"pm10":600,"pm25":600,"O3":4,"no2":2})
#print aqi({"co":25,"pm10":None,"no2":1.123})
#print aqi({"co":25,"pm10":None,"no2":None})
#print aqi({"co":4.123,"pm10":None,"no2":0.024})