コード例 #1
0
def readOffset(filename):
    from isceobj.Location.Offset import OffsetField, Offset

    with open(filename, 'r') as f:
        lines = f.readlines()
    #                                          0      1       2       3      4         5             6          7
    #retstr = "%s %s %s %s %s %s %s %s" % (self.x,self.dx,self.y,self.dy,self.snr, self.sigmax, self.sigmay, self.sigmaxy)

    offsets = OffsetField()
    for linex in lines:
        #linexl = re.split('\s+', linex)
        #detect blank lines with only spaces and tabs
        if linex.strip() == '':
            continue

        linexl = linex.split()
        offset = Offset()
        #offset.setCoordinate(int(linexl[0]),int(linexl[2]))
        offset.setCoordinate(float(linexl[0]), float(linexl[2]))
        offset.setOffset(float(linexl[1]), float(linexl[3]))
        offset.setSignalToNoise(float(linexl[4]))
        offset.setCovariance(float(linexl[5]), float(linexl[6]),
                             float(linexl[7]))
        offsets.addOffset(offset)

    return offsets
コード例 #2
0
    def getOffsetField(self):
        """Return and OffsetField object instead of an array of results"""
        offsets = OffsetField()
        for i in range(self.numRows):
            across = self.locationAcross[i]
            down = self.locationDown[i]
            acrossOffset = self.locationAcrossOffset[i]
            downOffset = self.locationDownOffset[i]
            snr = self.snrRet[i]
            sigx = self.cov1Ret[i]
            sigy = self.cov2Ret[i]
            sigxy = self.cov3Ret[i]
            offset = Offset()
            offset.setCoordinate(across, down)
            offset.setOffset(acrossOffset, downOffset)
            offset.setSignalToNoise(snr)
            offset.setCovariance(sigx, sigy, sigxy)
            offsets.addOffset(offset)

        return offsets
