Ejemplo n.º 1
0
def create_phsig(ifg_file, cor_file=None):
    from mroipac.icu.Icu import Icu

    logger.info("Estimating spatial coherence based phase sigma")
    if cor_file is None:
        ext = os.path.splitext(ifg_file)[1]
        cor_file = ifg_file.replace(ext, ".cor")
        logger.info("writing output to %s", cor_file)

    # Create phase sigma correlation file here
    intImage = isceobj.createIntImage()
    intImage.load(ifg_file.replace(".xml", "") + ".xml")
    intImage.setAccessMode("read")
    intImage.createImage()

    phsigImage = isceobj.createImage()
    phsigImage.dataType = "FLOAT"
    phsigImage.bands = 1
    phsigImage.setWidth(intImage.getWidth())
    phsigImage.setFilename(cor_file)
    phsigImage.setAccessMode("write")
    phsigImage.createImage()

    icuObj = Icu(name="filter_icu")
    icuObj.configure()
    icuObj.unwrappingFlag = False
    icuObj.useAmplitudeFlag = False

    icuObj.icu(intImage=intImage, phsigImage=phsigImage)
    phsigImage.renderHdr()

    intImage.finalizeImage()
    phsigImage.finalizeImage()
Ejemplo n.º 2
0
def estCoherence(outfile, corfile):
    from mroipac.icu.Icu import Icu

    #Create phase sigma correlation file here
    filtImage = isceobj.createIntImage()
    filtImage.load(outfile + '.xml')
    filtImage.setAccessMode('read')
    filtImage.createImage()

    phsigImage = isceobj.createImage()
    phsigImage.dataType = 'FLOAT'
    phsigImage.bands = 1
    phsigImage.setWidth(filtImage.getWidth())
    phsigImage.setFilename(corfile)
    phsigImage.setAccessMode('write')
    phsigImage.createImage()

    icuObj = Icu(name='sentinel_filter_icu')
    icuObj.configure()
    icuObj.unwrappingFlag = False
    icuObj.useAmplitudeFlag = False
    #icuObj.correlationType = 'NOSLOPE'

    icuObj.icu(intImage=filtImage, phsigImage=phsigImage)
    phsigImage.renderHdr()

    filtImage.finalizeImage()
    phsigImage.finalizeImage()
Ejemplo n.º 3
0
def runUnwrap(self):
    '''Specific connector from an insarApp object to a Snaphu object.'''

    wrapName = self.insar.topophaseFlatFilename
    unwrapName = self.insar.unwrappedIntFilename

    #Setup images
    ampImage = self.insar.resampAmpImage.copy(access_mode='read')
    width = ampImage.getWidth()

    #intImage
    intImage = isceobj.createIntImage()
    intImage.initImage(wrapName, 'read', width)
    intImage.createImage()

    #unwImage
    unwImage = isceobj.Image.createUnwImage()
    unwImage.setFilename(unwrapName)
    unwImage.setWidth(width)
    unwImage.imageType = 'unw'
    unwImage.bands = 2
    unwImage.scheme = 'BIL'
    unwImage.dataType = 'FLOAT'
    unwImage.setAccessMode('write')
    unwImage.createImage()

    icuObj = Icu(name='insarapp_icu')
    icuObj.configure()
    icuObj.icu(intImage=intImage, ampImage=ampImage, unwImage = unwImage)
    #At least one can query for the name used
    self.insar.connectedComponentsFilename =  icuObj.conncompFilename
    ampImage.finalizeImage()
    intImage.finalizeImage()
    unwImage.finalizeImage()
    unwImage.renderHdr()
Ejemplo n.º 4
0
    def unwrap(self):
        icuObj = Icu()
        icuObj.filteringFlag = False      ##insarApp.py already filters it
        icuObj.initCorrThreshold = 0.1
        icuObj.icu(intImage=self.intImage, ampImage=self.ampImage, unwImage = self.unwImage)

        self.ampImage.finalizeImage()
        self.intImage.finalizeImage()
        self.unwImage.renderHdr()
        self.unwImage.finalizeImage()
Ejemplo n.º 5
0
def runUnwrapIcu(infile, outfile):
    from mroipac.icu.Icu import Icu
    #Setup images
    #ampImage
   # ampImage = obj.insar.resampAmpImage.copy(access_mode='read')
   # width = self.ampImage.getWidth()

    img = isceobj.createImage()
    img.load(infile + '.xml')


    width      = img.getWidth()

    #intImage
    intImage = isceobj.createIntImage()
    intImage.initImage(infile, 'read', width)
    intImage.createImage()
   

    #unwImage
    unwImage = isceobj.Image.createImage()
    unwImage.setFilename(outfile)
    unwImage.setWidth(width)
    unwImage.imageType = 'unw'
    unwImage.bands = 2
    unwImage.scheme = 'BIL'
    unwImage.dataType = 'FLOAT'
    unwImage.setAccessMode('write')
    unwImage.createImage()
    
    #unwrap with icu
    icuObj = Icu()
    icuObj.filteringFlag = False      
    icuObj.useAmplitudeFlag = False
    icuObj.singlePatch = True
    icuObj.initCorrThreshold = 0.1
    icuObj.icu(intImage=intImage, unwImage = unwImage)

    #ampImage.finalizeImage()
    intImage.finalizeImage()
    unwImage.finalizeImage()
    unwImage.renderHdr()
