コード例 #1
0
def run(frame1,
        frame2,
        orbit1,
        orbit2,
        formSlc1,
        formSlc2,
        imSlc1,
        imSlc2,
        infos,
        catalog=None,
        sceneid='NO_ID'):
    logger.info("Calculate offset between slcs using ampcor: %s" % sceneid)

    prf1 = frame1.getInstrument().getPulseRepetitionFrequency()
    prf2 = frame2.getInstrument().getPulseRepetitionFrequency()
    nearRange1 = formSlc1.startingRange
    nearRange2 = formSlc2.startingRange
    fs1 = frame1.getInstrument().getRangeSamplingRate()

    ###There seems to be no other way of determining image length - Piyush
    patchSize = infos['patchSize']
    numPatches = infos['numberPatches']
    valid_az_samples = infos['numberValidPulses']
    firstAc = infos['firstSampleAcrossPrf']
    firstDown = infos['firstSampleDownPrf']
    numLocationAcross = infos['numberLocationAcrossPrf']
    numLocationDown = infos['numberLocationDownPrf']

    widthSlc = imSlc1.getWidth()

    coarseRange = (nearRange1 - nearRange2) / (CN.SPEED_OF_LIGHT / (2 * fs1))
    coarseAcross = int(coarseRange + 0.5)
    if (coarseRange <= 0):
        coarseAcross = int(coarseRange - 0.5)

    grossRg = infos['grossRg']
    print("gross Rg: ", grossRg)

    if grossRg is not None:
        coarseAcross = grossRg

    time1, schPosition1, schVelocity1, offset1 = orbit1._unpackOrbit()
    time2, schPosition2, schVelocity2, offset2 = orbit2._unpackOrbit()
    s1 = schPosition1[0][0]
    s1_2 = schPosition1[1][0]
    s2 = schPosition2[0][0]
    s2_2 = schPosition2[1][0]

    coarseAz = int((s1 - s2) / (s2_2 - s2) + prf1 * (1 / prf1 - 1 / prf2) *
                   (patchSize - valid_az_samples) / 2)
    coarseDown = int(coarseAz + 0.5)
    if (coarseAz <= 0):
        coarseDown = int(coarseAz - 0.5)

    grossAz = infos['grossAz']
    print("gross Az: ", grossAz)

    if grossAz is not None:
        coarseDown = grossAz

    coarseAcross = 0 + coarseAcross
    coarseDown = 0 + coarseDown

    logger.debug("Gross Across: %s" % (coarseAcross))
    logger.debug("Gross Down: %s" % (coarseDown))

    offAc = max(firstAc, coarseAcross)
    offDn = max(firstDown, coarseDown)
    lastAc = widthSlc - offAc
    lastDown = (numPatches * valid_az_samples) - offDn

    mSlc = isceobj.createSlcImage()
    IU.copyAttributes(imSlc1, mSlc)
    accessMode = 'read'
    mSlc.setAccessMode(accessMode)
    mSlc.createImage()

    sSlc = isceobj.createSlcImage()
    IU.copyAttributes(imSlc2, sSlc)
    accessMode = 'read'
    sSlc.setAccessMode(accessMode)
    sSlc.createImage()

    objAmpcor = Ampcor()
    objAmpcor.setImageDataType1('complex')
    objAmpcor.setImageDataType2('complex')
    objAmpcor.setFirstSampleAcross(offAc)
    objAmpcor.setLastSampleAcross(lastAc)
    objAmpcor.setNumberLocationAcross(numLocationAcross)
    objAmpcor.setFirstSampleDown(offDn)
    objAmpcor.setLastSampleDown(lastDown)
    objAmpcor.setNumberLocationDown(numLocationDown)
    objAmpcor.setAcrossGrossOffset(coarseAcross)
    objAmpcor.setDownGrossOffset(coarseDown)
    objAmpcor.setFirstPRF(prf1)
    objAmpcor.setSecondPRF(prf2)

    if catalog is not None:
        # Record the inputs
        isceobj.Catalog.recordInputs(catalog, objAmpcor,
                                     "runOffsetprf.%s" % sceneid, logger,
                                     "runOffsetprf.%s" % sceneid)

    objAmpcor.ampcor(mSlc, sSlc)

    if catalog is not None:
        # Record the outputs
        isceobj.Catalog.recordOutputs(catalog, objAmpcor,
                                      "runOffsetprf.%s" % sceneid, logger,
                                      "runOffsetprf.%s" % sceneid)

    mSlc.finalizeImage()
    sSlc.finalizeImage()

    return objAmpcor.getOffsetField()
