From 55b9d2c03795429dc64f7a69883a4a7f413a0fdf Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Sat, 24 Oct 2020 09:31:48 -0700 Subject: [PATCH] topsStack: ignore coreg_secondary images with inconsistent num of bursts (#195) * ImageLib: fix str syntax * stackSentl: rename slc workflow merge for consistency rename the mergeSLC step in "slc" workflow, to be consistent with the other workflows. * topsStack: check inconsistent num of bursts in secondary images + extractCommonValidRegion.py: add dropSecondarysWithDifferentNumberOfBursts() to discard those acquisitions during the common region calculation + mergeBursts.py: skip secondarys with inconsistent num of bursts by raise exception and exit + s1a_isce_utils.adjustValidSampleLine_V2(): remove a redundant line Co-authored-by: Zhang Yunjun --- components/isceobj/Util/ImageUtil/ImageLib.py | 2 +- .../topsStack/extractCommonValidRegion.py | 31 +++++++++++++++++++ contrib/stack/topsStack/mergeBursts.py | 8 +++-- contrib/stack/topsStack/s1a_isce_utils.py | 1 - contrib/stack/topsStack/stackSentinel.py | 2 +- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/components/isceobj/Util/ImageUtil/ImageLib.py b/components/isceobj/Util/ImageUtil/ImageLib.py index 8faee0a..8e6524d 100755 --- a/components/isceobj/Util/ImageUtil/ImageLib.py +++ b/components/isceobj/Util/ImageUtil/ImageLib.py @@ -262,7 +262,7 @@ class memmap(object): nyy = nbytes//(fsize*nchannels*nxx) if (nxx*nyy*fsize*nchannels) != nbytes: - raise ValueError('File size mismatch for %s. Fractional number of lines'(fname)) + raise ValueError('File size mismatch for %s. Fractional number of lines'%(fname)) elif (nxx*nyy*fsize*nchannels) > nbytes: raise ValueError('File size mismatch for %s. Number of bytes expected: %d'%(nbytes)) diff --git a/contrib/stack/topsStack/extractCommonValidRegion.py b/contrib/stack/topsStack/extractCommonValidRegion.py index baa5606..0c990d9 100755 --- a/contrib/stack/topsStack/extractCommonValidRegion.py +++ b/contrib/stack/topsStack/extractCommonValidRegion.py @@ -39,6 +39,7 @@ def updateValidRegion(topReference, secondaryPath, swath): ####Load relevant products #topReference = ut.loadProduct(os.path.join(inps.reference , 'IW{0}.xml'.format(swath))) + print(secondaryPath) topCoreg = ut.loadProduct(os.path.join(secondaryPath , 'IW{0}.xml'.format(swath))) topIfg = ut.coregSwathSLCProduct() @@ -67,6 +68,34 @@ def updateValidRegion(topReference, secondaryPath, swath): return topReference +def dropSecondarysWithDifferentNumberOfBursts(secondaryList, reference, swathList): + '''Drop secondary acquisitions that have different number of bursts + than the reference acquisition. + ''' + print('checking the number of bursts in coreg_secondarys against the one in reference') + secondaryList2Drop = [] + for swath in swathList: + prodReference = ut.loadProduct(os.path.join(reference, 'IW{0}.xml'.format(swath))) + numBursts = len(prodReference.bursts) + + for secondary in secondaryList: + prodSecondary = ut.loadProduct(os.path.join(secondary, 'IW{0}.xml'.format(swath))) + if len(prodSecondary.bursts) != numBursts: + msg = 'WARNING: {} has different number of bursts ({}) than the reference {} ({}) for swath {}'.format( + os.path.basename(secondary), len(prodSecondary.bursts), + os.path.basename(reference), numBursts, swath) + msg += ' --> exclude it for common region calculation' + print(msg) + secondaryList2Drop.append(secondary) + + secondaryList2Drop = list(sorted(set(secondaryList2Drop))) + if len(secondaryList2Drop) == 0: + print('all secondary images have the same number of bursts as the reference') + + secondaryList = list(sorted(set(secondaryList) - set(secondaryList2Drop))) + + return secondaryList + def main(iargs=None): '''extract common valid overlap region for the stack. @@ -88,6 +117,8 @@ def main(iargs=None): secondaryList = glob.glob(os.path.join(inps.secondary,'2*')) secondarySwathList = ut.getSwathList(secondaryList[0]) # assuming all secondarys have the same swaths swathList = list(sorted(set(referenceSwathList+secondarySwathList))) + # discard secondarys with different number of bursts than the reference + secondaryList = dropSecondarysWithDifferentNumberOfBursts(secondaryList, inps.reference, swathList) for swath in swathList: print('******************') diff --git a/contrib/stack/topsStack/mergeBursts.py b/contrib/stack/topsStack/mergeBursts.py index 3c93e0e..fc245df 100755 --- a/contrib/stack/topsStack/mergeBursts.py +++ b/contrib/stack/topsStack/mergeBursts.py @@ -362,6 +362,12 @@ def main(iargs=None): stack = ut.loadProduct(os.path.join(inps.stack , 'IW{0}.xml'.format(swath))) if inps.isaligned: reference = ifg.reference + + # checking inconsistent number of bursts in the secondary acquisitions + if reference.numberOfBursts != ifg.numberOfBursts: + raise ValueError('{} has different number of bursts ({}) than the reference ({})'.format( + inps.reference, ifg.numberOfBursts, reference.numberOfBursts)) + else: reference = ifg @@ -376,9 +382,7 @@ def main(iargs=None): if inps.stack: minStack = stack.bursts[0].burstNumber print('Updating the valid region of each burst to the common valid region of the stack') - ####Updating the valid region of each burst to the common valid region of the stack for ii in range(minBurst, maxBurst + 1): - ifg.bursts[ii-minBurst].firstValidLine = stack.bursts[ii-minStack].firstValidLine ifg.bursts[ii-minBurst].firstValidSample = stack.bursts[ii-minStack].firstValidSample ifg.bursts[ii-minBurst].numValidLines = stack.bursts[ii-minStack].numValidLines diff --git a/contrib/stack/topsStack/s1a_isce_utils.py b/contrib/stack/topsStack/s1a_isce_utils.py index c79208d..782794e 100755 --- a/contrib/stack/topsStack/s1a_isce_utils.py +++ b/contrib/stack/topsStack/s1a_isce_utils.py @@ -161,7 +161,6 @@ def adjustValidSampleLine_V2(reference, secondary, minAz=0, maxAz=0, minRng=0, m elif (minAz < 0) and (maxAz < 0): reference.firstValidLine = secondary.firstValidLine - int(np.floor(minAz) - 4) - lastValidLine = reference.firstValidLine + secondary.numValidLines + int(np.floor(minAz) - 8) lastValidLine = reference.firstValidLine + secondary.numValidLines - 8 if lastValidLine < reference.numberOfLines: reference.numValidLines = secondary.numValidLines - 8 diff --git a/contrib/stack/topsStack/stackSentinel.py b/contrib/stack/topsStack/stackSentinel.py index 761325d..7efa7cd 100755 --- a/contrib/stack/topsStack/stackSentinel.py +++ b/contrib/stack/topsStack/stackSentinel.py @@ -523,7 +523,7 @@ def slcStack(inps, acquisitionDates, stackReferenceDate, secondaryDates, safe_di if mergeSLC: i+=1 runObj = run() - runObj.configure(inps, 'run_{:02d}_merge'.format(i)) + runObj.configure(inps, 'run_{:02d}_merge_reference_secondary_slc'.format(i)) runObj.mergeReference(stackReferenceDate, virtual = 'False') runObj.mergeSecondarySLC(secondaryDates, virtual = 'False') runObj.finalize()