-
Notifications
You must be signed in to change notification settings - Fork 2
/
catalogResults.py
executable file
·225 lines (159 loc) · 6.42 KB
/
catalogResults.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env python
import os, glob, optparse, re, shutil, subprocess, sys, string, time
import simplekml
def parseBoundingBoxes(folder):
'''Gets the bounding box of one of our files'''
downloadLogPath = os.path.join(folder, 'downloadLog.txt')
# Search the download log for the bounding box
f = open(downloadLogPath, 'r')
imgFiles = []
minLon = None
minLat = None
maxLon = None
maxLat = None
for line in f:
if 'minLon' in line:
numStart = line.find(':') + 1
minLon = line[numStart:].strip()
if 'maxLon' in line:
numStart = line.find(':') + 1
maxLon = line[numStart:].strip()
if 'minLat' in line:
numStart = line.find(':') + 1
minLat = line[numStart:].strip()
if 'maxLat' in line:
numStart = line.find(':') + 1
maxLat = line[numStart:].strip()
f.close()
#if (abs(float(minLat)) > 60) or (abs(float(maxLat)) > 60):
# print 'lat > 60! --> ' + folder
# print minLat
# print maxLat
# Make sure we got all four values
if (not minLon) or (not minLat) or (not maxLon) or (not maxLat):
raise Exception('Could not find BB in folder ' + folder)
return (minLon, minLat, maxLon, maxLat)
def generateKml(outputPath, bbDict, colors):
'''Plots all of the bounding boxes with the specified colors'''
# Initialize kml document
kml = simplekml.Kml()
kml.document.name = 'DTM Locations'
kml.hint = 'target=moon'
#minError = min(asuMeanList)
#maxError = max(asuMeanList)
#errorRange = maxError - minError
# Try to set up bounding box for each used folder
i = 0
for key in bbDict:
(minLon, minLat, maxLon, maxLat) = bbDict[key]
poly = kml.newpolygon(name=key, outerboundaryis=[(minLon,maxLat), (maxLon,maxLat), (maxLon, minLat), (minLon,minLat), (minLon,maxLat)])
#if key == 'NAC_DTM_M188958772_M188987370':
# print key
# print bbDict[key]
# print poly
# poly.style.polystyle.color = simplekml.Color.red # Why is polygon not working?
# poly.style.polystyle.fill = 1
# poly.style.polystyle.outline = 1
poly.style.linestyle.width = 5
# For now just draw white lines
if colors[i] == 'red':
poly.style.linestyle.color = simplekml.Color.rgb(255,0,0,255)
else: # Default is white
poly.style.linestyle.color = simplekml.Color.rgb(255,255,255,255)
## Generate a color based on the error value: white (low error) <--> red (high error)
#colorVal = 255 - 255*(asuMeanList[i] - minError)/errorRange
#poly.style.linestyle.color = simplekml.Color.rgb(255,colorVal,colorVal,255)
i = i + 1
print i
# Save kml document
kml.save(outputPath)
def getInputImages(folder):
'''Find out the input images used in a given folder'''
downloadLogPath = os.path.join(folder, 'downloadLog.txt')
f = open(downloadLogPath, 'r')
imgFiles = []
for line in f:
if '.IMG' in line:
nameStart = line.rfind('/') + 1
imgName = line[nameStart:].strip()
imgFiles.append(imgName)
f.close()
if len(imgFiles) != 4:
raise Exception('Failed to find four IMG files in folder ' + folder)
return imgFiles
def getAsuImageList():
'''Returns dictionary containing input images for each ASU data set'''
sourceFile = '/u/smcmich1/projects/lronacPipeline/logFile.txt'
asuDict = {}
setName = None
f = open(sourceFile, 'r')
for line in f:
if 'ASU DTM' in line:
# Grab the name from the line
nameStart = line.rfind('/') + 1
setName = line[nameStart:].strip()
asuDict[setName] = []
if '.IMG' in line:
# Get the name and append to the list for this set
nameStart = line.rfind('/') + 1
imgName = line[nameStart:].strip()
asuDict[setName].append(imgName)
f.close()
#print asuDict
return(asuDict)
def findAsuMatches():
# Location of processed data
dataFolder = '/u/smcmich1/data/lronacProduction'
bbKmlPath = '/u/smcmich1/data/lronacProduction/boundingBoxes.kml'
print 'Building ASU dictionary...'
asuImageList = getAsuImageList()
print 'Looping through pipeline output...'
# Loop through all folders in the directory
foldersInDirectory = os.listdir(dataFolder)
foldersInDirectory.sort()
bbDict = {}
colors = []
for f in foldersInDirectory:
# Skip the other files in the directory
if 'NAC_DTM' not in f:
continue
folderPath = os.path.join(dataFolder, f)
if not os.path.exists(os.path.join(folderPath, 'output-CompressedInputs.tar.bz2')):
print 'Skipping incomplete folder ' + f
continue
try:
# Get the bounding box from the folder
bb = parseBoundingBoxes(folderPath)
# Get the list of input images used by that folder
imageList = getInputImages(folderPath)
except:
#print 'Folder ' + folderPath + ' is incomplete, skipping it!'
continue
bbDict[f] = bb
# Search for those images in the ASU list
allContained = True
for key in asuImageList: # Loop through all ASU data sets
for image in imageList: # Loop through all image for current folder
#print '-- ' + image
if image not in asuImageList[key]:
allContained = False
break
#else:
# print 'Matched image ' + image
if allContained:
print 'Folder ' + f + ' matched ASU data set ' + key
break
# Handle unmatched DTMs and assign color for KML plot
if not allContained:
colors.append('white')
#print 'Folder ' + f + ' did not match any data set'
else:
colors.append('red')
# Create a kml file containing the bounding box of each DTM
generateKml(bbKmlPath, bbDict, colors)
return 0
def main():
findAsuMatches()
pass
if __name__ == "__main__":
sys.exit(main())