ISCE_INSAR/contrib/stack/stripmapStack/unpackFrame_GF3.py

100 lines
2.7 KiB
Python
Raw Permalink Normal View History

2023-12-06 09:44:22 +00:00
#!/usr/bin/env python3
# import isce
from isce.components.isceobj.Sensor import createSensor
import shelve
import argparse
import glob
from isce.components.isceobj.Util import Poly1D
from isce.components.isceobj.Planet.AstronomicalHandbook import Const
from isce.components.isceobj.Util.decorators import use_api
import os
def cmdLineParse():
'''
Command line parser.
'''
parser = argparse.ArgumentParser(description='Unpack GF3 SLC data and store metadata in pickle file.')
parser.add_argument('-i','--input', dest='RSATdir', type=str,
required=True, help='Input GF3 SLC directory')
parser.add_argument('-o', '--output', dest='slcdir', type=str,
required=True, help='Output unpacked SLC directory')
return parser.parse_args()
@use_api
def unpack(RSATdir, slcname):
'''
Unpack GF3 data to binary SLC file. assume HH only for now
'''
###Search for imagery and XML files in input directory
imgnames = glob.glob(os.path.join(RSATdir,'GF3*.tiff'))
if len(imgnames) <= 0:
imgnames = glob.glob(os.path.join(RSATdir,'GF3*.tif'))
imgname = imgnames[0]
xmlname = glob.glob(os.path.join(RSATdir, 'GF3*.meta.xml'))[0]
####Create output SLC directory if needed
if not os.path.isdir(slcname):
os.mkdir(slcname)
date = os.path.basename(slcname)
#####Create an GF3 object and wire it
obj = createSensor('GF3_SLC')
obj.configure()
obj.xml = xmlname
obj.tiff = imgname
obj.output = os.path.join(slcname, date+'.slc')
####Extract the image and write the XML file for the SLC
obj.extractImage()
obj.frame.getImage().renderHdr()
####Save the doppler polynomial
####CEOS already provides doppler polynomial
####as a function of range pixel
coeffs = obj.doppler_coeff
poly = Poly1D.Poly1D()
poly.initPoly(order=len(coeffs)-1)
poly.setCoeffs(coeffs)
####Save the FMrate polynomial
####CEOS already provides FMrate polynomial
####as a function of range pixel
fcoeffs = obj.azfmrate_coeff
# fcoeffs = [0.0, 0.0, 0.0] # zero-Doppler geometry, so this is not used
fpoly = Poly1D.Poly1D()
fpoly.initPoly(order=len(fcoeffs)-1)
fpoly.setCoeffs(fcoeffs)
####Save required metadata for further use
####All data is output to a shelve file
pickName = os.path.join(slcname, 'data')
2025-02-05 01:37:37 +00:00
with shelve.open(pickName) as db:
2023-12-06 09:44:22 +00:00
db['frame'] = obj.frame
db['doppler'] = poly
db['fmrate'] = fpoly
if __name__ == '__main__':
'''
Main driver.
'''
inps = cmdLineParse()
if inps.slcdir.endswith('/'):
inps.slcdir = inps.slcdir[:-1]
if inps.RSATdir.endswith('/'):
inps.RSATdir = inps.RSATdir[:-1]
unpack(inps.RSATdir, inps.slcdir)