コード例 #2
0
def runOffsetprf(self):
    from isceobj.Catalog import recordInputs

    logger.info("Calculate offset between slcs using ampcor")
    masterFrame = self._insar.getMasterFrame()
    slaveFrame = self._insar.getSlaveFrame()
    masterOrbit = self._insar.getMasterOrbit()
    slaveOrbit = self._insar.getSlaveOrbit()
    prf1 = masterFrame.getInstrument().getPulseRepetitionFrequency()
    prf2 = slaveFrame.getInstrument().getPulseRepetitionFrequency()
    nearRange1 = self.insar.formSLC1.startingRange
    nearRange2 = self.insar.formSLC2.startingRange
    fs1 = masterFrame.getInstrument().getRangeSamplingRate()
    fs2 = slaveFrame.getInstrument().getRangeSamplingRate()

    ###There seems to be no other way of determining image length - Piyush
    patchSize = self._insar.getPatchSize()
    numPatches = self._insar.getNumberPatches()
    valid_az_samples = self._insar.getNumberValidPulses()
    firstAc = self._insar.getFirstSampleAcrossPrf()
    firstDown = self._insar.getFirstSampleDownPrf()
    numLocationAcross = self._insar.getNumberLocationAcrossPrf()
    numLocationDown = self._insar.getNumberLocationDownPrf()

    delRg1 = CN.SPEED_OF_LIGHT / (2 * fs1)
    delRg2 = CN.SPEED_OF_LIGHT / (2 * fs2)

    coarseRange = (nearRange1 - nearRange2) / delRg2
    coarseAcross = int(coarseRange + 0.5)
    if (coarseRange <= 0):
        coarseAcross = int(coarseRange - 0.5)
        pass

    if self.grossRg is not None:
        coarseAcross = self.grossRg
        pass

    s1 = self.insar.formSLC1.mocompPosition[1][0]
    s1_2 = self.insar.formSLC1.mocompPosition[1][1]
    s2 = self.insar.formSLC2.mocompPosition[1][0]
    s2_2 = self.insar.formSLC2.mocompPosition[1][1]

    coarseAz = int((s1 - s2) / (s2_2 - s2) + prf2 * (1 / prf1 - 1 / prf2) *
                   (patchSize - valid_az_samples) / 2)

    coarseDown = int(coarseAz + 0.5)
    if (coarseAz <= 0):
        coarseDown = int(coarseAz - 0.5)
        pass

    if self.grossAz is not None:
        coarseDown = self.grossAz
        pass

    coarseAcross = 0 + coarseAcross
    coarseDown = 0 + coarseDown

    mSlcImage = self._insar.getMasterSlcImage()
    mSlc = isceobj.createSlcImage()
    IU.copyAttributes(mSlcImage, mSlc)
    accessMode = 'read'
    mSlc.setAccessMode(accessMode)
    mSlc.createImage()
    masterWidth = mSlc.getWidth()
    masterLength = mSlc.getLength()

    sSlcImage = self._insar.getSlaveSlcImage()
    sSlc = isceobj.createSlcImage()
    IU.copyAttributes(sSlcImage, sSlc)
    accessMode = 'read'
    sSlc.setAccessMode(accessMode)
    sSlc.createImage()
    slaveWidth = sSlc.getWidth()
    slaveLength = sSlc.getLength()

    objAmpcor = Ampcor(name='insarapp_slcs_ampcor')
    objAmpcor.configure()
    objAmpcor.setImageDataType1('complex')
    objAmpcor.setImageDataType2('complex')

    if objAmpcor.acrossGrossOffset:
        coarseAcross = objAmpcor.acrossGrossOffset

    if objAmpcor.downGrossOffset:
        coarseDown = objAmpcor.downGrossOffset

    logger.debug("Gross Across: %s" % (coarseAcross))
    logger.debug("Gross Down: %s" % (coarseDown))

    xMargin = 2 * objAmpcor.searchWindowSizeWidth + objAmpcor.windowSizeWidth
    yMargin = 2 * objAmpcor.searchWindowSizeHeight + objAmpcor.windowSizeHeight

    #####Compute image positions
    offAc = max(firstAc, -coarseAcross) + xMargin
    offDn = max(firstDown, -coarseDown) + yMargin

    offAcmax = int(coarseAcross + ((fs2 / fs1) - 1) * masterWidth)
    logger.debug("Gross Max Across: %s" % (offAcmax))
    lastAc = int(min(masterWidth, slaveWidth - offAcmax) - xMargin)

    offDnmax = int(coarseDown + ((prf2 / prf1) - 1) * masterLength)
    logger.debug("Gross Max Down: %s" % (offDnmax))
    lastDown = int(min(masterLength, slaveLength - offDnmax) - yMargin)

    if not objAmpcor.firstSampleAcross:
        objAmpcor.setFirstSampleAcross(offAc)

    if not objAmpcor.lastSampleAcross:
        objAmpcor.setLastSampleAcross(lastAc)

    if not objAmpcor.numberLocationAcross:
        objAmpcor.setNumberLocationAcross(numLocationAcross)

    if not objAmpcor.firstSampleDown:
        objAmpcor.setFirstSampleDown(offDn)

    if not objAmpcor.lastSampleDown:
        objAmpcor.setLastSampleDown(lastDown)

    if not objAmpcor.numberLocationDown:
        objAmpcor.setNumberLocationDown(numLocationDown)

    #####Override gross offsets if not provided
    if not objAmpcor.acrossGrossOffset:
        objAmpcor.setAcrossGrossOffset(coarseAcross)

    if not objAmpcor.downGrossOffset:
        objAmpcor.setDownGrossOffset(coarseDown)

    #####User inputs are overriden here
    objAmpcor.setFirstPRF(prf1)
    objAmpcor.setSecondPRF(prf2)
    objAmpcor.setFirstRangeSpacing(delRg1)
    objAmpcor.setSecondRangeSpacing(delRg2)

    # Record the inputs
    recordInputs(self._insar.procDoc, objAmpcor, "runOffsetprf", logger,
                 "runOffsetprf")

    objAmpcor.ampcor(mSlc, sSlc)

    # Record the outputs
    from isceobj.Catalog import recordOutputs
    recordOutputs(self._insar.procDoc, objAmpcor, "runOffsetprf", logger,
                  "runOffsetprf")

    mSlc.finalizeImage()
    sSlc.finalizeImage()

    # save the input offset field for the record
    self._insar.setOffsetField(objAmpcor.getOffsetField())
    self._insar.setRefinedOffsetField(objAmpcor.getOffsetField())
