From 17b22417fd7916a0a7c1bc28dee498accbc56d6a Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Mon, 23 Mar 2020 17:09:04 -0700 Subject: [PATCH] topo: add more arguments for runMultilookGdal() + add in_ext/out_ext/fbase_list for more flexibility + fix bug for .full.xml file copying when input/output are in the same directory --- contrib/stack/stripmapStack/topo.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/contrib/stack/stripmapStack/topo.py b/contrib/stack/stripmapStack/topo.py index 2b175a6..cadc6e6 100755 --- a/contrib/stack/stripmapStack/topo.py +++ b/contrib/stack/stripmapStack/topo.py @@ -401,7 +401,8 @@ def runMultilook(in_dir, out_dir, alks, rlks): return out_dir -def runMultilookGdal(in_dir, out_dir, alks, rlks): +def runMultilookGdal(in_dir, out_dir, alks, rlks, in_ext='.rdr', out_ext='.rdr', + fbase_list=['hgt', 'incLocal', 'lat', 'lon', 'los', 'shadowMask', 'waterMask']): print('generate multilooked geometry files with alks={} and rlks={}'.format(alks, rlks)) import gdal @@ -411,10 +412,9 @@ def runMultilookGdal(in_dir, out_dir, alks, rlks): print('create directory: {}'.format(out_dir)) # multilook files one by one - for fbase in ['hgt', 'incLocal', 'lat', 'lon', 'los', 'shadowMask', 'waterMask']: - fname = '{}.rdr'.format(fbase) - in_file = os.path.join(in_dir, fname) - out_file = os.path.join(out_dir, fname) + for fbase in fbase_list: + in_file = os.path.join(in_dir, '{}{}'.format(fbase, in_ext)) + out_file = os.path.join(out_dir, '{}{}'.format(fbase, out_ext)) if os.path.isfile(in_file): ds = gdal.Open(in_file, gdal.GA_ReadOnly) @@ -434,8 +434,9 @@ def runMultilookGdal(in_dir, out_dir, alks, rlks): # copy the full resolution xml/vrt file from ./merged/geom_master to ./geom_master # to facilitate the number of looks extraction # the file path inside .xml file is not, but should, updated - shutil.copy(in_file+'.xml', out_file+'.full.xml') - shutil.copy(in_file+'.vrt', out_file+'.full.vrt') + if in_file != out_file+'.full': + shutil.copy(in_file+'.xml', out_file+'.full.xml') + shutil.copy(in_file+'.vrt', out_file+'.full.vrt') return out_dir