Ejemplo n.º 6
0
def runUnwrap(self):
    '''Specific connector from an insarApp object to a Snaphu object.'''

    wrapName = os.path.join(self._insar.mergedDirname,
                            self._insar.filtFilename)
    unwrapName = os.path.join(self._insar.mergedDirname,
                              self._insar.unwrappedIntFilename)

    print(wrapName, unwrapName)
    #intImage
    intImage = isceobj.createImage()
    intImage.load(wrapName + '.xml')
    intImage.setAccessMode('READ')
    intImage.createImage()

    #unwImage
    unwImage = isceobj.Image.createUnwImage()
    unwImage.setFilename(unwrapName)
    unwImage.setWidth(intImage.getWidth())
    unwImage.imageType = 'unw'
    unwImage.bands = 2
    unwImage.scheme = 'BIL'
    unwImage.dataType = 'FLOAT'
    unwImage.setAccessMode('write')
    unwImage.createImage()

    icuObj = Icu(name='topsapp_icu')
    icuObj.configure()
    icuObj.useAmplitudeFlag = False
    icuObj.icu(intImage=intImage, unwImage=unwImage)

    #At least one can query for the name used
    self._insar.connectedComponentsFilename = icuObj.conncompFilename
    intImage.finalizeImage()
    unwImage.finalizeImage()
    unwImage.renderHdr()
Ejemplo n.º 7
0
def estPhaseSigma(insar):
    from mroipac.icu.Icu import Icu

    intImage = isceobj.createSlcImage()  #Filtered file
    intImage.setWidth(insar.resampIntImage.width)
    intImage.setFilename(insar.topophaseFlatFilename)
    intImage.setAccessMode('read')

    ampImage = isceobj.createAmpImage()
    ampImage.setWidth(insar.resampIntImage.width)
    ampImage.setFilename('resampOnlyImage.amp')
    ampImage.setAccessMode('read')

    outImage = isceobj.createRgImage()
    outImage.imageType = 'cor'
    outImage.scheme = 'BIL'
    outImage.bands = 1
    outImage.setWidth(insar.resampIntImage.width)
    outImage.setFilename('phsig.cor')
    outImage.setAccessMode('write')

    intImage.createImage()
    ampImage.createImage()
    outImage.createImage()

    icuObj = Icu()
    icuObj.filteringFlag = False
    icuObj.unwrappingFlag = False
    icuObj.initCorrThreshold = 0.1

    icuObj.icu(intImage=intImage, ampImage=ampImage, phsigImage=outImage)

    outImage.renderHdr()
    intImage.finalizeImage()
    ampImage.finalizeImage()
    outImage.finalizeImage()
Ejemplo n.º 8
0
def run(resampAmpImage, infos, sceneid='NO_ID'):
    logger.info("Unwrapping interferogram using ICU: %s" % sceneid)
    wrapName = infos['outputPath'] + '.' + infos['topophaseFlatFilename']
    unwrapName = infos['outputPath'] + '.' + infos['unwrappedIntFilename']

    #Setup images
    ampImage = resampAmpImage.copy(access_mode='read')
    width = ampImage.getWidth()

    #intImage
    intImage = isceobj.createIntImage()
    intImage.initImage(wrapName, 'read', width)
    intImage.createImage()

    #unwImage
    unwImage = isceobj.Image.createUnwImage()
    unwImage.setFilename(unwrapName)
    unwImage.setWidth(width)
    unwImage.imageType = 'unw'
    unwImage.bands = 2
    unwImage.scheme = 'BIL'
    unwImage.dataType = 'FLOAT'
    unwImage.setAccessMode('write')
    unwImage.createImage()

    #icuObj = Icu()
    #icuObj.filteringFlag = False      ##insarApp.py already filters it
    icuObj = Icu(name='insarapp_icu')
    icuObj.configure()
    icuObj.initCorrThreshold = 0.1
    icuObj.icu(intImage=intImage, ampImage=ampImage, unwImage=unwImage)

    ampImage.finalizeImage()
    intImage.finalizeImage()
    unwImage.finalizeImage()
    unwImage.renderHdr()