コード例 #3
0
def runAmpcor(master, slave):
    '''
    Run one ampcor process.
    '''
    import isceobj
    from mroipac.ampcor.Ampcor import Ampcor

    mImg = isceobj.createSlcImage()
    mImg.load(master + '.xml')
    mImg.setAccessMode('READ')
    mImg.createImage()

    sImg = isceobj.createSlcImage()
    sImg.load(slave + '.xml')
    sImg.setAccessMode('READ')
    sImg.createImage()

    objAmpcor = Ampcor('ampcor_burst')
    objAmpcor.configure()
    objAmpcor.setImageDataType1('mag')
    objAmpcor.setImageDataType2('mag')

    if objAmpcor.acrossGrossOffset is None:
        coarseAcross = 0

    if objAmpcor.downGrossOffset is None:
        coarseDown = 0

    objAmpcor.windowSizeWidth = 64
    objAmpcor.windowSizeHeight = 32
    objAmpcor.searchWindowSizeWidth = 16
    objAmpcor.searchWindowSizeHeight = 16
    objAmpcor.oversamplingFactor = 32

    xMargin = 2 * objAmpcor.searchWindowSizeWidth + objAmpcor.windowSizeWidth
    yMargin = 2 * objAmpcor.searchWindowSizeHeight + objAmpcor.windowSizeHeight

    firstAc = 1000

    #####Compute image positions

    offDn = objAmpcor.windowSizeHeight // 2 + 1
    offAc = firstAc + xMargin

    offDnmax = mImg.getLength() - objAmpcor.windowSizeHeight // 2 - 1
    lastAc = int(mImg.width - 1000 - xMargin)

    if not objAmpcor.firstSampleAcross:
        objAmpcor.setFirstSampleAcross(offAc)

    if not objAmpcor.lastSampleAcross:
        objAmpcor.setLastSampleAcross(lastAc)

    if not objAmpcor.numberLocationAcross:
        objAmpcor.setNumberLocationAcross(80)

    if not objAmpcor.firstSampleDown:
        objAmpcor.setFirstSampleDown(offDn)

    if not objAmpcor.lastSampleDown:
        objAmpcor.setLastSampleDown(offDnmax)

    ###Since we are only dealing with overlaps
    objAmpcor.setNumberLocationDown(20)

    #####Override gross offsets if not provided
    if not objAmpcor.acrossGrossOffset:
        objAmpcor.setAcrossGrossOffset(coarseAcross)

    if not objAmpcor.downGrossOffset:
        objAmpcor.setDownGrossOffset(coarseDown)

    objAmpcor.setImageDataType1('mag')
    objAmpcor.setImageDataType2('mag')

    objAmpcor.setFirstPRF(1.0)
    objAmpcor.setSecondPRF(1.0)
    objAmpcor.setFirstRangeSpacing(1.0)
    objAmpcor.setSecondRangeSpacing(1.0)
    objAmpcor(mImg, sImg)

    mImg.finalizeImage()
    sImg.finalizeImage()

    return objAmpcor.getOffsetField()
コード例 #4
0
def estimateOffsetField(reference, secondary, azoffset=0, rgoffset=0):
    '''
    Estimate offset field between burst and simamp.
    '''

    sim = isceobj.createSlcImage()
    sim.load(secondary + '.xml')
    sim.setAccessMode('READ')
    sim.createImage()

    sar = isceobj.createSlcImage()
    sar.load(reference + '.xml')
    sar.setAccessMode('READ')
    sar.createImage()

    width = sar.getWidth()
    length = sar.getLength()

    objOffset = Ampcor(name='reference_offset1')
    objOffset.configure()
    objOffset.setAcrossGrossOffset(rgoffset)
    objOffset.setDownGrossOffset(azoffset)
    objOffset.setWindowSizeWidth(128)
    objOffset.setWindowSizeHeight(128)
    objOffset.setSearchWindowSizeWidth(40)
    objOffset.setSearchWindowSizeHeight(40)
    margin = 2 * objOffset.searchWindowSizeWidth + objOffset.windowSizeWidth

    nAcross = 60
    nDown = 60

    offAc = max(101, -rgoffset) + margin
    offDn = max(101, -azoffset) + margin

    lastAc = int(min(width, sim.getWidth() - offAc) - margin)
    lastDn = int(min(length, sim.getLength() - offDn) - margin)

    if not objOffset.firstSampleAcross:
        objOffset.setFirstSampleAcross(offAc)

    if not objOffset.lastSampleAcross:
        objOffset.setLastSampleAcross(lastAc)

    if not objOffset.firstSampleDown:
        objOffset.setFirstSampleDown(offDn)

    if not objOffset.lastSampleDown:
        objOffset.setLastSampleDown(lastDn)

    if not objOffset.numberLocationAcross:
        objOffset.setNumberLocationAcross(nAcross)

    if not objOffset.numberLocationDown:
        objOffset.setNumberLocationDown(nDown)

    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)
    objOffset.setImageDataType1('complex')
    objOffset.setImageDataType2('complex')

    objOffset.ampcor(sar, sim)

    sar.finalizeImage()
    sim.finalizeImage()

    result = objOffset.getOffsetField()
    return result
