Skip to content

Commit

Permalink
adding scripts -preparing ERS for stack processing
Browse files Browse the repository at this point in the history
  • Loading branch information
yjzhenglamarmota committed Jun 28, 2023
1 parent 9ee285a commit 3bc7ae5
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
91 changes: 91 additions & 0 deletions contrib/stack/stripmapStack/prepareERS_ENVstack.py
Original file line number Diff line number Diff line change
@@ -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()


2 changes: 1 addition & 1 deletion contrib/stack/stripmapStack/unpackFrame_ERS_ENV.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


0 comments on commit 3bc7ae5

Please sign in to comment.