UAVSAR_Stack: bugfix for line/sample num and dopplerFile path (#431)

* UAVSAR_Stack: bugfix for line/sample num and dopplerFile path
+ UAVSAR_Stack: use segment index while setting the number of lines / samples
+ UAVSAR_Stack: use self.dopplerFile if it exists otherwise use the path from *.ann file, to support unpackFrame_UAVSAR.py when dop file is not in the current directory
+ unpackFrame_UAVSAR: rename variables and comments to improve code readability

* use getattr() instead of hasattr()
LT1AB
Zhang Yunjun 2022-02-01 13:50:40 -08:00 committed by GitHub
parent dfa202456a
commit 9adf1955fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 43 deletions

View File

@ -146,14 +146,11 @@ class UAVSAR_Stack(Component):
frame.setSensingStart(tStart)
frame.setSensingStop(tStop)
frame.setSensingMid(tMid)
frame.setNumberOfLines(
int(self.metadata['slc_1_1x1_mag.set_rows']))
frame.setNumberOfSamples(
int(self.metadata['slc_1_1x1_mag.set_cols']))
frame.setNumberOfLines(int(self.metadata['slc_{}_1x1_mag.set_rows'.format(self.segment_index)]))
frame.setNumberOfSamples(int(self.metadata['slc_{}_1x1_mag.set_cols'.format(self.segment_index)]))
frame.setPolarization(self.metadata['Polarization'])
frame.C0 = self.metadata['slc_1_1x1_mag.col_addr']
frame.S0 = self.metadata[
'Segment {} Data Starting Azimuth'.format(self.segment_index)]
frame.C0 = self.metadata['slc_{}_1x1_mag.col_addr'.format(self.segment_index)]
frame.S0 = self.metadata['Segment {} Data Starting Azimuth'.format(self.segment_index)]
frame.nearLookAngle = self.metadata['Minimum Look Angle']
frame.farLookAngle = self.metadata['Maximum Look Angle']
frame.setStartingRange(self.startingRange)
@ -175,8 +172,7 @@ class UAVSAR_Stack(Component):
#of values in degrees at each corner (without rdf unit specified)
llC = []
for ic in range(1,5):
key = 'Segment {0} Data Approximate Corner {1}'.format(
self.segment_index, ic)
key = 'Segment {0} Data Approximate Corner {1}'.format(self.segment_index, ic)
self.logger.info("key = {}".format(key))
self.logger.info("metadata[key] = {}".format(self.metadata[key], type(self.metadata[key])))
llC.append(list(map(float, self.metadata[key].split(','))))
@ -316,8 +312,8 @@ class UAVSAR_Stack(Component):
drho = instrument.getRangePixelSize() #full res value, not spacing in the dop file
prf = instrument.getPulseRepetitionFrequency()
self.logger.info("extractDoppler: rho0, drho, prf = {}, {}, {}".format(rho0, drho, prf))
dopfile = self.metadata['dop']
f = open(dopfile,'r')
dopfile = getattr(self, 'dopplerFile', self.metadata['dop'])
with open(dopfile,'r') as f:
x = f.readlines() #first line is a header
import numpy
@ -337,12 +333,11 @@ class UAVSAR_Stack(Component):
res2 = fit[1][0] #sum of squared residuals
self.logger.info("coeffs = {}".format(coefs))
self.logger.info("rms residual = {}".format(numpy.sqrt(res2/len(dop))))
o = open("dop.txt", 'w')
with open("dop.txt", 'w') as o:
for i, d in zip(rhoi, dop):
val = polyval(coefs,i)
res = d-val
o.write("{0} {1} {2} {3}\n".format(i, d, val, res))
dopfile = self.metadata['dop']
self.dopplerVals = {'Near':polyval(coefs, 0)} #need this temporarily in this module

View File

@ -1,14 +1,15 @@
#!/usr/bin/env python3
# modified to pass the segment number to UAVSAR_STACK sensor EJF 2020/08/02
import os
import glob
import argparse
import shelve
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
def cmdLineParse():
'''
@ -16,46 +17,46 @@ def cmdLineParse():
'''
parser = argparse.ArgumentParser(description='Unpack UAVSAR SLC data and store metadata in pickle file.')
parser.add_argument('-i','--input', dest='h5dir', type=str,
required=True, help='Input UAVSAR directory')
parser.add_argument('-i','--input', dest='metaFile', type=str,
required=True, help='metadata file')
parser.add_argument('-d','--dop_file', dest='dopFile', type=str,
default=None, help='Doppler file')
parser.add_argument('-s','--segment', dest='stackSegment', type=int,
default=1, help='stack segment')
parser.add_argument('-o', '--output', dest='slcdir', type=str,
parser.add_argument('-o', '--output', dest='slcDir', type=str,
required=True, help='Output SLC directory')
return parser.parse_args()
def unpack(hdf5, slcname, dopFile, stackSegment, parse=False):
def unpack(metaFile, slcDir, dopFile, stackSegment, parse=False):
'''
Unpack HDF5 to binary SLC file.
Prepare shelve/pickle file for the binary SLC file.
'''
obj = createSensor('UAVSAR_STACK')
obj.configure()
obj.metadataFile = hdf5
obj.metadataFile = metaFile
obj.dopplerFile = dopFile
obj.segment_index = stackSegment
obj.parse()
if not os.path.isdir(slcname):
os.mkdir(slcname)
if not os.path.isdir(slcDir):
os.mkdir(slcDir)
pickName = os.path.join(slcname, 'data')
pickName = os.path.join(slcDir, 'data')
with shelve.open(pickName) as db:
db['frame'] = obj.frame
if __name__ == '__main__':
'''
Main driver.
'''
inps = cmdLineParse()
if inps.slcdir.endswith('/'):
inps.slcdir = inps.slcdir[:-1]
inps.slcDir = inps.slcDir.rstrip('/')
inps.metaFile = os.path.abspath(inps.metaFile)
inps.dopFile = os.path.abspath(inps.dopFile)
inps.slcDir = os.path.abspath(inps.slcDir)
if inps.h5dir.endswith('/'):
inps.h5dir = inps.h5dir[:-1]
unpack(inps.h5dir, inps.slcdir, inps.dopFile, inps.stackSegment)
unpack(inps.metaFile, inps.slcDir, inps.dopFile, inps.stackSegment)