From 7c40da5a74d4074c5b745c65b9ac1d4f66df6281 Mon Sep 17 00:00:00 2001 From: Lijun Zhu Date: Tue, 16 Feb 2021 13:02:04 -0800 Subject: [PATCH] PyCuAmpcor: offer an option to add gross offset to output offset image --- .../isceobj/TopsProc/runDenseOffsets.py | 7 +++ contrib/PyCuAmpcor/examples/cuDenseOffsets.py | 5 +++ contrib/PyCuAmpcor/src/PyCuAmpcor.pyx | 9 ++++ contrib/PyCuAmpcor/src/cuAmpcorController.cu | 43 +++++++++++-------- contrib/PyCuAmpcor/src/cuAmpcorController.h | 2 - contrib/PyCuAmpcor/src/cuAmpcorParameter.cu | 2 + contrib/PyCuAmpcor/src/cuAmpcorParameter.h | 1 + contrib/PyCuAmpcor/src/cuOffset.cu | 3 ++ 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/components/isceobj/TopsProc/runDenseOffsets.py b/components/isceobj/TopsProc/runDenseOffsets.py index a1ffb29..5b80ea2 100644 --- a/components/isceobj/TopsProc/runDenseOffsets.py +++ b/components/isceobj/TopsProc/runDenseOffsets.py @@ -170,11 +170,15 @@ def runDenseOffsetsGPU(self): m = isceobj.createSlcImage() m.load(reference + '.xml') m.setAccessMode('READ') + # re-create vrt in terms of merged full slc + m.renderHdr() ### Load the secondary object s = isceobj.createSlcImage() s.load(secondary + '.xml') s.setAccessMode('READ') + # re-create vrt in terms of merged full slc + s.renderHdr() # get the dimension width = m.getWidth() @@ -244,6 +248,9 @@ def runDenseOffsetsGPU(self): objOffset.snrImageName = os.path.join(self._insar.mergedDirname, self._insar.snrfile) objOffset.covImageName = os.path.join(self._insar.mergedDirname, self._insar.covfile) + # merge gross offset to final offset + objOffset.mergeGrossOffset = 1 + ### print the settings print('\nReference frame: %s' % (mf)) print('Secondary frame: %s' % (sf)) diff --git a/contrib/PyCuAmpcor/examples/cuDenseOffsets.py b/contrib/PyCuAmpcor/examples/cuDenseOffsets.py index 4ad9ece..96a9413 100755 --- a/contrib/PyCuAmpcor/examples/cuDenseOffsets.py +++ b/contrib/PyCuAmpcor/examples/cuDenseOffsets.py @@ -89,6 +89,8 @@ def createParser(): help='Gross range offset (default: %(default)s).') gross.add_argument('--gf', '--gross-file', type=str, dest='gross_offset_file', help='Varying gross offset input file') + gross.add_argument('--mg', '--merge-gross-offset', type=int, dest='merge_gross_offset', default=0, + help='Whether to merge gross offset to the output offset image (default: %(default)s).') corr = parser.add_argument_group('Correlation surface') corr.add_argument('--corr-stat-size', type=int, dest='corr_stat_win_size', default=21, @@ -238,6 +240,9 @@ def estimateOffsetField(reference, secondary, inps=None): print("snr: ",objOffset.snrImageName) print("cov: ",objOffset.covImageName) + # whether to include the gross offset in offsetImage + objOffset.mergeGrossOffset = inps.merge_gross_offset + offsetImageName = objOffset.offsetImageName grossOffsetImageName = objOffset.grossOffsetImageName snrImageName = objOffset.snrImageName diff --git a/contrib/PyCuAmpcor/src/PyCuAmpcor.pyx b/contrib/PyCuAmpcor/src/PyCuAmpcor.pyx index 7fc9cc5..8af89d2 100644 --- a/contrib/PyCuAmpcor/src/PyCuAmpcor.pyx +++ b/contrib/PyCuAmpcor/src/PyCuAmpcor.pyx @@ -87,6 +87,8 @@ cdef extern from "cuAmpcorParameter.h": int *grossOffsetAcross ## Gross offsets between reference and secondary windows (across) int grossOffsetDown0 ## constant gross offset (down) int grossOffsetAcross0 ## constant gross offset (across) + int mergeGrossOffset ## whether to merge gross offset to final offset + int referenceStartPixelDown0 ## the first pixel of reference image (down), be adjusted with margins and gross offset int referenceStartPixelAcross0 ## the first pixel of reference image (across) int *referenceChunkStartPixelDown ## array of starting pixels for all reference chunks (down) @@ -337,6 +339,13 @@ cdef class PyCuAmpcor(object): def offsetImageName(self, str a): self.c_cuAmpcor.param.offsetImageName = a.encode() + @property + def mergeGrossOffset(self): + return self.c_cuAmpcor.param.mergeGrossOffset + @mergeGrossOffset.setter + def mergeGrossOffset(self, int a): + self.c_cuAmpcor.param.mergeGrossOffset = a + @property def snrImageName(self): return self.c_cuAmpcor.param.snrImageName.decode("utf-8") diff --git a/contrib/PyCuAmpcor/src/cuAmpcorController.cu b/contrib/PyCuAmpcor/src/cuAmpcorController.cu index eee12fe..625a6a4 100644 --- a/contrib/PyCuAmpcor/src/cuAmpcorController.cu +++ b/contrib/PyCuAmpcor/src/cuAmpcorController.cu @@ -129,12 +129,32 @@ void cuAmpcorController::runAmpcor() cuArraysCopyExtract(offsetImageRun, offsetImage, make_int2(0,0), streams[0]); cuArraysCopyExtract(snrImageRun, snrImage, make_int2(0,0), streams[0]); cuArraysCopyExtract(covImageRun, covImage, make_int2(0,0), streams[0]); - // save outputs to files - offsetImage->outputToFile(param->offsetImageName, streams[0]); + + /* save the offsets and gross offsets */ + // copy the offset to host + offsetImage->allocateHost(); + offsetImage->copyToHost(streams[0]); + // construct the gross offset + cuArrays *grossOffsetImage = new cuArrays(param->numberWindowDown, param->numberWindowAcross); + grossOffsetImage->allocateHost(); + for(int i=0; i< param->numberWindows; i++) + grossOffsetImage->hostData[i] = make_float2(param->grossOffsetDown[i], param->grossOffsetAcross[i]); + + // check whether to merge gross offset + if (param->mergeGrossOffset) + { + // if merge, add the gross offsets to offset + for(int i=0; i< param->numberWindows; i++) + offsetImage->hostData[i] += grossOffsetImage->hostData[i]; + } + // output both offset and gross offset + offsetImage->outputHostToFile(param->offsetImageName); + grossOffsetImage->outputHostToFile(param->grossOffsetImageName); + delete grossOffsetImage; + + // save the snr/cov images snrImage->outputToFile(param->snrImageName, streams[0]); covImage->outputToFile(param->covImageName, streams[0]); - // also save the gross offsets - outputGrossOffsets(); // Delete arrays. delete offsetImage; @@ -155,19 +175,4 @@ void cuAmpcorController::runAmpcor() delete secondaryImage; } - -/** - * Output gross offset fields - */ -void cuAmpcorController::outputGrossOffsets() -{ - cuArrays *grossOffsets = new cuArrays(param->numberWindowDown, param->numberWindowAcross); - grossOffsets->allocateHost(); - - for(int i=0; i< param->numberWindows; i++) - grossOffsets->hostData[i] = make_float2(param->grossOffsetDown[i], param->grossOffsetAcross[i]); - grossOffsets->outputHostToFile(param->grossOffsetImageName); - delete grossOffsets; -} - // end of file diff --git a/contrib/PyCuAmpcor/src/cuAmpcorController.h b/contrib/PyCuAmpcor/src/cuAmpcorController.h index 9c0c77e..77973b6 100644 --- a/contrib/PyCuAmpcor/src/cuAmpcorController.h +++ b/contrib/PyCuAmpcor/src/cuAmpcorController.h @@ -27,8 +27,6 @@ public: ~cuAmpcorController(); // run interface void runAmpcor(); - // output gross offsets - void outputGrossOffsets(); }; #endif diff --git a/contrib/PyCuAmpcor/src/cuAmpcorParameter.cu b/contrib/PyCuAmpcor/src/cuAmpcorParameter.cu index cc9e348..d1451b4 100644 --- a/contrib/PyCuAmpcor/src/cuAmpcorParameter.cu +++ b/contrib/PyCuAmpcor/src/cuAmpcorParameter.cu @@ -59,6 +59,8 @@ cuAmpcorParameter::cuAmpcorParameter() useMmap = 1; // use mmap mmapSizeInGB = 1; + mergeGrossOffset = 0; // default to separate gross offset + } /** diff --git a/contrib/PyCuAmpcor/src/cuAmpcorParameter.h b/contrib/PyCuAmpcor/src/cuAmpcorParameter.h index 862284a..9116ac1 100644 --- a/contrib/PyCuAmpcor/src/cuAmpcorParameter.h +++ b/contrib/PyCuAmpcor/src/cuAmpcorParameter.h @@ -112,6 +112,7 @@ public: int grossOffsetAcross0; ///< gross offset static component (across) int *grossOffsetDown; ///< Gross offsets between reference and secondary windows (down) int *grossOffsetAcross; ///< Gross offsets between reference and secondary windows (across) + int mergeGrossOffset; ///< whether to merge gross offsets into the final offsets int *referenceChunkStartPixelDown; ///< reference starting pixels for each chunk (down) int *referenceChunkStartPixelAcross; ///< reference starting pixels for each chunk (across) diff --git a/contrib/PyCuAmpcor/src/cuOffset.cu b/contrib/PyCuAmpcor/src/cuOffset.cu index 0121204..ac77f13 100644 --- a/contrib/PyCuAmpcor/src/cuOffset.cu +++ b/contrib/PyCuAmpcor/src/cuOffset.cu @@ -4,7 +4,9 @@ * */ +// my module dependencies #include "cuAmpcorUtil.h" +// for FLT_MAX #include // find the max between two elements @@ -254,6 +256,7 @@ void cuDetermineSecondaryExtractOffset(cuArrays *maxLoc, cuArrays *m int blockspergrid=IDIVUP(maxLoc->size, threadsperblock); cudaKernel_determineSecondaryExtractOffset<<>> (maxLoc->devData, maxLocShift->devData, maxLoc->size, xOldRange, yOldRange, xNewRange, yNewRange); + getLastCudaError("cuDetermineSecondaryExtractOffset"); } // end of file