-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.py
More file actions
131 lines (105 loc) · 3.43 KB
/
util.py
File metadata and controls
131 lines (105 loc) · 3.43 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
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
############################List functions!
def listAP(incl8 = False):
from os import listdir
from read import makePath
try:
dirnames = listdir('AHPDATA')
except:
return
APs = [int(AP[2:]) for AP in dirnames]
if not incl8:
APs.remove(8)
APs.sort()
return APs
def listSS(AP, G, T):
'''List the available sample stations for a given AP, FIT and Traverse.'''
from os import listdir
from read import makePath
try:
dirnames = listdir(makePath(AP, 6, T))
except:
return #versatility in case no such AP/G/T exists.
dirnames.remove('Data')
ss = [int(station[2:]) for station in dirnames]
ss.sort()
return ss
def listT(AP, G):
'''List the available traverses for a given AP and FIT.
Basically, it returns [1, 2, 3].'''
T = range(1, 4)
return T
def listG(AP):
'''List the FITs for a given AP.'''
if AP == 13:
return range(1, 8)
else:
return range(1, 7)
################################Traverse functions!
###Note: for all traverse functions, remember to put the import statements
###within stmt
def traverseSS(AP, G, T, stmt):
'''Runs 'stmt' for *all* sample stations in a given AP, G, and T.'''
allSS = listSS(AP, G, T)
for S in allSS:
#provide some context for stmt to reference.
GTS = G*100 + T*10 + S
## try:
## exec(stmt)
## except:
## print 'Error -- did not run at AP{0}-{1}.'.format(AP, GTS)
exec(stmt)
def traverseT(AP, G, stmt):
'''Runs 'stmt' for all sample stations in a given AP and G.'''
allT = listT(AP, G)
for T in allT:
traverseSS(AP, G, T, stmt)
def traverseAP(AP, stmt):
'''Runs 'stmt' for all sample stations in a given AP.'''
allG = listG(AP)
for G in allG:
traverseT(AP, G, stmt)
def traverseAll(stmt):
'''Runs 'stmt' for *all* sample stations in all APs.'''
## for AP in range(8, 14):
## numG = listG(AP)
## for G in listG:
## numT = listT(AP, G)
## for T in numT:
## numSS = listSS(AP, G, T)
## for S in listSS:
##
## #Give stmt some context.
## GTS = G*100 + T * 10 + S
## try:
## exec(stmt)
## except:
## print 'Did not run properly for AP{0}-{1}'.format(AP, GTS)
for AP in listAP:
traverseAP(AP, stmt)
####################Using the traverse functions!
def forAllAPs(target, GTS):
'''Gets all the values of the target for all of that GTS through AP 8 - 13.
In other words, if you wanted 'Water pH', 622, it would get you that value
for Water pH in AP8-622, AP9-622, etc.
Returns a list of the format [AP8.val, AP9.val...AP13.val]. If no value
exists, None is put in its place.
'''
from extract import extract
l = [GTS]
#AP8 is not included because I am not satisfied with
#how PyAHP reads its data.
for AP in listAP():
l.append(extract(target, AP, GTS))
return l
def forAllAPsGTS(target):
'''Gets the value of the target for all GTSs for all APs.
Essentially, repeatedly calls forAllAPs.
'''
l = []
AP = 13 #reference AP
for G in listG(AP):
for T in listT(AP, G):
for S in listSS(AP, G, T):
GTS = G*100+T*10+S
l.append(forAllAPs(target, GTS))
return l