-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (37 loc) · 1.46 KB
/
main.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
import sys, os, subprocess
from modules import mergeTool, crop, ndvi, downloader, sort, subregion
def getPathRow(path, row):
'''
Return path/row in string format.
'''
return str(path) + str(row)
def main(regions):
sub_regions_raster = []
subprocesses = []
resume = False
for region in regions:
print 'Processing ' + region + ' subregion.'
sub_regions_raster.append('crop_sub_regions/' + region + '.tif')
FNULL = open(os.devnull, 'w')
subprocesses.append((subprocess.Popen(' '.join(['python', 'modules/subregion.py', region]),
shell=True, stdout=FNULL, stderr=FNULL), region))
for subprocesse, region in subprocesses:
subprocesse.wait()
print 'Finish ' + region + 'subregion.'
mergeTool.merge( sub_regions_raster, "", "NDVI_FINAL")
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Insufficient arguments. Use 'python main.py run|setup'"
elif sys.argv[1] == 'setup':
os.system("make -C modules/merge/")
os.system("make -C modules/ndvi/")
downloader.setup()
elif sys.argv[1] == 'run':
if not os.path.isfile('.secretFlag'):
os.system("find . -iname '.secretFlag' | xargs -n 1 rm -rf")
os.system("echo '' >.secretFlag")
regions = downloader.parse_path_and_rows('samples/semi-arid/path_row.txt').keys()
main(regions)
os.system('rm .secretFlag')
else:
print "Unsupported operation"