Ejemplo n.º 9
0
def runIonUwrap(self):
    '''unwrap subband interferograms
    '''
    catalog = isceobj.Catalog.createCatalog(self._insar.procDoc.name)
    self.updateParamemetersFromUser()

    if not self.doIon:
        catalog.printToLog(logger, "runIonUwrap")
        self._insar.procDoc.addAllFromCatalog(catalog)
        return

    referenceTrack = self._insar.loadTrack(reference=True)
    secondaryTrack = self._insar.loadTrack(reference=False)
    wbdFile = os.path.abspath(self._insar.wbd)

    from isceobj.Alos2Proc.runIonSubband import defineIonDir
    ionDir = defineIonDir()
    subbandPrefix = ['lower', 'upper']

    ionCalDir = os.path.join(ionDir['ion'], ionDir['ionCal'])
    os.makedirs(ionCalDir, exist_ok=True)
    os.chdir(ionCalDir)


    ############################################################
    # STEP 1. take looks
    ############################################################
    from isceobj.Alos2Proc.Alos2ProcPublic import create_xml
    from contrib.alos2proc.alos2proc import look
    from isceobj.Alos2Proc.Alos2ProcPublic import waterBodyRadar

    ml2 = '_{}rlks_{}alks'.format(self._insar.numberRangeLooks1*self._insar.numberRangeLooksIon, 
                              self._insar.numberAzimuthLooks1*self._insar.numberAzimuthLooksIon)

    for k in range(2):
        fullbandDir = os.path.join('../../', ionDir['insar'])
        subbandDir = os.path.join('../', ionDir['subband'][k], ionDir['insar'])
        prefix = subbandPrefix[k]

        amp = isceobj.createImage()
        amp.load(os.path.join(subbandDir, self._insar.amplitude)+'.xml')
        width = amp.width
        length = amp.length
        width2 = int(width / self._insar.numberRangeLooksIon)
        length2 = int(length / self._insar.numberAzimuthLooksIon)

        #take looks
        look(os.path.join(subbandDir, self._insar.differentialInterferogram), prefix+ml2+'.int', width, self._insar.numberRangeLooksIon, self._insar.numberAzimuthLooksIon, 4, 0, 1)
        create_xml(prefix+ml2+'.int', width2, length2, 'int')
        look(os.path.join(subbandDir, self._insar.amplitude), prefix+ml2+'.amp', width, self._insar.numberRangeLooksIon, self._insar.numberAzimuthLooksIon, 4, 1, 1)
        create_xml(prefix+ml2+'.amp', width2, length2, 'amp')

        # #water body
        # if k == 0:
        #     wbdOutFile = os.path.join(fullbandDir, self._insar.wbdOut)
        #     if os.path.isfile(wbdOutFile):
        #         look(wbdOutFile, 'wbd'+ml2+'.wbd', width, self._insar.numberRangeLooksIon, self._insar.numberAzimuthLooksIon, 0, 0, 1)
        #         create_xml('wbd'+ml2+'.wbd', width2, length2, 'byte')

        #water body
        if k == 0:
            look(os.path.join(fullbandDir, self._insar.latitude), 'lat'+ml2+'.lat', width, self._insar.numberRangeLooksIon, self._insar.numberAzimuthLooksIon, 3, 0, 1)
            look(os.path.join(fullbandDir, self._insar.longitude), 'lon'+ml2+'.lon', width, self._insar.numberRangeLooksIon, self._insar.numberAzimuthLooksIon, 3, 0, 1)
            create_xml('lat'+ml2+'.lat', width2, length2, 'double')
            create_xml('lon'+ml2+'.lon', width2, length2, 'double')
            waterBodyRadar('lat'+ml2+'.lat', 'lon'+ml2+'.lon', wbdFile, 'wbd'+ml2+'.wbd')


    ############################################################
    # STEP 2. compute coherence
    ############################################################
    from isceobj.Alos2Proc.Alos2ProcPublic import cal_coherence

    lowerbandInterferogramFile = subbandPrefix[0]+ml2+'.int'
    upperbandInterferogramFile = subbandPrefix[1]+ml2+'.int'
    lowerbandAmplitudeFile = subbandPrefix[0]+ml2+'.amp'
    upperbandAmplitudeFile = subbandPrefix[1]+ml2+'.amp'
    lowerbandCoherenceFile = subbandPrefix[0]+ml2+'.cor'
    upperbandCoherenceFile = subbandPrefix[1]+ml2+'.cor'
    coherenceFile = 'diff'+ml2+'.cor'

    lowerint = np.fromfile(lowerbandInterferogramFile, dtype=np.complex64).reshape(length2, width2)
    upperint = np.fromfile(upperbandInterferogramFile, dtype=np.complex64).reshape(length2, width2)
    loweramp = np.fromfile(lowerbandAmplitudeFile, dtype=np.float32).reshape(length2, width2*2)
    upperamp = np.fromfile(upperbandAmplitudeFile, dtype=np.float32).reshape(length2, width2*2)

    #compute coherence only using interferogram
    #here I use differential interferogram of lower and upper band interferograms
    #so that coherence is not affected by fringes
    cord = cal_coherence(lowerint*np.conjugate(upperint), win=3, edge=4)
    cor = np.zeros((length2*2, width2), dtype=np.float32)
    cor[0:length2*2:2, :] = np.sqrt( (np.absolute(lowerint)+np.absolute(upperint))/2.0 )
    cor[1:length2*2:2, :] = cord
    cor.astype(np.float32).tofile(coherenceFile)
    create_xml(coherenceFile, width2, length2, 'cor')

    #create lower and upper band coherence files
    #lower
    amp1 = loweramp[:, 0:width2*2:2]
    amp2 = loweramp[:, 1:width2*2:2]
    cor[1:length2*2:2, :] = np.absolute(lowerint)/(amp1+(amp1==0))/(amp2+(amp2==0))*(amp1!=0)*(amp2!=0)
    cor.astype(np.float32).tofile(lowerbandCoherenceFile)
    create_xml(lowerbandCoherenceFile, width2, length2, 'cor')

    #upper
    amp1 = upperamp[:, 0:width2*2:2]
    amp2 = upperamp[:, 1:width2*2:2]
    cor[1:length2*2:2, :] = np.absolute(upperint)/(amp1+(amp1==0))/(amp2+(amp2==0))*(amp1!=0)*(amp2!=0)
    cor.astype(np.float32).tofile(upperbandCoherenceFile)
    create_xml(upperbandCoherenceFile, width2, length2, 'cor')


    ############################################################
    # STEP 3. filtering subband interferograms
    ############################################################
    from contrib.alos2filter.alos2filter import psfilt1
    from isceobj.Alos2Proc.Alos2ProcPublic import runCmd
    from isceobj.Alos2Proc.Alos2ProcPublic import create_xml
    from mroipac.icu.Icu import Icu

    if self.filterSubbandInt:
        for k in range(2):
            toBeFiltered = 'tmp.int'
            if self.removeMagnitudeBeforeFilteringSubbandInt:
                cmd = "imageMath.py -e='a/(abs(a)+(a==0))' --a={} -o {} -t cfloat -s BSQ".format(subbandPrefix[k]+ml2+'.int', toBeFiltered)
            else:
                #scale the inteferogram, otherwise its magnitude is too large for filtering
                cmd = "imageMath.py -e='a/100000.0' --a={} -o {} -t cfloat -s BSQ".format(subbandPrefix[k]+ml2+'.int', toBeFiltered)
            runCmd(cmd)

            intImage = isceobj.createIntImage()
            intImage.load(toBeFiltered + '.xml')
            width = intImage.width
            length = intImage.length

            windowSize = self.filterWinsizeSubbandInt
            stepSize = self.filterStepsizeSubbandInt
            psfilt1(toBeFiltered, 'filt_'+subbandPrefix[k]+ml2+'.int', width, self.filterStrengthSubbandInt, windowSize, stepSize)
            create_xml('filt_'+subbandPrefix[k]+ml2+'.int', width, length, 'int')

            os.remove(toBeFiltered)
            os.remove(toBeFiltered + '.vrt')
            os.remove(toBeFiltered + '.xml')

            #create phase sigma for phase unwrapping
            #recreate filtered image
            filtImage = isceobj.createIntImage()
            filtImage.load('filt_'+subbandPrefix[k]+ml2+'.int' + '.xml')
            filtImage.setAccessMode('read')
            filtImage.createImage()

            #amplitude image
            ampImage = isceobj.createAmpImage()
            ampImage.load(subbandPrefix[k]+ml2+'.amp' + '.xml')
            ampImage.setAccessMode('read')
            ampImage.createImage()

            #phase sigma correlation image
            phsigImage = isceobj.createImage()
            phsigImage.setFilename(subbandPrefix[k]+ml2+'.phsig')
            phsigImage.setWidth(width)
            phsigImage.dataType='FLOAT'
            phsigImage.bands = 1
            phsigImage.setImageType('cor')
            phsigImage.setAccessMode('write')
            phsigImage.createImage()

            icu = Icu(name='insarapp_filter_icu')
            icu.configure()
            icu.unwrappingFlag = False
            icu.icu(intImage = filtImage, ampImage=ampImage, phsigImage=phsigImage)

            phsigImage.renderHdr()

            filtImage.finalizeImage()
            ampImage.finalizeImage()
            phsigImage.finalizeImage()


    ############################################################
    # STEP 4. phase unwrapping
    ############################################################
    from isceobj.Alos2Proc.Alos2ProcPublic import snaphuUnwrap

    for k in range(2):
        tmid = referenceTrack.sensingStart + datetime.timedelta(seconds=(self._insar.numberAzimuthLooks1-1.0)/2.0*referenceTrack.azimuthLineInterval+
               referenceTrack.numberOfLines/2.0*self._insar.numberAzimuthLooks1*referenceTrack.azimuthLineInterval)

        if self.filterSubbandInt:
            toBeUnwrapped = 'filt_'+subbandPrefix[k]+ml2+'.int'
            coherenceFile = subbandPrefix[k]+ml2+'.phsig'
        else:
            toBeUnwrapped = subbandPrefix[k]+ml2+'.int'
            coherenceFile = 'diff'+ml2+'.cor'

        snaphuUnwrap(referenceTrack, tmid, 
            toBeUnwrapped, 
            coherenceFile, 
            subbandPrefix[k]+ml2+'.unw', 
            self._insar.numberRangeLooks1*self._insar.numberRangeLooksIon, 
            self._insar.numberAzimuthLooks1*self._insar.numberAzimuthLooksIon, 
            costMode = 'SMOOTH',initMethod = 'MCF', defomax = 2, initOnly = True)


    os.chdir('../../')
    catalog.printToLog(logger, "runIonUwrap")
    self._insar.procDoc.addAllFromCatalog(catalog)
