ISCE_INSAR/applications/fixImageXml.py

53 lines
1.4 KiB
Python
Raw Normal View History

2019-01-16 19:40:08 +00:00
#!/usr/bin/env python3
import os
import argparse
2019-01-16 19:40:08 +00:00
import isce
import isceobj
from isceobj.Util.ImageUtil import ImageLib as IML
2019-01-16 19:40:08 +00:00
def cmdLineParse():
'''
Command line parser.
'''
parser = argparse.ArgumentParser(description='Fixes pathnames in ISCE image XML files. Can be used to do more things in the future.')
parser.add_argument('-i', '--input', type=str, required=True, dest='infile',
help = 'Input image for which the XML file needs to be fixed.')
fname = parser.add_mutually_exclusive_group(required=True)
fname.add_argument('-f', '--full', action='store_false',
2019-01-16 19:40:08 +00:00
help = 'Replace filename with full path including dir in which file is located')
fname.add_argument('-b', '--base', action='store_true',
2019-01-16 19:40:08 +00:00
help = 'Replace filename with basename to use in current directory')
inps = parser.parse_args()
return inps
if __name__ == '__main__':
'''
Main driver.
'''
inps = cmdLineParse()
if inps.infile.endswith('.xml'):
inps.infile = os.path.splitext(inps.infile)[0]
dirname = os.path.dirname(inps.infile)
img = IML.loadImage(inps.infile)[0]
2019-01-16 19:40:08 +00:00
if inps.full:
fname = os.path.abspath( os.path.join(dirname, os.path.basename(inps.infile)))
else:
fname = os.path.basename( os.path.basename(inps.infile))
2019-01-16 19:40:08 +00:00
img.filename = fname
img.setAccessMode('READ')
img.renderHdr()