Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions components/isceobj/Sensor/UAVSAR_Stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,11 @@ def _populateFrame(self):
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)
Expand All @@ -175,8 +172,7 @@ def _populateFrame(self):
#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(','))))
Expand Down Expand Up @@ -316,9 +312,9 @@ def extractDoppler(self):
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')
x = f.readlines() #first line is a header
dopfile = getattr(self, 'dopplerFile', self.metadata['dop'])
with open(dopfile,'r') as f:
x = f.readlines() #first line is a header

import numpy
z = numpy.array(
Expand All @@ -337,21 +333,20 @@ def extractDoppler(self):
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')
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']
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))

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: prf = {}".format(prf))

#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
#doppler coefficients
#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
#doppler coefficients
dop_scale = self.velocity/2.0/math.pi
coefs = [x*dop_scale for x in coefs]
#Set the coefs in frame._dopplerVsPixel because that is where DefaultDopp looks for them
Expand All @@ -361,14 +356,14 @@ def extractDoppler(self):

@property
def terrainHeight(self):
#The peg point incorporates the actual terrainHeight
#The peg point incorporates the actual terrainHeight
return 0.0

@property
def platformHeight(self):
h = self.metadata['Global Average Altitude']
#Reduce the platform height by the terrain height because the
#peg radius of curvature includes the terrain height
#Reduce the platform height by the terrain height because the
#peg radius of curvature includes the terrain height
h -= self.metadata['Global Average Terrain Height']
return h

Expand Down
39 changes: 20 additions & 19 deletions contrib/stack/stripmapStack/unpackFrame_UAVSAR.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
#!/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():
'''
Command line parser.
'''

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]

if inps.h5dir.endswith('/'):
inps.h5dir = inps.h5dir[:-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)

unpack(inps.h5dir, inps.slcdir, inps.dopFile, inps.stackSegment)
unpack(inps.metaFile, inps.slcDir, inps.dopFile, inps.stackSegment)