From 077615a59194c659330f422c9f81d3e43b33e3d5 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Thu, 13 Apr 2023 17:19:56 -0700 Subject: [PATCH 1/8] adding scripts -preparing ERS for stack processing --- .../stripmapStack/prepareERS_ENVstack.py | 91 +++++++++++++++++++ .../stripmapStack/unpackFrame_ERS_ENV.py | 84 +++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100755 contrib/stack/stripmapStack/prepareERS_ENVstack.py create mode 100755 contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py diff --git a/contrib/stack/stripmapStack/prepareERS_ENVstack.py b/contrib/stack/stripmapStack/prepareERS_ENVstack.py new file mode 100755 index 000000000..5743cba4c --- /dev/null +++ b/contrib/stack/stripmapStack/prepareERS_ENVstack.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +# modified to pass the segment number to unpackFrame_UAVSAR EJF 2020/08/02 +# modified to work for different UAVSAR stack segments EJF 2019/05/04 + +import os +import glob +import argparse + +import isce +import isceobj +import shelve +from isceobj.Util.decorators import use_api + +def createParser(): + ''' + Create command line parser. + ''' + + parser = argparse.ArgumentParser(description='Prepare ESA ERS Stack files.') + parser.add_argument('-i', '--input', dest='input', type=str, required=True, + help='directory which has all dates.') + parser.add_argument('-o', '--output', dest='output', type=str, required=True, + help='output directory which will be used for unpacking.') + parser.add_argument('--orbitdir', dest='orbitdir', type=str, required=True, help='Orbit directory') + parser.add_argument('-t', '--text_cmd', dest='text_cmd', type=str, default='source ~/.bash_profile;', + help='text command to be added to the beginning of each line of the run files. Default: source ~/.bash_profile;') + + return parser + + +def cmdLineParse(iargs=None): + ''' + Command line parser. + ''' + + parser = createParser() + return parser.parse_args(args = iargs) + +def write_xml(shelveFile, slcFile): + with shelve.open(shelveFile,flag='r') as db: + frame = db['frame'] + + length = frame.numberOfLines + width = frame.numberOfSamples + print (width,length) + + slc = isceobj.createSlcImage() + slc.setWidth(width) + slc.setLength(length) + slc.filename = slcFile + slc.setAccessMode('write') + slc.renderHdr() + slc.renderVRT() + + +def get_Date(file): + yyyymmdd=file[14:22] + return yyyymmdd + +def main(iargs=None): + ''' + The main driver. + ''' + + inps = cmdLineParse(iargs) + + outputDir = os.path.abspath(inps.output) + + ####################################### + slc_files = glob.glob(os.path.join(inps.input, 'SAR*.E*')) + for file in slc_files: + imgDate = get_Date(os.path.basename(file)) + print (imgDate) + + imgDir = os.path.join(outputDir,imgDate) + os.makedirs(imgDir, exist_ok=True) + + cmd = 'unpackFrame_ERS_ENV.py -i ' + inps.input +' -o ' + imgDir + ' --orbitdir ' + inps.orbitdir + print (cmd) + os.system(cmd) + + slcFile = os.path.join(imgDir, imgDate+'.slc') + + shelveFile = os.path.join(imgDir, 'data') + write_xml(shelveFile, slcFile) + +if __name__ == '__main__': + + main() + + diff --git a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py new file mode 100755 index 000000000..7b7befcb7 --- /dev/null +++ b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 + +import isce +from isceobj.Sensor import createSensor +import shelve +import argparse +import glob +from isceobj.Util import Poly1D +from isceobj.Planet.AstronomicalHandbook import Const +import os +import datetime +import numpy as np + +def cmdLineParse(): + ''' + Command line parser. + ''' + + parser = argparse.ArgumentParser(description='Unpack ERS(ESA) SLC data and store metadata in pickle file.') + parser.add_argument('-i','--input', dest='datadir', type=str, + required=True, help='Input ERS directory') + parser.add_argument('-o', '--output', dest='slcdir', type=str, + required=True, help='Output SLC directory') + parser.add_argument('--orbitdir', dest='orbitdir', type=str,required=True, help='Orbit directory') + + return parser.parse_args() + + +def unpack(hdf5, slcname, orbitdir): + ''' + Unpack HDF5 to binary SLC file. + ''' + + fname = glob.glob(os.path.join(hdf5,'SAR*.E*'))[0] + if not os.path.isdir(slcname): + os.mkdir(slcname) + + date = os.path.basename(slcname) + + obj = createSensor('ERS_ENviSAT_SLC') + obj._imageFileName = fname + obj.orbitDir = orbitdir + #obj.instrumentDir = '/Users/agram/orbit/INS_DIR' + obj.output = os.path.join(slcname, date+'.slc') + + obj.extractImage() + obj.frame.getImage().renderHdr() + + #### computation of "poly" adapted from line 339 - line 353 of isceobj/Sensor/ERS_EnviSAT_SLC.py ### + coeffs = obj.dopplerRangeTime + dr = obj.frame.getInstrument().getRangePixelSize() + rref = 0.5 * Const.c * obj.rangeRefTime + r0 = obj.frame.getStartingRange() + norm = 0.5 * Const.c / dr + + dcoeffs = [] + for ind, val in enumerate(coeffs): + dcoeffs.append( val / (norm**ind)) + + poly = Poly1D.Poly1D() + poly.initPoly(order=len(coeffs)-1) + poly.setMean( (rref - r0)/dr - 1.0) + poly.setCoeffs(dcoeffs) + + + pickName = os.path.join(slcname, 'data') + with shelve.open(pickName) as db: + db['frame'] = obj.frame + db['doppler'] = poly + + +if __name__ == '__main__': + ''' + Main driver. + ''' + + inps = cmdLineParse() + if inps.slcdir.endswith('/'): + inps.slcdir = inps.slcdir[:-1] + + if inps.datadir.endswith('/'): + inps.datadir = inps.datadir[:-1] + + unpack(inps.datadir, inps.slcdir, inps.orbitdir) From 1be3ad796ca64feaa83e5fdafd1a7ebf51804b81 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Mon, 17 Apr 2023 21:44:29 -0700 Subject: [PATCH 2/8] Combine prepareERS_ENVstack,py with unpackFrame_ERS_ENV.py in the latter. --- .../stripmapStack/prepareERS_ENVstack.py | 91 ------------------- .../stripmapStack/unpackFrame_ERS_ENV.py | 36 ++++---- 2 files changed, 18 insertions(+), 109 deletions(-) delete mode 100755 contrib/stack/stripmapStack/prepareERS_ENVstack.py diff --git a/contrib/stack/stripmapStack/prepareERS_ENVstack.py b/contrib/stack/stripmapStack/prepareERS_ENVstack.py deleted file mode 100755 index 5743cba4c..000000000 --- a/contrib/stack/stripmapStack/prepareERS_ENVstack.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python3 -# modified to pass the segment number to unpackFrame_UAVSAR EJF 2020/08/02 -# modified to work for different UAVSAR stack segments EJF 2019/05/04 - -import os -import glob -import argparse - -import isce -import isceobj -import shelve -from isceobj.Util.decorators import use_api - -def createParser(): - ''' - Create command line parser. - ''' - - parser = argparse.ArgumentParser(description='Prepare ESA ERS Stack files.') - parser.add_argument('-i', '--input', dest='input', type=str, required=True, - help='directory which has all dates.') - parser.add_argument('-o', '--output', dest='output', type=str, required=True, - help='output directory which will be used for unpacking.') - parser.add_argument('--orbitdir', dest='orbitdir', type=str, required=True, help='Orbit directory') - parser.add_argument('-t', '--text_cmd', dest='text_cmd', type=str, default='source ~/.bash_profile;', - help='text command to be added to the beginning of each line of the run files. Default: source ~/.bash_profile;') - - return parser - - -def cmdLineParse(iargs=None): - ''' - Command line parser. - ''' - - parser = createParser() - return parser.parse_args(args = iargs) - -def write_xml(shelveFile, slcFile): - with shelve.open(shelveFile,flag='r') as db: - frame = db['frame'] - - length = frame.numberOfLines - width = frame.numberOfSamples - print (width,length) - - slc = isceobj.createSlcImage() - slc.setWidth(width) - slc.setLength(length) - slc.filename = slcFile - slc.setAccessMode('write') - slc.renderHdr() - slc.renderVRT() - - -def get_Date(file): - yyyymmdd=file[14:22] - return yyyymmdd - -def main(iargs=None): - ''' - The main driver. - ''' - - inps = cmdLineParse(iargs) - - outputDir = os.path.abspath(inps.output) - - ####################################### - slc_files = glob.glob(os.path.join(inps.input, 'SAR*.E*')) - for file in slc_files: - imgDate = get_Date(os.path.basename(file)) - print (imgDate) - - imgDir = os.path.join(outputDir,imgDate) - os.makedirs(imgDir, exist_ok=True) - - cmd = 'unpackFrame_ERS_ENV.py -i ' + inps.input +' -o ' + imgDir + ' --orbitdir ' + inps.orbitdir - print (cmd) - os.system(cmd) - - slcFile = os.path.join(imgDir, imgDate+'.slc') - - shelveFile = os.path.join(imgDir, 'data') - write_xml(shelveFile, slcFile) - -if __name__ == '__main__': - - main() - - diff --git a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py index 7b7befcb7..2ba6643c1 100755 --- a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py +++ b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py @@ -18,35 +18,32 @@ def cmdLineParse(): parser = argparse.ArgumentParser(description='Unpack ERS(ESA) SLC data and store metadata in pickle file.') parser.add_argument('-i','--input', dest='datadir', type=str, - required=True, help='Input ERS directory') + required=True, help='Input ERS files path') parser.add_argument('-o', '--output', dest='slcdir', type=str, required=True, help='Output SLC directory') parser.add_argument('--orbitdir', dest='orbitdir', type=str,required=True, help='Orbit directory') return parser.parse_args() +def get_Date(file): + yyyymmdd=file[14:22] + return yyyymmdd -def unpack(hdf5, slcname, orbitdir): +def unpack(fname, slcname, orbitdir): ''' - Unpack HDF5 to binary SLC file. + Unpack .E* file to binary SLC file. ''' - fname = glob.glob(os.path.join(hdf5,'SAR*.E*'))[0] - if not os.path.isdir(slcname): - os.mkdir(slcname) - - date = os.path.basename(slcname) - obj = createSensor('ERS_ENviSAT_SLC') obj._imageFileName = fname - obj.orbitDir = orbitdir + obj._orbitDir = orbitdir + obj._orbitType = 'ODR' #obj.instrumentDir = '/Users/agram/orbit/INS_DIR' - obj.output = os.path.join(slcname, date+'.slc') - + obj.output = os.path.join(slcname,os.path.basename(slcname)+'.slc') obj.extractImage() obj.frame.getImage().renderHdr() - #### computation of "poly" adapted from line 339 - line 353 of isceobj/Sensor/ERS_EnviSAT_SLC.py ### + #### computation of "poly" adapted from line 339 - line 353 of Components/isceobj/Sensor/ERS_EnviSAT_SLC.py ### coeffs = obj.dopplerRangeTime dr = obj.frame.getInstrument().getRangePixelSize() rref = 0.5 * Const.c * obj.rangeRefTime @@ -77,8 +74,11 @@ def unpack(hdf5, slcname, orbitdir): inps = cmdLineParse() if inps.slcdir.endswith('/'): inps.slcdir = inps.slcdir[:-1] - - if inps.datadir.endswith('/'): - inps.datadir = inps.datadir[:-1] - - unpack(inps.datadir, inps.slcdir, inps.orbitdir) + if not os.path.isdir(inps.slcdir): + os.mkdir(inps.slcdir) + for fname in glob.glob(os.path.join(inps.datadir, '*.E*')): + date = get_Date(os.path.basename(fname)) + slcname = os.path.join(inps.slcdir, date) + if not os.path.isdir(slcname): + os.mkdir(slcname) + unpack(fname, slcname, inps.orbitdir) From 84b7a4f354610d907700fe7c41dcbc87093e1c29 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Wed, 19 Apr 2023 11:48:50 -0700 Subject: [PATCH 3/8] Fix bugs --- .../stripmapStack/unpackFrame_ERS_ENV.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py index 2ba6643c1..3e46b1099 100755 --- a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py +++ b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py @@ -2,6 +2,7 @@ import isce from isceobj.Sensor import createSensor +import isceobj import shelve import argparse import glob @@ -29,6 +30,22 @@ def get_Date(file): yyyymmdd=file[14:22] return yyyymmdd +def write_xml(shelveFile, slcFile): + with shelve.open(shelveFile,flag='r') as db: + frame = db['frame'] + + length = frame.numberOfLines + width = frame.numberOfSamples + print (width,length) + + slc = isceobj.createSlcImage() + slc.setWidth(width) + slc.setLength(length) + slc.filename = slcFile + slc.setAccessMode('write') + slc.renderHdr() + slc.renderVRT() + def unpack(fname, slcname, orbitdir): ''' Unpack .E* file to binary SLC file. @@ -78,7 +95,13 @@ def unpack(fname, slcname, orbitdir): os.mkdir(inps.slcdir) for fname in glob.glob(os.path.join(inps.datadir, '*.E*')): date = get_Date(os.path.basename(fname)) - slcname = os.path.join(inps.slcdir, date) - if not os.path.isdir(slcname): - os.mkdir(slcname) + slcname = os.path.abspath(os.path.join(inps.slcdir, date)) + os.makedirs(slcname, exist_ok=True) + + print(fname) unpack(fname, slcname, inps.orbitdir) + + slcFile = os.path.abspath(os.path.join(slcname, date+'.slc')) + + shelveFile = os.path.join(slcname, 'data') + write_xml(shelveFile,slcFile) From 9bf4721b10ad7e8f9019ff05dcadf301e3f8eda3 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Thu, 27 Apr 2023 10:57:18 -0700 Subject: [PATCH 4/8] Add geolocation constraint option --- .../stripmapStack/unpackFrame_ERS_ENV.py | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py index 3e46b1099..78b143b4d 100755 --- a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py +++ b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py @@ -20,6 +20,8 @@ def cmdLineParse(): parser = argparse.ArgumentParser(description='Unpack ERS(ESA) SLC data and store metadata in pickle file.') parser.add_argument('-i','--input', dest='datadir', type=str, required=True, help='Input ERS files path') + parser.add_argument('-b', '--box' ,dest='bbox', type=float, nargs=4, default=None, + help='Bbox (SNWE in degrees)') parser.add_argument('-o', '--output', dest='slcdir', type=str, required=True, help='Output SLC directory') parser.add_argument('--orbitdir', dest='orbitdir', type=str,required=True, help='Orbit directory') @@ -59,28 +61,30 @@ def unpack(fname, slcname, orbitdir): obj.output = os.path.join(slcname,os.path.basename(slcname)+'.slc') obj.extractImage() obj.frame.getImage().renderHdr() - - #### computation of "poly" adapted from line 339 - line 353 of Components/isceobj/Sensor/ERS_EnviSAT_SLC.py ### - coeffs = obj.dopplerRangeTime - dr = obj.frame.getInstrument().getRangePixelSize() - rref = 0.5 * Const.c * obj.rangeRefTime - r0 = obj.frame.getStartingRange() - norm = 0.5 * Const.c / dr - - dcoeffs = [] - for ind, val in enumerate(coeffs): - dcoeffs.append( val / (norm**ind)) + obj.extractDoppler() + + # #### computation of "poly" adapted from line 339 - line 353 of Components/isceobj/Sensor/ERS_EnviSAT_SLC.py ### + ####### removed this section and added obj.extractDoppler() above instead. Doesn't seem to change anything in the processing. The latter is required for cropFrame. + # coeffs = obj.dopplerRangeTime + # dr = obj.frame.getInstrument().getRangePixelSize() + # rref = 0.5 * Const.c * obj.rangeRefTime + # r0 = obj.frame.getStartingRange() + # norm = 0.5 * Const.c / dr + + # dcoeffs = [] + # for ind, val in enumerate(coeffs): + # dcoeffs.append( val / (norm**ind)) - poly = Poly1D.Poly1D() - poly.initPoly(order=len(coeffs)-1) - poly.setMean( (rref - r0)/dr - 1.0) - poly.setCoeffs(dcoeffs) + # poly = Poly1D.Poly1D() + # poly.initPoly(order=len(coeffs)-1) + # poly.setMean( (rref - r0)/dr - 1.0) + # poly.setCoeffs(dcoeffs) pickName = os.path.join(slcname, 'data') with shelve.open(pickName) as db: db['frame'] = obj.frame - db['doppler'] = poly + # db['doppler'] = poly if __name__ == '__main__': @@ -105,3 +109,11 @@ def unpack(fname, slcname, orbitdir): shelveFile = os.path.join(slcname, 'data') write_xml(shelveFile,slcFile) + + if inps.bbox is not None: + slccropname = os.path.abspath(os.path.join(inps.slcdir+'_crop',date)) + os.makedirs(slccropname, exist_ok=True) + cmd = 'cropFrame.py -i {} -o {} -b {}'.format(slcname, slccropname, ' '.join([str(x) for x in inps.bbox])) + print(cmd) + os.system(cmd) + \ No newline at end of file From 5d62ff7abd69a278cbbd0879ad618cc42f19ff0a Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Thu, 4 May 2023 14:26:45 -0700 Subject: [PATCH 5/8] Update unpackFrame_ERS_ENV.py Added orbit data type --- contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py index 78b143b4d..300c55174 100755 --- a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py +++ b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py @@ -24,8 +24,8 @@ def cmdLineParse(): help='Bbox (SNWE in degrees)') parser.add_argument('-o', '--output', dest='slcdir', type=str, required=True, help='Output SLC directory') - parser.add_argument('--orbitdir', dest='orbitdir', type=str,required=True, help='Orbit directory') - + parser.add_argument('--orbitdir', dest='orbitdir', type=str, required=True, help='Orbit directory') + parser.add_argument('--orbittype',dest='orbittype', type = str, default='ODR', help='ODR, PDS, PDS') return parser.parse_args() def get_Date(file): @@ -48,7 +48,7 @@ def write_xml(shelveFile, slcFile): slc.renderHdr() slc.renderVRT() -def unpack(fname, slcname, orbitdir): +def unpack(fname, slcname, orbitdir, orbittype): ''' Unpack .E* file to binary SLC file. ''' @@ -56,7 +56,7 @@ def unpack(fname, slcname, orbitdir): obj = createSensor('ERS_ENviSAT_SLC') obj._imageFileName = fname obj._orbitDir = orbitdir - obj._orbitType = 'ODR' + obj._orbitType = orbittype #obj.instrumentDir = '/Users/agram/orbit/INS_DIR' obj.output = os.path.join(slcname,os.path.basename(slcname)+'.slc') obj.extractImage() @@ -103,7 +103,7 @@ def unpack(fname, slcname, orbitdir): os.makedirs(slcname, exist_ok=True) print(fname) - unpack(fname, slcname, inps.orbitdir) + unpack(fname, slcname, inps.orbitdir, inps.orbittype) slcFile = os.path.abspath(os.path.join(slcname, date+'.slc')) From 704085dc0d06391ce299e2b34b2d6bb8ab4684b8 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Thu, 4 May 2023 15:06:21 -0700 Subject: [PATCH 6/8] Update ODR.py The arclist file in the more complete ODR orbit files downloaded from http://www.deos.tudelft.nl/AS/pieter/Local/ERS/index.html (contains ERS-2 orbit files beyond 2003) has slight format change and the original hard coded line parser no longer works. The updated version should work both for the new and old versions of arclist. --- components/isceobj/Orbit/ODR.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/components/isceobj/Orbit/ODR.py b/components/isceobj/Orbit/ODR.py index 570f09362..c956f3d23 100644 --- a/components/isceobj/Orbit/ODR.py +++ b/components/isceobj/Orbit/ODR.py @@ -184,15 +184,17 @@ def parse(self): def parseLine(self,line): arc = Arc() - arc.number = line[0:3] # Arc number - arc.start = datetime.datetime.strptime(line[5:17],'%y%m%d %H:%M') # Starting time for the arc - arc.stop = datetime.datetime.strptime(line[20:32],'%y%m%d %H:%M') # End time for the arc - arc.slrResidual = line[34:38] # Satellite laser ranging residual in cm - arc.crossOver = line[39:43] - arc.altimeter = line[45:49] - arc.repeat = line[51:57] # Repeat cycle in days - arc.version = line[58:61] # Version number - arc.precise = datetime.datetime.strptime(line[63:78],'%y%m%d %H:%M:%S') # Starting time of the precise segment of the arc + ###### Change to also work for the new arclist format in the recalcuated ODR orbit files.####### + arc.number = line.split()[0] # Arc number + arc.start = datetime.datetime.strptime(" ".join(line.split()[1:3]),'%y%m%d %H:%M') # Starting time for the arc + arc.stop = datetime.datetime.strptime(" ".join(line.split()[4:6]),'%y%m%d %H:%M') # End time for the arc + ###### commented the following because it is not always present in the new arclist file ############ + # arc.slrResidual = line[34:38] # Satellite laser ranging residual in cm + # arc.crossOver = line[39:43] + # arc.altimeter = line[45:49] + # arc.repeat = line[51:57] # Repeat cycle in days + # arc.version = line[58:61] # Version number + arc.precise = datetime.datetime.strptime(" ".join(line.split()[-2:]),'%y%m%d %H:%M:%S') # Starting time of the precise segment of the arc return arc From 2de84c00ad06ed0774474d597d2ec8d7937cf040 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Thu, 13 Apr 2023 17:19:56 -0700 Subject: [PATCH 7/8] adding scripts -preparing ERS for stack processing --- .../stripmapStack/prepareERS_ENVstack.py | 91 +++++++++++++++++++ .../stripmapStack/unpackFrame_ERS_ENV.py | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100755 contrib/stack/stripmapStack/prepareERS_ENVstack.py diff --git a/contrib/stack/stripmapStack/prepareERS_ENVstack.py b/contrib/stack/stripmapStack/prepareERS_ENVstack.py new file mode 100755 index 000000000..5743cba4c --- /dev/null +++ b/contrib/stack/stripmapStack/prepareERS_ENVstack.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +# modified to pass the segment number to unpackFrame_UAVSAR EJF 2020/08/02 +# modified to work for different UAVSAR stack segments EJF 2019/05/04 + +import os +import glob +import argparse + +import isce +import isceobj +import shelve +from isceobj.Util.decorators import use_api + +def createParser(): + ''' + Create command line parser. + ''' + + parser = argparse.ArgumentParser(description='Prepare ESA ERS Stack files.') + parser.add_argument('-i', '--input', dest='input', type=str, required=True, + help='directory which has all dates.') + parser.add_argument('-o', '--output', dest='output', type=str, required=True, + help='output directory which will be used for unpacking.') + parser.add_argument('--orbitdir', dest='orbitdir', type=str, required=True, help='Orbit directory') + parser.add_argument('-t', '--text_cmd', dest='text_cmd', type=str, default='source ~/.bash_profile;', + help='text command to be added to the beginning of each line of the run files. Default: source ~/.bash_profile;') + + return parser + + +def cmdLineParse(iargs=None): + ''' + Command line parser. + ''' + + parser = createParser() + return parser.parse_args(args = iargs) + +def write_xml(shelveFile, slcFile): + with shelve.open(shelveFile,flag='r') as db: + frame = db['frame'] + + length = frame.numberOfLines + width = frame.numberOfSamples + print (width,length) + + slc = isceobj.createSlcImage() + slc.setWidth(width) + slc.setLength(length) + slc.filename = slcFile + slc.setAccessMode('write') + slc.renderHdr() + slc.renderVRT() + + +def get_Date(file): + yyyymmdd=file[14:22] + return yyyymmdd + +def main(iargs=None): + ''' + The main driver. + ''' + + inps = cmdLineParse(iargs) + + outputDir = os.path.abspath(inps.output) + + ####################################### + slc_files = glob.glob(os.path.join(inps.input, 'SAR*.E*')) + for file in slc_files: + imgDate = get_Date(os.path.basename(file)) + print (imgDate) + + imgDir = os.path.join(outputDir,imgDate) + os.makedirs(imgDir, exist_ok=True) + + cmd = 'unpackFrame_ERS_ENV.py -i ' + inps.input +' -o ' + imgDir + ' --orbitdir ' + inps.orbitdir + print (cmd) + os.system(cmd) + + slcFile = os.path.join(imgDir, imgDate+'.slc') + + shelveFile = os.path.join(imgDir, 'data') + write_xml(shelveFile, slcFile) + +if __name__ == '__main__': + + main() + + diff --git a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py index 300c55174..8e620cdab 100755 --- a/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py +++ b/contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py @@ -116,4 +116,4 @@ def unpack(fname, slcname, orbitdir, orbittype): cmd = 'cropFrame.py -i {} -o {} -b {}'.format(slcname, slccropname, ' '.join([str(x) for x in inps.bbox])) print(cmd) os.system(cmd) - \ No newline at end of file + From f226619ff13f345be1b27bbcf60242a1d3a862d9 Mon Sep 17 00:00:00 2001 From: Yujie Zheng Date: Mon, 17 Apr 2023 21:44:29 -0700 Subject: [PATCH 8/8] Combine prepareERS_ENVstack,py with unpackFrame_ERS_ENV.py in the latter. --- .../stripmapStack/prepareERS_ENVstack.py | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100755 contrib/stack/stripmapStack/prepareERS_ENVstack.py diff --git a/contrib/stack/stripmapStack/prepareERS_ENVstack.py b/contrib/stack/stripmapStack/prepareERS_ENVstack.py deleted file mode 100755 index 5743cba4c..000000000 --- a/contrib/stack/stripmapStack/prepareERS_ENVstack.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python3 -# modified to pass the segment number to unpackFrame_UAVSAR EJF 2020/08/02 -# modified to work for different UAVSAR stack segments EJF 2019/05/04 - -import os -import glob -import argparse - -import isce -import isceobj -import shelve -from isceobj.Util.decorators import use_api - -def createParser(): - ''' - Create command line parser. - ''' - - parser = argparse.ArgumentParser(description='Prepare ESA ERS Stack files.') - parser.add_argument('-i', '--input', dest='input', type=str, required=True, - help='directory which has all dates.') - parser.add_argument('-o', '--output', dest='output', type=str, required=True, - help='output directory which will be used for unpacking.') - parser.add_argument('--orbitdir', dest='orbitdir', type=str, required=True, help='Orbit directory') - parser.add_argument('-t', '--text_cmd', dest='text_cmd', type=str, default='source ~/.bash_profile;', - help='text command to be added to the beginning of each line of the run files. Default: source ~/.bash_profile;') - - return parser - - -def cmdLineParse(iargs=None): - ''' - Command line parser. - ''' - - parser = createParser() - return parser.parse_args(args = iargs) - -def write_xml(shelveFile, slcFile): - with shelve.open(shelveFile,flag='r') as db: - frame = db['frame'] - - length = frame.numberOfLines - width = frame.numberOfSamples - print (width,length) - - slc = isceobj.createSlcImage() - slc.setWidth(width) - slc.setLength(length) - slc.filename = slcFile - slc.setAccessMode('write') - slc.renderHdr() - slc.renderVRT() - - -def get_Date(file): - yyyymmdd=file[14:22] - return yyyymmdd - -def main(iargs=None): - ''' - The main driver. - ''' - - inps = cmdLineParse(iargs) - - outputDir = os.path.abspath(inps.output) - - ####################################### - slc_files = glob.glob(os.path.join(inps.input, 'SAR*.E*')) - for file in slc_files: - imgDate = get_Date(os.path.basename(file)) - print (imgDate) - - imgDir = os.path.join(outputDir,imgDate) - os.makedirs(imgDir, exist_ok=True) - - cmd = 'unpackFrame_ERS_ENV.py -i ' + inps.input +' -o ' + imgDir + ' --orbitdir ' + inps.orbitdir - print (cmd) - os.system(cmd) - - slcFile = os.path.join(imgDir, imgDate+'.slc') - - shelveFile = os.path.join(imgDir, 'data') - write_xml(shelveFile, slcFile) - -if __name__ == '__main__': - - main() - -