Ejemplo n.º 10
0
def runFilt(self):
    '''filter interferogram
    '''
    catalog = isceobj.Catalog.createCatalog(self._insar.procDoc.name)
    self.updateParamemetersFromUser()

    #masterTrack = self._insar.loadTrack(master=True)
    #slaveTrack = self._insar.loadTrack(master=False)

    insarDir = 'insar'
    os.makedirs(insarDir, exist_ok=True)
    os.chdir(insarDir)

    ############################################################
    # STEP 1. filter interferogram
    ############################################################
    print('\nfilter interferogram: {}'.format(
        self._insar.multilookDifferentialInterferogram))

    toBeFiltered = self._insar.multilookDifferentialInterferogram
    if self.removeMagnitudeBeforeFiltering:
        toBeFiltered = 'tmp.int'
        cmd = "imageMath.py -e='a/(abs(a)+(a==0))' --a={} -o {} -t cfloat -s BSQ".format(
            self._insar.multilookDifferentialInterferogram, toBeFiltered)
        runCmd(cmd)

    #if shutil.which('psfilt1') != None:
    if True:
        intImage = isceobj.createIntImage()
        intImage.load(toBeFiltered + '.xml')
        width = intImage.width
        length = intImage.length
        # cmd = "psfilt1 {int} {filtint} {width} {filterstrength} 64 16".format(
        #        int = toBeFiltered,
        #        filtint = self._insar.filteredInterferogram,
        #        width = width,
        #        filterstrength = self.filterStrength
        #        )
        # runCmd(cmd)
        windowSize = self.filterWinsize
        stepSize = self.filterStepsize
        psfilt1(toBeFiltered, self._insar.filteredInterferogram, width,
                self.filterStrength, windowSize, stepSize)
        create_xml(self._insar.filteredInterferogram, width, length, 'int')
    else:
        #original
        intImage = isceobj.createIntImage()
        intImage.load(toBeFiltered + '.xml')
        intImage.setAccessMode('read')
        intImage.createImage()
        width = intImage.width
        length = intImage.length

        #filtered
        filtImage = isceobj.createIntImage()
        filtImage.setFilename(self._insar.filteredInterferogram)
        filtImage.setWidth(width)
        filtImage.setAccessMode('write')
        filtImage.createImage()

        #looks like the ps filtering program keep the original interferogram magnitude, which is bad for phase unwrapping?
        filters = Filter()
        filters.wireInputPort(name='interferogram', object=intImage)
        filters.wireOutputPort(name='filtered interferogram', object=filtImage)
        filters.goldsteinWerner(alpha=self.filterStrength)
        intImage.finalizeImage()
        filtImage.finalizeImage()
        del intImage, filtImage, filters

    if self.removeMagnitudeBeforeFiltering:
        os.remove(toBeFiltered)
        os.remove(toBeFiltered + '.vrt')
        os.remove(toBeFiltered + '.xml')

    #restore original magnitude
    tmpFile = 'tmp.int'
    renameFile(self._insar.filteredInterferogram, tmpFile)
    cmd = "imageMath.py -e='a*abs(b)' --a={} --b={} -o {} -t cfloat -s BSQ".format(
        tmpFile, self._insar.multilookDifferentialInterferogram,
        self._insar.filteredInterferogram)
    runCmd(cmd)
    os.remove(tmpFile)
    os.remove(tmpFile + '.vrt')
    os.remove(tmpFile + '.xml')

    ############################################################
    # STEP 2. create phase sigma using filtered interferogram
    ############################################################
    print('\ncreate phase sigma using: {}'.format(
        self._insar.filteredInterferogram))

    #recreate filtered image
    filtImage = isceobj.createIntImage()
    filtImage.load(self._insar.filteredInterferogram + '.xml')
    filtImage.setAccessMode('read')
    filtImage.createImage()

    #amplitude image
    ampImage = isceobj.createAmpImage()
    ampImage.load(self._insar.multilookAmplitude + '.xml')
    ampImage.setAccessMode('read')
    ampImage.createImage()

    #phase sigma correlation image
    phsigImage = isceobj.createImage()
    phsigImage.setFilename(self._insar.multilookPhsig)
    phsigImage.setWidth(width)
    phsigImage.dataType = 'FLOAT'
    phsigImage.bands = 1
    phsigImage.setImageType('cor')
    phsigImage.setAccessMode('write')
    phsigImage.createImage()

    icu = Icu(name='insarapp_filter_icu')
    icu.configure()
    icu.unwrappingFlag = False
    icu.icu(intImage=filtImage, ampImage=ampImage, phsigImage=phsigImage)

    phsigImage.renderHdr()

    filtImage.finalizeImage()
    ampImage.finalizeImage()
    phsigImage.finalizeImage()

    del filtImage
    del ampImage
    del phsigImage
    del icu

    ############################################################
    # STEP 3. mask filtered interferogram using water body
    ############################################################
    print('\nmask filtered interferogram using: {}'.format(
        self._insar.multilookWbdOut))

    if self.waterBodyMaskStartingStep == 'filt':
        if not os.path.exists(self._insar.multilookWbdOut):
            catalog.addItem(
                'warning message',
                'requested masking interferogram with water body, but water body does not exist',
                'runFilt')
        else:
            wbd = np.fromfile(self._insar.multilookWbdOut,
                              dtype=np.int8).reshape(length, width)
            phsig = np.memmap(self._insar.multilookPhsig,
                              dtype='float32',
                              mode='r+',
                              shape=(length, width))
            phsig[np.nonzero(wbd == -1)] = 0
            del phsig
            filt = np.memmap(self._insar.filteredInterferogram,
                             dtype='complex64',
                             mode='r+',
                             shape=(length, width))
            filt[np.nonzero(wbd == -1)] = 0
            del filt
            del wbd

    os.chdir('../')

    catalog.printToLog(logger, "runFilt")
    self._insar.procDoc.addAllFromCatalog(catalog)