コード例 #5
0
def run(imageAmp, imageSim, numBand, prf, fs1, infos, stdWriter, catalog=None, sceneid='NO_ID'):
    #fs1: range sampling rate
    firstAc =  infos['firstSampleAcrossPrf']
    firstDown =  infos['firstSampleDownPrf']
    numLocationAcross =  infos['numberLocationAcrossPrf']
    numLocationDown =  infos['numberLocationDownPrf']
    coarseAcross = 0
    coarseDown = 0

    #Fake amplitude image as a complex image
    objAmp = isceobj.createImage()
    objAmp.setAccessMode('read')
    objAmp.dataType = 'CFLOAT'
    objAmp.bands = 1
    objAmp.setFilename(imageAmp.filename)
    objAmp.setWidth(imageAmp.width)
    objAmp.createImage()
    widthAmp = objAmp.getWidth()
    intLength = objAmp.getLength()

    objSim = isceobj.createImage()
    objSim.setFilename(imageSim.filename)
    objSim.setWidth(imageSim.width)
    objSim.dataType='FLOAT'
    objSim.setAccessMode('read')
    objSim.createImage()

    # check if it's correct
    delRg1 = CN.SPEED_OF_LIGHT / (2*fs1)

    objAmpcor = Ampcor()
    objAmpcor.setImageDataType1('real')
    objAmpcor.setImageDataType2('complex')

    ####Adjust first and last values using window sizes
    xMargin = 2*objAmpcor.searchWindowSizeWidth + objAmpcor.windowSizeWidth
    yMargin = 2*objAmpcor.searchWindowSizeHeight + objAmpcor.windowSizeHeight

    offAc = max(firstAc, -coarseAcross) + xMargin
    offDn = max(firstDown, -coarseDown) + yMargin
    lastAc = int(min(widthAmp, widthAmp-offAc) - xMargin)
    lastDn = int(min(intLength, intLength-offDn) - yMargin)

    print(xMargin, yMargin)
    print(offAc, lastAc)
    print(offDn, lastDn)
    objAmpcor.setFirstSampleAcross(offAc)
    objAmpcor.setLastSampleAcross(lastAc)
    objAmpcor.setNumberLocationAcross(numLocationAcross)
    objAmpcor.setFirstSampleDown(offDn)
    objAmpcor.setLastSampleDown(lastDn)
    objAmpcor.setNumberLocationDown(numLocationDown)

    #set the tag used in the outfile. each message is preceded by this tag
    #if the writer is not of "file" type the call has no effect
    objAmpcor.stdWriter = stdWriter.set_file_tags("rgoffset",
                                                  "log",
                                                  "err",
                                                  "out")

    objAmpcor.setFirstPRF(prf)
    objAmpcor.setSecondPRF(prf)
    objAmpcor.setAcrossGrossOffset(coarseAcross)
    objAmpcor.setDownGrossOffset(coarseDown)
    objAmpcor.setFirstRangeSpacing(delRg1)
    objAmpcor.setSecondRangeSpacing(delRg1)

    objAmpcor.ampcor(objSim,objAmp)

    if catalog is not None:
        # Record the inputs and outputs
        isceobj.Catalog.recordInputsAndOutputs(catalog, objAmpcor,
                                               "runRgoffset_ampcor.%s" % sceneid,
                                               logger,
                                               "runRgoffset_ampcor.%s" % sceneid)

    objAmp.finalizeImage()
    objSim.finalizeImage()

    return objAmpcor.getOffsetField()
