-
Notifications
You must be signed in to change notification settings - Fork 8
/
processCtxPair.py
executable file
·136 lines (103 loc) · 4.76 KB
/
processCtxPair.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# __BEGIN_LICENSE__
# Copyright (c) 2009-2013, United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration. All
# rights reserved.
#
# The NGT platform is licensed under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# __END_LICENSE__
import sys, os, glob, optparse, re, shutil, subprocess, string, time
def man(option, opt, value, parser):
print >>sys.stderr, parser.usage
print >>sys.stderr, '''\
Generates a stereo DEM from two LRONAC pairs using SBA and LOLA for increased accuracy.
'''
sys.exit()
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
#--------------------------------------------------------------------------------
def replaceExtensionAndFolder(inputPath, outputFolder, newExtension):
newExt = os.path.splitext(inputPath)[0] + newExtension
return os.path.join(outputFolder, os.path.basename(newExt))
def prepareImage(inputPath, workDir, keep):
"""Prepare a single CTX image for processing"""
# Set up paths
cubPath = replaceExtensionAndFolder(inputPath, workDir, '.cub')
calPath = replaceExtensionAndFolder(inputPath, workDir, '.cal.cub')
# Convert to ISIS format
cmd = 'mroctx2isis from=' + inputPath + ' to=' + cubPath
os.system(cmd)
# Init Spice data
cmd = 'spiceinit from=' + cubPath
os.system(cmd)
# Apply image correction
cmd = 'ctxcal from='+cubPath+' to='+calPath
os.system(cmd)
#you can also optionally run} ctxevenodd \textnormal{on the} cal.cub \textnormal{files, if needed}
if not keep:
os.remove(cubPath)
return calPath
def main():
print '#################################################################################'
print "Running processCtxPair.py"
try:
try:
usage = "usage: processCtxPair.py <left image> <right image> <output prefix> [--workDir <folder>][--keep][--manual]\n "
parser = optparse.OptionParser(usage=usage)
parser.set_defaults(keep=False)
parser.add_option("--workDir", dest="workDir", help="Folder to place intermediate files in")
parser.add_option("--manual", action="callback", callback=man,
help="Read the manual.")
parser.add_option("--keep", action="store_true", dest="keep",
help="Do not delete the temporary files.")
(options, args) = parser.parse_args()
if len(args) < 3:
parser.error('Missing required input!')
options.leftPath = args[0]
options.rightPath = args[1]
options.outputPrefix = args[2]
if not options.workDir:
options.workDir = os.path.dirname(options.outputPrefix)
except optparse.OptionError, msg:
raise Usage(msg)
startTime = time.time()
# Do individual input image preparations
leftCalPath = prepareImage(options.leftPath, options.workDir, options.keep)
rightCalPath = prepareImage(options.rightPath, options.workDir, options.keep)
# Do joint prepration
cmd = 'cam2map4stereo.py ' + leftCalPath + ' ' + rightCalPath
os.system(cmd)
leftMapPath = replaceExtensionAndFolder(options.leftPath, workDir, '.map.cub')
rightMapPath = replaceExtensionAndFolder(options.rightPath, workDir, '.map.cub')
# Final stereo call
cmd = ('parallel_stereo.py ' + leftMapPath + ' ' + rightMapPath + ' ' + options.outputPrefix
+ ' --alignment affineepipolar --subpixel-mode 3 --corr-timeout 400'
+ ' --filter-mode 1 --subpixel-max-levels 0')
os.system(cmd)
# Clean up temporary files
if not options.keep:
os.remove(leftCalPath)
os.remove(rightCalPath)
os.remove(leftMapPath)
os.remove(rightMapPath)
endTime = time.time()
print "Finished in " + str(endTime - startTime) + " seconds."
print '#################################################################################'
return 0
except Usage, err:
print err
print >>sys.stderr, err.msg
return 2
if __name__ == "__main__":
sys.exit(main())