Ejemplo n.º 11
0
def runFilter(self, filterStrength):
    logger.info("Applying power-spectral filter")

    # Initialize the flattened interferogram
    topoflatIntFilename = self.insar.topophaseFlatFilename
    intImage = isceobj.createIntImage()
    widthInt = self.insar.resampIntImage.width
    intImage.setFilename(topoflatIntFilename)
    intImage.setWidth(widthInt)
    intImage.setAccessMode('read')
    intImage.createImage()

    # Create the filtered interferogram
    filtIntFilename = 'filt_' + topoflatIntFilename
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('write')
    filtImage.createImage()

    objFilter = Filter()
    objFilter.wireInputPort(name='interferogram', object=intImage)
    objFilter.wireOutputPort(name='filtered interferogram', object=filtImage)
    if filterStrength is not None:
        self.insar.filterStrength = filterStrength

    objFilter.goldsteinWerner(alpha=self.insar.filterStrength)

    intImage.finalizeImage()
    filtImage.finalizeImage()
    del filtImage

    #Create phase sigma correlation file here
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('read')
    filtImage.createImage()

    phsigImage = isceobj.createImage()
    phsigImage.dataType = 'FLOAT'
    phsigImage.bands = 1
    phsigImage.setWidth(widthInt)
    phsigImage.setFilename(self.insar.phsigFilename)
    phsigImage.setAccessMode('write')
    phsigImage.setImageType(
        'cor'
    )  #the type in this case is not for mdx.py displaying but for geocoding method
    phsigImage.createImage()

    ampImage = isceobj.createAmpImage()
    IU.copyAttributes(self.insar.resampAmpImage, ampImage)
    ampImage.setAccessMode('read')
    ampImage.createImage()

    icuObj = Icu(name='insarapp_filter_icu')
    icuObj.configure()
    icuObj.unwrappingFlag = False

    icuObj.icu(intImage=filtImage, ampImage=ampImage, phsigImage=phsigImage)

    filtImage.finalizeImage()
    phsigImage.finalizeImage()
    ampImage.finalizeImage()
    phsigImage.renderHdr()

    # Set the filtered image to be the one geocoded
    self.insar.topophaseFlatFilename = filtIntFilename