コード例 #6
0
def run(imageAmp, imageSim, numBand, infos, nstages, scale, stdWriter, catalog=None, sceneid='NO_ID'):
    logger.info("Running Rgoffset: %s" % sceneid)

    coarseAcross = 0
    coarseDown = 0
    firstAc =  infos['firstSampleAcross']
    firstDown =  infos['firstSampleDown']
    numLocationAcross =  infos['numberLocationAcross']
    numLocationDown =  infos['numberLocationDown']

    slaveWidth = imageAmp.getWidth()
    slaveLength = imageAmp.getLength()
    objAmp = isceobj.createSlcImage()
    objAmp.dataType = 'CFLOAT'
    objAmp.bands = 1
    objAmp.setFilename(imageAmp.getFilename())
    objAmp.setAccessMode('read')
    objAmp.setWidth(slaveWidth)
    objAmp.createImage()

    masterWidth = imageSim.getWidth()
    objSim = isceobj.createImage()
    objSim.setFilename(imageSim.getFilename())
    objSim.dataType = 'FLOAT'
    objSim.setWidth(masterWidth)
    objSim.setAccessMode('read')
    objSim.createImage()
    masterLength = imageSim.getLength()

    finalIteration = False
    for iterNum in xrange(nstages-1,-1,-1):
        ####Rewind the images
        try:
            objAmp.rewind()
            objSim.rewind()
        except:
            print('Issues when rewinding images.') #KK sys.exit?

        ######
        logger.debug('Starting Iteration Stage : %d'%(iterNum))
        logger.debug("Gross Across: %s" % (coarseAcross))
        logger.debug("Gross Down: %s" % (coarseDown))

        ####Clear objs
        objAmpcor = None
        objOff = None
        offField = None

        objAmpcor = Ampcor()
        objAmpcor.setImageDataType1('real')
        objAmpcor.setImageDataType2('complex')

        ####Dummy values as there is no scale difference at this step
        objAmpcor.setFirstPRF(1.0)
        objAmpcor.setSecondPRF(1.0)
        objAmpcor.setFirstRangeSpacing(1.0)
        objAmpcor.setSecondRangeSpacing(1.0)

        #####Scale all the reference and search windows
        scaleFactor = scale**iterNum
        objAmpcor.windowSizeWidth *= scaleFactor
        objAmpcor.windowSizeHeight *= scaleFactor
        objAmpcor.searchWindowSizeWidth *= scaleFactor
        objAmpcor.searchWindowSizeHeight *= scaleFactor
        xMargin = 2*objAmpcor.searchWindowSizeWidth + objAmpcor.windowSizeWidth
        yMargin = 2*objAmpcor.searchWindowSizeHeight + objAmpcor.windowSizeHeight


        #####Set image limits for search
        offAc = max(firstAc,-coarseAcross)+xMargin
        offDn = max(firstDn,-coarseDown)+yMargin

        offAcmax = int(coarseAcross)
        logger.debug("Gross Max Across: %s" % (offAcmax))
        lastAc = int(min(masterWidth, slaveWidth-offAcmax) - xMargin)

        offDnmax = int(coarseDown)
        logger.debug("Gross Max Down: %s" % (offDnmax))

        lastDn = int(min(masterLength, slaveLength-offDnmax)  - yMargin)
        logger.debug("Last Down: %s" %(lastDn))
        objAmpcor.setFirstSampleAcross(offAc)
        objAmpcor.setLastSampleAcross(lastAc)
        objAmpcor.setFirstSampleDown(offDn)
        objAmpcor.setLastSampleDown(lastDn)
        objAmpcor.setAcrossGrossOffset(coarseAcross)
        objAmpcor.setDownGrossOffset(coarseDown)

        if (offAc > lastAc) or (offDn > lastDn):
            print('Search window scale is too large.')
            print('Skipping Scale: %d'%(iterNum+1))
            continue

        if ((lastAc - offAc) <=  (2*xMargin)) or ((lastDn - offDn) <= (2*yMargin)):
            print('Image not large enough accounting for margins.')
            print('Skipping Scale: %d'%(iterNum+1))
            continue

        logger.debug('Looks = %d'%scaleFactor)
        logger.debug('Correlation window sizes: %d  %d'%(objAmpcor.windowSizeWidth, objAmpcor.windowSizeHeight))
        logger.debug('Search window sizes: %d %d'%(objAmpcor.searchWindowSizeWidth, objAmpcor.searchWindowSizeHeight))
        logger.debug(' Across pos: %d %d out of (%d,%d)'%(objAmpcor.firstSampleAcross, objAmpcor.lastSampleAcross, masterWidth, slaveWidth))
        logger.debug(' Down pos: %d %d out of (%d,%d)'%(objAmpcor.firstSampleDown, objAmpcor.lastSampleDown, masterLength, slaveLength))
        if (iterNum == 0) or finalIteration:
            if catalog is not None:
                # Record the inputs
            isceobj.Catalog.recordInputs(catalog, objAmpcor,
                                         "runRgoffset.%s" % sceneid,
                                         logger,
                                         "runRgoffset.%s" % sceneid)
            objAmpcor.setNumberLocationAcross(numLocationAcross)
            objAmpcor.setNumberLocationDown(numLocationDown)
        else:
            objAmpcor.setNumberLocationAcross(20)
            objAmpcor.setNumberLocationDown(20)
            objAmpcor.setAcrossLooks(scaleFactor)
            objAmpcor.setDownLooks(scaleFactor)
            objAmpcor.setZoomWindowSize(scale*objAmpcor.zoomWindowSize)
            objAmpcor.setOversamplingFactor(2)


        objAmpcor.ampcor(objSim,objAmp)
        offField = objAmpcor.getOffsetField()

        if (iterNum == 0) or finalIteration:
            if catalog is not None:
                # Record the outputs
                isceobj.Catalog.recordOutputs(catalog, objAmpcor,
                                              "runRgoffset.%s" % sceneid,
                                              logger,
                                              "runRgoffset.%s" % sceneid)
        else:
            objOff = isceobj.createOffoutliers()
            objOff.wireInputPort(name='offsets', object=offField)
            objOff.setSNRThreshold(2.0)
            objOff.setDistance(10)
            objOff.setStdWriter = stdWriter.set_file_tags("nstage_offoutliers"+str(iterNum),
                                                          "log",
                                                          "err",
                                                          "out")
            objOff.offoutliers()
            coarseAcross = int(objOff.averageOffsetAcross)
            coarseDown = int(objOff.averageOffsetDown)

    objSim.finalizeImage()
    objAmp.finalizeImage()
    objOff = None
    objAmpcor = None

    return offField
