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.setSensingStart(tStart)
frame.setSensingStop(tStop) frame.setSensingStop(tStop)
frame.setSensingMid(tMid) frame.setSensingMid(tMid)
frame.setNumberOfLines( frame.setNumberOfLines(int(self.metadata['slc_{}_1x1_mag.set_rows'.format(self.segment_index)]))
int(self.metadata['slc_1_1x1_mag.set_rows'])) frame.setNumberOfSamples(int(self.metadata['slc_{}_1x1_mag.set_cols'.format(self.segment_index)]))
frame.setNumberOfSamples(
int(self.metadata['slc_1_1x1_mag.set_cols']))
frame.setPolarization(self.metadata['Polarization']) frame.setPolarization(self.metadata['Polarization'])
frame.C0 = self.metadata['slc_1_1x1_mag.col_addr'] frame.C0 = self.metadata['slc_{}_1x1_mag.col_addr'.format(self.segment_index)]
frame.S0 = self.metadata[ frame.S0 = self.metadata['Segment {} Data Starting Azimuth'.format(self.segment_index)]
'Segment {} Data Starting Azimuth'.format(self.segment_index)]
frame.nearLookAngle = self.metadata['Minimum Look Angle'] frame.nearLookAngle = self.metadata['Minimum Look Angle']
frame.farLookAngle = self.metadata['Maximum Look Angle'] frame.farLookAngle = self.metadata['Maximum Look Angle']
frame.setStartingRange(self.startingRange) frame.setStartingRange(self.startingRange)
@ -175,8 +172,7 @@ class UAVSAR_Stack(Component):
#of values in degrees at each corner (without rdf unit specified) #of values in degrees at each corner (without rdf unit specified)
llC = [] llC = []
for ic in range(1,5): for ic in range(1,5):
key = 'Segment {0} Data Approximate Corner {1}'.format( key = 'Segment {0} Data Approximate Corner {1}'.format(self.segment_index, ic)
self.segment_index, ic)
self.logger.info("key = {}".format(key)) self.logger.info("key = {}".format(key))
self.logger.info("metadata[key] = {}".format(self.metadata[key], type(self.metadata[key]))) self.logger.info("metadata[key] = {}".format(self.metadata[key], type(self.metadata[key])))
llC.append(list(map(float, self.metadata[key].split(',')))) llC.append(list(map(float, self.metadata[key].split(','))))
@ -316,9 +312,9 @@ class UAVSAR_Stack(Component):
drho = instrument.getRangePixelSize() #full res value, not spacing in the dop file drho = instrument.getRangePixelSize() #full res value, not spacing in the dop file
prf = instrument.getPulseRepetitionFrequency() prf = instrument.getPulseRepetitionFrequency()
self.logger.info("extractDoppler: rho0, drho, prf = {}, {}, {}".format(rho0, drho, prf)) self.logger.info("extractDoppler: rho0, drho, prf = {}, {}, {}".format(rho0, drho, prf))
dopfile = self.metadata['dop'] dopfile = getattr(self, 'dopplerFile', self.metadata['dop'])
f = open(dopfile,'r') with open(dopfile,'r') as f:
x = f.readlines() #first line is a header x = f.readlines() #first line is a header
import numpy import numpy
z = numpy.array( z = numpy.array(
@ -337,21 +333,20 @@ class UAVSAR_Stack(Component):
res2 = fit[1][0] #sum of squared residuals res2 = fit[1][0] #sum of squared residuals
self.logger.info("coeffs = {}".format(coefs)) self.logger.info("coeffs = {}".format(coefs))
self.logger.info("rms residual = {}".format(numpy.sqrt(res2/len(dop)))) 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): for i, d in zip(rhoi, dop):
val = polyval(coefs,i) val = polyval(coefs,i)
res = d-val res = d-val
o.write("{0} {1} {2} {3}\n".format(i, d, val, res)) 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 self.dopplerVals = {'Near':polyval(coefs, 0)} #need this temporarily in this module
self.logger.info("UAVSAR_Stack.extractDoppler: self.dopplerVals = {}".format(self.dopplerVals)) self.logger.info("UAVSAR_Stack.extractDoppler: self.dopplerVals = {}".format(self.dopplerVals))
self.logger.info("UAVSAR_Stack.extractDoppler: prf = {}".format(prf)) self.logger.info("UAVSAR_Stack.extractDoppler: prf = {}".format(prf))
#The doppler file values are in units rad/m. divide by 2*pi rad/cycle to convert #The doppler file values are in units rad/m. divide by 2*pi rad/cycle to convert
#to cycle/m. Then multiply by velocity to get Hz and divide by prf for dimensionless #to cycle/m. Then multiply by velocity to get Hz and divide by prf for dimensionless
#doppler coefficients #doppler coefficients
dop_scale = self.velocity/2.0/math.pi dop_scale = self.velocity/2.0/math.pi
coefs = [x*dop_scale for x in coefs] coefs = [x*dop_scale for x in coefs]
#Set the coefs in frame._dopplerVsPixel because that is where DefaultDopp looks for them #Set the coefs in frame._dopplerVsPixel because that is where DefaultDopp looks for them
@ -361,14 +356,14 @@ class UAVSAR_Stack(Component):
@property @property
def terrainHeight(self): def terrainHeight(self):
#The peg point incorporates the actual terrainHeight #The peg point incorporates the actual terrainHeight
return 0.0 return 0.0
@property @property
def platformHeight(self): def platformHeight(self):
h = self.metadata['Global Average Altitude'] h = self.metadata['Global Average Altitude']
#Reduce the platform height by the terrain height because the #Reduce the platform height by the terrain height because the
#peg radius of curvature includes the terrain height #peg radius of curvature includes the terrain height
h -= self.metadata['Global Average Terrain Height'] h -= self.metadata['Global Average Terrain Height']
return h return h

View File

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