Ejemplo n.º 12
0
def run(resampAmpImage, widthInt, infos, catalog=None, sceneid='NO_ID'):
    logger.info("Applying power-spectral filter: %s" % sceneid)

    # Initialize the flattened interferogram
    topoflatIntFilename = infos['outputPath'] + '.' + infos['topophaseFlatFilename']
    intImage = isceobj.createIntImage()
    intImage.setFilename(topoflatIntFilename)
    intImage.setWidth(widthInt)
    intImage.setAccessMode('read')
    intImage.createImage()

    # Create the filtered interferogram
    filtIntFilename = infos['outputPath'] + '.' + infos['filt_topophaseFlatFilename']
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('write')
    filtImage.createImage()

    objFilter = Filter()
    objFilter.wireInputPort(name='interferogram',object=intImage)
    objFilter.wireOutputPort(name='filtered interferogram',object=filtImage)

    objFilter.goldsteinWerner(alpha=infos['filterStrength'])

    intImage.finalizeImage()
    filtImage.finalizeImage()


    #Create phase sigma correlation file here
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('read')
    filtImage.createImage()

    phsigFilename = infos['outputPath'] + '.' + infos['phsigFilename']
    phsigImage = isceobj.createImage()
    phsigImage.dataType='FLOAT'
    phsigImage.bands = 1
    phsigImage.setWidth(widthInt)
    phsigImage.setFilename(phsigFilename)
    phsigImage.setAccessMode('write')
    phsigImage.setImageType('cor')#the type in this case is not for mdx.py displaying but for geocoding method
    phsigImage.createImage()


    ampImage = isceobj.createAmpImage()
    IU.copyAttributes(resampAmpImage, ampImage)
    ampImage.setAccessMode('read')
    ampImage.createImage()


    icuObj = Icu(name='insarapp_filter_icu')
    icuObj.configure()
    icuObj.filteringFlag = False
    icuObj.unwrappingFlag = False
    icuObj.initCorrThreshold = 0.1

    icuObj.icu(intImage=filtImage, ampImage=ampImage, phsigImage=phsigImage)

    filtImage.finalizeImage()
    phsigImage.finalizeImage()
    phsigImage.renderHdr()
    ampImage.finalizeImage()
Ejemplo n.º 13
0
def runFilter(self):

    if not self.doInSAR:
        return

    logger.info("Applying power-spectral filter")

    mergedir = self._insar.mergedDirname
    filterStrength = self.filterStrength

    # Initialize the flattened interferogram
    inFilename = os.path.join(mergedir, self._insar.mergedIfgname)
    intImage = isceobj.createIntImage()
    intImage.load(inFilename + '.xml')
    intImage.setAccessMode('read')
    intImage.createImage()
    widthInt = intImage.getWidth()

    # Create the filtered interferogram
    filtIntFilename = os.path.join(mergedir, self._insar.filtFilename)
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('write')
    filtImage.createImage()

    objFilter = Filter()
    objFilter.wireInputPort(name='interferogram', object=intImage)
    objFilter.wireOutputPort(name='filtered interferogram', object=filtImage)

    objFilter.goldsteinWerner(alpha=filterStrength)

    intImage.finalizeImage()
    filtImage.finalizeImage()
    del filtImage

    #Create phase sigma correlation file here
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('read')
    filtImage.createImage()

    phsigImage = isceobj.createImage()
    phsigImage.dataType = 'FLOAT'
    phsigImage.bands = 1
    phsigImage.setWidth(widthInt)
    phsigImage.setFilename(
        os.path.join(mergedir, self._insar.coherenceFilename))
    phsigImage.setAccessMode('write')
    phsigImage.setImageType(
        'cor'
    )  #the type in this case is not for mdx.py displaying but for geocoding method
    phsigImage.createImage()

    icuObj = Icu(name='topsapp_filter_icu')
    icuObj.configure()
    icuObj.unwrappingFlag = False
    icuObj.useAmplitudeFlag = False

    icuObj.icu(intImage=filtImage, phsigImage=phsigImage)

    filtImage.finalizeImage()
    phsigImage.finalizeImage()
    phsigImage.renderHdr()