コード例 #7
0
def runRgoffset(self):
    numLocationAcross = self._insar.getNumberLocationAcrossPrf()
    numLocationDown = self._insar.getNumberLocationDownPrf()
    firstAc = self._insar.getFirstSampleAcrossPrf()
    firstDown = self._insar.getFirstSampleDownPrf()

    #Fake amplitude image as a complex image
    imageAmp = self._insar.getResampAmpImage()
    objAmp = isceobj.createImage()
    objAmp.setAccessMode('read')
    objAmp.dataType = 'CFLOAT'
    objAmp.bands = 1
    objAmp.setFilename(imageAmp.filename)
    objAmp.setWidth(imageAmp.width)
    objAmp.createImage()
    widthAmp = objAmp.getWidth()
    intLength = objAmp.getLength()

    imageSim = self._insar.getSimAmpImage()
    objSim = isceobj.createImage()
    objSim.setFilename(imageSim.filename)
    objSim.setWidth(imageSim.width)
    objSim.dataType = 'FLOAT'
    objSim.setAccessMode('read')
    objSim.createImage()

    simWidth = imageSim.getWidth()
    simLength = imageSim.getLength()
    fs1 = self._insar.getReferenceFrame().getInstrument().getRangeSamplingRate(
    )  ##check
    delRg1 = CN.SPEED_OF_LIGHT / (2 * fs1)  ## if it's correct

    objAmpcor = Ampcor(name='insarapp_intsim_ampcor')
    objAmpcor.configure()
    objAmpcor.setImageDataType1('real')
    objAmpcor.setImageDataType2('mag')

    ####Adjust first and last values using window sizes
    xMargin = 2 * objAmpcor.searchWindowSizeWidth + objAmpcor.windowSizeWidth
    yMargin = 2 * objAmpcor.searchWindowSizeHeight + objAmpcor.windowSizeHeight

    if not objAmpcor.acrossGrossOffset:
        coarseAcross = 0
    else:
        coarseAcross = objAmpcor.acrossGrossOffset

    if not objAmpcor.downGrossOffset:
        coarseDown = 0
    else:
        coarseDown = objAmpcor.downGrossOffset

    offAc = max(firstAc, -coarseAcross) + xMargin + 1
    offDn = max(firstDown, -coarseDown) + yMargin + 1
    lastAc = int(min(widthAmp, simWidth - offAc) - xMargin - 1)
    lastDn = int(min(intLength, simLength - offDn) - yMargin - 1)

    if not objAmpcor.firstSampleAcross:
        objAmpcor.setFirstSampleAcross(offAc)

    if not objAmpcor.lastSampleAcross:
        objAmpcor.setLastSampleAcross(lastAc)

    if not objAmpcor.numberLocationAcross:
        objAmpcor.setNumberLocationAcross(numLocationAcross)

    if not objAmpcor.firstSampleDown:
        objAmpcor.setFirstSampleDown(offDn)

    if not objAmpcor.lastSampleDown:
        objAmpcor.setLastSampleDown(lastDn)

    if not objAmpcor.numberLocationDown:
        objAmpcor.setNumberLocationDown(numLocationDown)

    #set the tag used in the outfile. each message is precided by this tag
    #is the writer is not of "file" type the call has no effect
    self._stdWriter.setFileTag("rgoffset", "log")
    self._stdWriter.setFileTag("rgoffset", "err")
    self._stdWriter.setFileTag("rgoffset", "out")
    objAmpcor.setStdWriter(self._stdWriter)
    prf = self._insar.getReferenceFrame().getInstrument(
    ).getPulseRepetitionFrequency()

    objAmpcor.setFirstPRF(prf)
    objAmpcor.setSecondPRF(prf)

    if not objAmpcor.acrossGrossOffset:
        objAmpcor.setAcrossGrossOffset(coarseAcross)

    if not objAmpcor.downGrossOffset:
        objAmpcor.setDownGrossOffset(coarseDown)

    objAmpcor.setFirstRangeSpacing(delRg1)
    objAmpcor.setSecondRangeSpacing(delRg1)

    objAmpcor.ampcor(objSim, objAmp)

    # Record the inputs and outputs
    from isceobj.Catalog import recordInputsAndOutputs
    recordInputsAndOutputs(self._insar.procDoc, objAmpcor, "runRgoffset_ampcor", \
                  logger, "runRgoffset_ampcor")

    self._insar.setOffsetField(objAmpcor.getOffsetField())
    self._insar.setRefinedOffsetField(objAmpcor.getOffsetField())

    objAmp.finalizeImage()
    objSim.finalizeImage()