コード例 #3
0
ファイル: gpuAmpcorTest.py プロジェクト: shakenbaby216/isce2
def estimateOffsetField(reference, secondary, azoffset=0, rgoffset=0):
    '''
    Estimate offset field between burst and simamp.
    '''
    print('Creating images')
    sim = isceobj.createSlcImage()
    sim.load(secondary+'.xml')
    sim.setAccessMode('READ')
    sim.createImage()

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

    print('Configuring parameters')
    width = sar.getWidth()
    length = sar.getLength()

    ###     CONFIG PARAMS   ###
    refChipWidth = 128
    refChipHeight = 128
    schMarginX = 40
    schMarginY = 40
    schWinWidth = refChipWidth + (2 * schMarginX)
    schWinHeight = refChipHeight + (2 * schMarginY)
    offAc = 309
    offDn = 309
    numberLocationAcross = 40
    numberLocationDown = 40
    ###                     ###

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

    band1 = 0 # bands are 0-indexed
    band2 = 0
    slcAccessor1 = sar.getImagePointer()
    slcAccessor2 = sim.getImagePointer()
    lineLength1 = sar.getWidth()
    fileLength1 = sar.getLength()
    lineLength2 = sim.getWidth()
    fileLength2 = sim.getLength()
    if sar.getDataType().upper().startswith('C'):
        imageDataType1 = 'complex'
    else:
        imageDataType1 = 'real'
    if sim.getDataType().upper().startswith('C'):
        imageDataType2 = 'complex'
    else:
        imageDataType2 = 'real'
    
    scaleFactorY = 1.0 # == prf2 / prf1
    scaleFactorX = 1.0 # == rangeSpacing1 / rangeSpacing2, but these are never set so I'm assuming....
    print('Scale Factor in Range: ', scaleFactorX)
    print('Scale Factor in Azimuth: ', scaleFactorY)
    offAcmax = int(rgoffset + (scaleFactorX-1)*lineLength1)
    offDnmax = int(azoffset + (scaleFactorY-1)*fileLength1)
    
    skipSampleDown = int((lastDn - offDn) / (numberLocationDown - 1.))
    print('Skip Sample Down: %d'%(skipSampleDown))
    skipSampleAcross = int((lastAc - offAc) / (numberLocationAcross - 1.))
    print('Skip Sample Across: %d'%(skipSampleAcross))

    ### setState
    objOffset = PyAmpcor()
    
    objOffset.imageBand1 = band1
    objOffset.imageBand2 = band2
    objOffset.imageAccessor1 = slcAccessor1
    objOffset.imageAccessor2 = slcAccessor2
    objOffset.datatype1 = imageDataType1
    objOffset.datatype2 = imageDataType2
    objOffset.lineLength1 = lineLength1
    objOffset.lineLength2 = lineLength2
    objOffset.firstSampleAcross = offAc
    objOffset.lastSampleAcross = lastAc
    objOffset.skipSampleAcross = skipSampleAcross
    objOffset.firstSampleDown = offDn
    objOffset.lastSampleDown = lastDn
    objOffset.skipSampleDown = skipSampleDown
    objOffset.acrossGrossOffset = rgoffset
    objOffset.downGrossOffset = azoffset
    objOffset.debugFlag = False
    objOffset.displayFlag = False
    objOffset.windowSizeWidth = refChipWidth
    objOffset.windowSizeHeight = refChipHeight
    objOffset.searchWindowSizeWidth = schMarginX
    objOffset.searchWindowSizeHeight = schMarginY
    objOffset.zoomWindowSize = 8
    objOffset.oversamplingFactor = 16
    objOffset.thresholdSNR = .001
    objOffset.thresholdCov = 1000.
    objOffset.scaleFactorX = scaleFactorX
    objOffset.scaleFactorY = scaleFactorY
    objOffset.acrossLooks = 1
    objOffset.downLooks = 1
    
    objOffset.runAmpcor()
    
    numElem = objOffset.numElem # numRowTable
    locationAcross = np.zeros(numElem, dtype=int)
    locationAcrossOffset = np.zeros(numElem, dtype=np.float32)
    locationDown = np.zeros(numElem, dtype=int)
    locationDownOffset = np.zeros(numElem, dtype=np.float32)
    snrRet = np.zeros(numElem, dtype=np.float32)
    cov1Ret = np.zeros(numElem, dtype=np.float32)
    cov2Ret = np.zeros(numElem, dtype=np.float32)
    cov3Ret = np.zeros(numElem, dtype=np.float32)
    for i in range(numElem):
        locationAcross[i] = objOffset.getLocationAcrossAt(i)
        locationAcrossOffset[i] = objOffset.getLocationAcrossOffsetAt(i)
        locationDown[i] = objOffset.getLocationDownAt(i)
        locationDownOffset[i] = objOffset.getLocationDownOffsetAt(i)
        snrRet[i] = objOffset.getSNRAt(i)
        cov1Ret[i] = objOffset.getCov1At(i)
        cov2Ret[i] = objOffset.getCov2At(i)
        cov3Ret[i] = objOffset.getCov3At(i)

    ### Back to refineSecondaryTiming.py from Ampcor.py
    sar.finalizeImage()
    sim.finalizeImage()
    
    result = OffsetField()
    for i in range(numElem):
        across = locationAcross[i]
        down = locationDown[i]
        acrossOffset = locationAcrossOffset[i]
        downOffset = locationDownOffset[i]
        snr = snrRet[i]
        sigx = cov1Ret[i]
        sigy = cov2Ret[i]
        sigxy = cov3Ret[i]
        offset = Offset()
        offset.setCoordinate(across,down)
        offset.setOffset(acrossOffset,downOffset)
        offset.setSignalToNoise(snr)
        offset.setCovariance(sigx,sigy,sigxy)
        result.addOffset(offset)
    
    return result
コード例 #4
0
                        x1 = offset.x * swathReference.rangePixelSize / swathReferenceResampled.rangePixelSize + \
                             (swathReference.startingRange - swathReferenceResampled.startingRange) / swathReferenceResampled.rangePixelSize
                        y1 = offset.y * swathReference.azimuthLineInterval / swathReferenceResampled.azimuthLineInterval + \
                             (swathReference.sensingStart - swathReferenceResampled.sensingStart).total_seconds() / swathReferenceResampled.azimuthLineInterval

                        x3 = offset.x + offset.dx
                        y3 = offset.y + offset.dy

                        dx = x3 - x1
                        dy = y3 - y1

                        offsetUpdate.setCoordinate(x1, y1)
                        offsetUpdate.setOffset(dx, dy)
                        offsetUpdate.setSignalToNoise(offset.snr)
                        offsetUpdate.setCovariance(offset.sigmax,
                                                   offset.sigmay,
                                                   offset.sigmaxy)
                        offsetsUpdated.addOffset(offsetUpdate)

                    azimuthPoly, rangePoly = offsetsUpdated.getFitPolynomials(
                        rangeOrder=2,
                        azimuthOrder=2,
                        maxOrder=True,
                        usenumpy=False)

                    #check polynomial accuracy
                    if DEBUG:
                        print()
                        print(
                            '       x            y            dx          dy         dx(poly)    dy(poly)    dx - dx(poly)  dy - dy(poly)'
                        )