Ejemplo n.º 14
0
def runUnwrap(self, igramSpectrum="full"):
    '''Specific connector from an insarApp object to a Snaphu object.'''

    if igramSpectrum == "full":
        ifgDirname = self.insar.ifgDirname

    elif igramSpectrum == "low":
        if not self.doDispersive:
            print(
                'Estimating dispersive phase not requested ... skipping sub-band interferogram unwrapping'
            )
            return
        ifgDirname = os.path.join(self.insar.ifgDirname,
                                  self.insar.lowBandSlcDirname)

    elif igramSpectrum == "high":
        if not self.doDispersive:
            print(
                'Estimating dispersive phase not requested ... skipping sub-band interferogram unwrapping'
            )
            return
        ifgDirname = os.path.join(self.insar.ifgDirname,
                                  self.insar.highBandSlcDirname)

    wrapName = os.path.join(ifgDirname, 'filt_' + self.insar.ifgFilename)

    if '.flat' in wrapName:
        unwrapName = wrapName.replace('.flat', '.unw')
    elif '.int' in wrapName:
        unwrapName = wrapName.replace('.int', '.unw')
    else:
        unwrapName = wrapName + '.unw'

    img1 = isceobj.createImage()
    img1.load(wrapName + '.xml')
    width = img1.getWidth()

    # Get amp image name
    originalWrapName = os.path.join(ifgDirname, self.insar.ifgFilename)
    if '.flat' in originalWrapName:
        resampAmpImage = originalWrapName.replace('.flat', '.amp')
    elif '.int' in originalWrapName:
        resampAmpImage = originalWrapName.replace('.int', '.amp')
    else:
        resampAmpImage = originalWrapName + '.amp'

    ampImage = isceobj.createAmpImage()
    ampImage.setWidth(width)
    ampImage.setFilename(resampAmpImage)
    ampImage.setAccessMode('read')
    ampImage.createImage()
    #width = ampImage.getWidth()

    #intImage
    intImage = isceobj.createIntImage()
    intImage.initImage(wrapName, 'read', width)
    intImage.createImage()

    #unwImage
    unwImage = isceobj.Image.createUnwImage()
    unwImage.setFilename(unwrapName)
    unwImage.setWidth(width)
    unwImage.imageType = 'unw'
    unwImage.bands = 2
    unwImage.scheme = 'BIL'
    unwImage.dataType = 'FLOAT'
    unwImage.setAccessMode('write')
    unwImage.createImage()

    icuObj = Icu(name='insarapp_icu')
    icuObj.configure()
    icuObj.filteringFlag = False
    #icuObj.useAmplitudeFlag = False
    icuObj.singlePatch = True
    icuObj.initCorrThreshold = 0.1

    icuObj.icu(intImage=intImage, ampImage=ampImage, unwImage=unwImage)
    #At least one can query for the name used
    self.insar.connectedComponentsFilename = icuObj.conncompFilename
    ampImage.finalizeImage()
    intImage.finalizeImage()
    unwImage.finalizeImage()
    unwImage.renderHdr()
Ejemplo n.º 15
0
def runFilter(self, filterStrength, igramSpectrum = "full"):
    logger.info("Applying power-spectral filter")

    if igramSpectrum == "full":
        logger.info("Filtering the full-band interferogram")
        ifgDirname = self.insar.ifgDirname

    elif igramSpectrum == "low":
        if not self.doDispersive:
            print('Estimating dispersive phase not requested ... skipping sub-band interferograms')
            return
        logger.info("Filtering the low-band interferogram")
        ifgDirname = os.path.join(self.insar.ifgDirname, self.insar.lowBandSlcDirname)

    elif igramSpectrum == "high":
        if not self.doDispersive:
            print('Estimating dispersive phase not requested ... skipping sub-band interferograms')
            return
        logger.info("Filtering the high-band interferogram")
        ifgDirname = os.path.join(self.insar.ifgDirname, self.insar.highBandSlcDirname)

    topoflatIntFilename = os.path.join(ifgDirname , self.insar.ifgFilename)

    img1 = isceobj.createImage()
    img1.load(topoflatIntFilename + '.xml')
    widthInt = img1.getWidth()

    intImage = isceobj.createIntImage()
    intImage.setFilename(topoflatIntFilename)
    intImage.setWidth(widthInt)
    intImage.setAccessMode('read')
    intImage.createImage()

    # Create the filtered interferogram
    filtIntFilename = os.path.join(ifgDirname , 'filt_' + self.insar.ifgFilename)
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('write')
    filtImage.createImage()
    
    objFilter = Filter()
    objFilter.wireInputPort(name='interferogram',object=intImage)
    objFilter.wireOutputPort(name='filtered interferogram',object=filtImage)
    if filterStrength is not None:
        self.insar.filterStrength = filterStrength

    objFilter.goldsteinWerner(alpha=self.insar.filterStrength)

    intImage.finalizeImage()
    filtImage.finalizeImage()
    del filtImage
    
    #Create phase sigma correlation file here
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(filtIntFilename)
    filtImage.setWidth(widthInt)
    filtImage.setAccessMode('read')
    filtImage.createImage()


    phsigImage = isceobj.createImage()
    phsigImage.dataType='FLOAT'
    phsigImage.bands = 1
    phsigImage.setWidth(widthInt)
    phsigImage.setFilename(os.path.join(ifgDirname , self.insar.coherenceFilename))
    phsigImage.setAccessMode('write')
    phsigImage.setImageType('cor')#the type in this case is not for mdx.py displaying but for geocoding method
    phsigImage.createImage()

    resampAmpImage = os.path.join(ifgDirname , self.insar.ifgFilename)

    if '.flat' in resampAmpImage:
        resampAmpImage = resampAmpImage.replace('.flat', '.amp')
    elif '.int' in resampAmpImage:
        resampAmpImage = resampAmpImage.replace('.int', '.amp')
    else:
        resampAmpImage += '.amp'

    ampImage = isceobj.createAmpImage()
    ampImage.setWidth(widthInt)
    ampImage.setFilename(resampAmpImage)
    #IU.copyAttributes(self.insar.resampAmpImage, ampImage)
    #IU.copyAttributes(resampAmpImage, ampImage)
    ampImage.setAccessMode('read')
    ampImage.createImage()


    icuObj = Icu(name='stripmapapp_filter_icu')
    icuObj.configure()
    icuObj.unwrappingFlag = False

    icuObj.icu(intImage = filtImage, ampImage=ampImage, phsigImage=phsigImage)

    filtImage.finalizeImage()
    phsigImage.finalizeImage()
    phsigImage.renderHdr()
    ampImage.finalizeImage()