コード例 #8
0
def run(frame1,
        frame2,
        formSlc1,
        formSlc2,
        imSlc1,
        imSlc2,
        nstages,
        scale,
        infos,
        stdWriter,
        catalog=None,
        sceneid='NO_ID'):
    logger.info(
        "Calculate offset between slcs using %d stages of ampcor: %s " %
        (nstages, sceneid))

    prf1 = frame1.getInstrument().getPulseRepetitionFrequency()
    prf2 = frame2.getInstrument().getPulseRepetitionFrequency()
    nearRange1 = formSlc1.startingRange
    nearRange2 = formSlc2.startingRange
    fs1 = frame1.getInstrument().getRangeSamplingRate()
    fs2 = frame2.getInstrument().getRangeSamplingRate()

    ###There seems to be no other way of determining image length - Piyush
    patchSize = infos['patchSize']
    numPatches = infos['numberPatches']
    valid_az_samples = infos['numberValidPulses']
    firstAc = infos['firstSampleAcrossPrf']
    firstDown = infos['firstSampleDownPrf']
    numLocationAcross = infos['numberLocationAcrossPrf']
    numLocationDown = infos['numberLocationDownPrf']

    delRg1 = CN.SPEED_OF_LIGHT / (2 * fs1)
    delRg2 = CN.SPEED_OF_LIGHT / (2 * fs2)

    grossRg = infos['grossRg']
    if grossRg is not None:
        coarseAcross = grossRg
    else:
        coarseRange = (nearRange1 - nearRange2) / delRg2
        coarseAcross = int(coarseRange + 0.5)
        if (coarseRange <= 0):
            coarseAcross = int(coarseRange - 0.5)

    grossAz = infos['grossAz']
    if grossAz is not None:
        coarseDown = grossAz
    else:
        s1 = formSlc1.mocompPosition[1][0]
        s1_2 = formSlc1.mocompPosition[1][1]
        s2 = formSlc2.mocompPosition[1][0]
        s2_2 = formSlc2.mocompPosition[1][1]

        coarseAz = int((s1 - s2) / (s2_2 - s2) + prf2 * (1 / prf1 - 1 / prf2) *
                       (patchSize - valid_az_samples) / 2)
        coarseDown = int(coarseAz + 0.5)
        if (coarseAz <= 0):
            coarseDown = int(coarseAz - 0.5)

    coarseAcross = 0 + coarseAcross
    coarseDown = 0 + coarseDown

    mSlc = isceobj.createSlcImage()
    IU.copyAttributes(imSlc1, mSlc)
    accessMode = 'read'
    mSlc.setAccessMode(accessMode)
    mSlc.createImage()
    masterWidth = mSlc.getWidth()
    masterLength = mSlc.getLength()

    sSlc = isceobj.createSlcImage()
    IU.copyAttributes(imSlc2, sSlc)
    accessMode = 'read'
    sSlc.setAccessMode(accessMode)
    sSlc.createImage()
    slaveWidth = sSlc.getWidth()
    slaveLength = sSlc.getLength()

    finalIteration = False
    for iterNum in xrange(nstages - 1, -1, -1):
        ####Rewind the images
        try:
            mSlc.rewind()
            sSlc.rewind()
        except:
            print('Issues when rewinding images.'
                  )  #KK shouldn't it be an error? sys.exit

        ######
        logger.debug('Starting Iteration Stage : %d' % (iterNum))
        logger.debug("Gross Across: %s" % (coarseAcross))
        logger.debug("Gross Down: %s" % (coarseDown))

        ####Clear objs
        objAmpcor = None
        objOff = None
        offField = None

        objAmpcor = Ampcor()
        objAmpcor.setImageDataType1('complex')
        objAmpcor.setImageDataType2('complex')
        objAmpcor.setFirstPRF(prf1)
        objAmpcor.setSecondPRF(prf2)
        objAmpcor.setFirstRangeSpacing(delRg1)
        objAmpcor.setSecondRangeSpacing(delRg2)

        #####Scale all the reference and search windows
        scaleFactor = scale**iterNum
        objAmpcor.windowSizeWidth *= scaleFactor
        objAmpcor.windowSizeHeight *= scaleFactor
        objAmpcor.searchWindowSizeWidth *= scaleFactor
        objAmpcor.searchWindowSizeHeight *= scaleFactor
        xMargin = 2 * objAmpcor.searchWindowSizeWidth + objAmpcor.windowSizeWidth
        yMargin = 2 * objAmpcor.searchWindowSizeHeight + objAmpcor.windowSizeHeight

        #####Set image limits for search
        offAc = max(firstAc, -coarseAcross) + xMargin
        offDn = max(firstDown, -coarseDown) + yMargin

        offAcmax = int(coarseAcross + ((fs2 / fs1) - 1) * masterWidth)
        logger.debug("Gross Max Across: %s" % (offAcmax))
        lastAc = int(min(masterWidth, slaveWidth - offAcmax) - xMargin)

        offDnmax = int(coarseDown + ((prf2 / prf1) - 1) * masterLength)
        logger.debug("Gross Max Down: %s" % (offDnmax))

        lastDn = int(min(masterLength, slaveLength - offDnmax) - yMargin)

        objAmpcor.setFirstSampleAcross(offAc)
        objAmpcor.setLastSampleAcross(lastAc)
        objAmpcor.setFirstSampleDown(offDn)
        objAmpcor.setLastSampleDown(lastDn)
        objAmpcor.setAcrossGrossOffset(coarseAcross)
        objAmpcor.setDownGrossOffset(coarseDown)

        if (offAc > lastAc) or (offDn > lastDn):
            print('Search window scale is too large.')
            print('Skipping Scale: %d' % (iterNum + 1))
            continue

        logger.debug('Looks = %d' % scaleFactor)
        logger.debug('Correlation window sizes: %d  %d' %
                     (objAmpcor.windowSizeWidth, objAmpcor.windowSizeHeight))
        logger.debug('Search window sizes: %d %d' %
                     (objAmpcor.searchWindowSizeWidth,
                      objAmpcor.searchWindowSizeHeight))
        logger.debug(' Across pos: %d %d out of (%d,%d)' %
                     (objAmpcor.firstSampleAcross, objAmpcor.lastSampleAcross,
                      masterWidth, slaveWidth))
        logger.debug(' Down pos: %d %d out of (%d,%d)' %
                     (objAmpcor.firstSampleDown, objAmpcor.lastSampleDown,
                      masterLength, slaveLength))
        if (iterNum == 0) or finalIteration:
            if catalog is not None:
                # Record the inputs
                isceobj.Catalog.recordInputs(catalog, objAmpcor,
                                             "runOffsetprf.%s" % sceneid,
                                             logger,
                                             "runOffsetprf.%s" % sceneid)
            objAmpcor.setNumberLocationAcross(numLocationAcross)
            objAmpcor.setNumberLocationDown(numLocationDown)
        else:
            objAmpcor.setNumberLocationAcross(10)
            objAmpcor.setNumberLocationDown(10)
            objAmpcor.setAcrossLooks(scaleFactor)
            objAmpcor.setDownLooks(scaleFactor)
            objAmpcor.setZoomWindowSize(scale * objAmpcor.zoomWindowSize)
            objAmpcor.setOversamplingFactor(2)

        objAmpcor.ampcor(mSlc, sSlc)
        offField = objAmpcor.getOffsetField()

        if (iterNum == 0) or finalIteration:
            if catalog is not None:
                # Record the outputs
                isceobj.Catalog.recordOutputs(catalog, objAmpcor,
                                              "runOffsetprf.%s" % sceneid,
                                              logger,
                                              "runOffsetprf.%s" % sceneid)
        else:
            objOff = isceobj.createOffoutliers()
            objOff.wireInputPort(name='offsets', object=offField)
            objOff.setSNRThreshold(2.0)
            objOff.setDistance(10)
            objOff.setStdWriter = stdWriter.set_file_tags(
                "nstage_offoutliers" + str(iterNum), "log", "err", "out")
            objOff.offoutliers()
            coarseAcross = int(objOff.averageOffsetAcross)
            coarseDown = int(objOff.averageOffsetDown)

    mSlc.finalizeImage()
    sSlc.finalizeImage()
    objOff = None
    objAmpcor = None

    return offField