Ejemplo n.º 16
0
def runFilter(inps):
    logger.info("Applying power-spectral filter")

    #get width from the header file of input interferogram
    width = getWidth(inps.intf + '.xml')
    length = getLength(inps.intf + '.xml')

    if shutil.which('psfilt1') != None:
        cmd = "psfilt1 {int} {filtint} {width} {filterstrength} 64 16".format(
               int = inps.intf,
               filtint = inps.fintf,
               width = width,
               filterstrength = inps.alpha
               )
        runCmd(cmd)

        #get xml file for interferogram
        create_xml(inps.fintf, width, length, 'int')
    else:
        #create flattened interferogram
        intImage = isceobj.createIntImage()
        intImage.setFilename(inps.intf)
        intImage.setWidth(width)
        intImage.setAccessMode('read')
        intImage.createImage()

        #create the filtered interferogram
        filtImage = isceobj.createIntImage()
        filtImage.setFilename(inps.fintf)
        filtImage.setWidth(width)
        filtImage.setAccessMode('write')
        filtImage.createImage()

        #create filter and run it
        objFilter = Filter()
        objFilter.wireInputPort(name='interferogram',object=intImage)
        objFilter.wireOutputPort(name='filtered interferogram',object=filtImage)
        objFilter.goldsteinWerner(alpha=inps.alpha)

        intImage.finalizeImage()
        filtImage.finalizeImage()
        del filtImage


    #recreate filt image to read
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(inps.fintf)
    filtImage.setWidth(width)
    filtImage.setAccessMode('read')
    filtImage.createImage()

    #create amplitude image
    ampImage = isceobj.createAmpImage()
    ampImage.setFilename(inps.amp)
    ampImage.setWidth(width)
    ampImage.setAccessMode('read')
    ampImage.createImage()

    #create phase sigma correlation file here
    phsig_tmp = 'tmp.phsig'
    phsigImage = isceobj.createImage()
    phsigImage.setFilename(phsig_tmp)
    phsigImage.setWidth(width)
    phsigImage.dataType='FLOAT'
    phsigImage.bands = 1
    phsigImage.setImageType('cor')#the type in this case is not for mdx.py displaying but for geocoding method
    phsigImage.setAccessMode('write')
    phsigImage.createImage()

    #create icu and run it
    icuObj = Icu(name='insarapp_filter_icu')
    icuObj.configure()
    icuObj.unwrappingFlag = False
    icuObj.icu(intImage = filtImage, ampImage=ampImage, phsigImage=phsigImage)
    
    phsigImage.renderHdr()

    filtImage.finalizeImage()
    ampImage.finalizeImage()
    phsigImage.finalizeImage()

    # #add an amplitude channel to phsig file
    # cmd = "imageMath.py -e='sqrt(a_0*a_1)*(b!=0);b' --a={amp} --b={phsig_tmp} -o {phsig} -s BIL".format(
    #        amp = inps.amp,
    #        phsig_tmp = phsig_tmp,
    #        phsig = inps.phsig
    #        )

    #add an amplitude channel to phsig file
    cmd = "imageMath.py -e='sqrt(a_0*a_1)*(b!=0);b' --a={amp} --b={phsig_tmp} -o {phsig} -s BIL".format(
           amp = inps.amp,
           phsig_tmp = phsig_tmp,
           phsig = inps.phsig
           )


    runCmd(cmd)

    #remove the original phsig file
    os.remove(phsig_tmp)
    os.remove(phsig_tmp + '.xml')
    os.remove(phsig_tmp + '.vrt')

    
    #rename original filtered interferogram
    filt_tmp = 'filt_tmp.int'
    os.rename(inps.fintf, filt_tmp)
    os.rename(inps.fintf + '.xml', filt_tmp + '.xml')
    os.rename(inps.fintf + '.vrt', filt_tmp + '.vrt')
    
    #do the numpy calculations
    #replace the magnitude of the filtered interferogram with magnitude of original interferogram
    #mask output file using layover mask (values 2 and 3).
    # cmd = "imageMath.py -e='a/(abs(a)+(abs(a)==0))*abs(b)*(c<2)' --a={0} --b={1} --c={2} -t CFLOAT -o={3}".format(
    #       filt_tmp,
    #       inps.intf,
    #       inps.msk,
    #       inps.fintf
    #     )

    #replacing magnitude is not good for phase unwrapping using snaphu
    cmd = "imageMath.py -e='a*(b<2)' --a={0} --b={1} -t CFLOAT -o={2}".format(
          filt_tmp,
          inps.msk,
          inps.fintf
        )

    runCmd(cmd)
    
    #remove the original filtered interferogram
    os.remove(filt_tmp)
    os.remove(filt_tmp + '.xml')
    os.remove(filt_tmp + '.vrt')