コード例 #9
0
def estimateOffsetField(burst, simfile,offset=0.0):
    '''
    Estimate offset field between burst and simamp.
    '''


    sim = isceobj.createImage()
    sim.load(simfile+'.xml')
    sim.setAccessMode('READ')
    sim.createImage()

    sar = isceobj.createSlcImage()
    sar.load(burst.getImage().filename + '.xml')
    sar.setAccessMode('READ')
    sar.createImage()

    width = sar.getWidth()
    length = sar.getLength()

    objOffset = Ampcor(name='reference_offset')
    objOffset.configure()
    objOffset.setWindowSizeWidth(128)
    objOffset.setWindowSizeHeight(128)
    objOffset.setSearchWindowSizeWidth(16)
    objOffset.setSearchWindowSizeHeight(16)
    margin = 2*objOffset.searchWindowSizeWidth + objOffset.windowSizeWidth

    nAcross = 40
    nDown = 40

    if not objOffset.firstSampleAcross:
        objOffset.setFirstSampleAcross(margin+101)

    if not objOffset.lastSampleAcross:
        objOffset.setLastSampleAcross(width-margin-101)

    if not objOffset.firstSampleDown:
        objOffset.setFirstSampleDown(margin+offset+101)

    if not objOffset.lastSampleDown:
        objOffset.setLastSampleDown(length - margin-101)

    if not objOffset.acrossGrossOffset:
        objOffset.setAcrossGrossOffset(0.0)

    if not objOffset.downGrossOffset:
        objOffset.setDownGrossOffset(offset)

    if not objOffset.numberLocationAcross:
        objOffset.setNumberLocationAcross(nAcross)

    if not objOffset.numberLocationDown:
        objOffset.setNumberLocationDown(nDown)        

    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)
    objOffset.setImageDataType1('complex')
    objOffset.setImageDataType2('real') 

    objOffset.ampcor(sar, sim)

    sar.finalizeImage()
    sim.finalizeImage()

    result = objOffset.getOffsetField()
    return result