Exemple #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
 def setUp(self):
     self.offsetField = OffsetField()
     for i in range(10):
         snr = 1.0
         if (i == 5):
             snr = 0.3
         elif (i == 8):
             snr = 0.1
         offset = Offset(x=i, y=i, dx=1, dy=2, snr=snr)
         self.offsetField.addOffset(offset)
def runOffsetprf(self):

    # dummy zero-valued offset field
    offField = OffsetField()
    for i in range(200):
        offField.addOffset(Offset(10 + i, 10 + i, 0, 0, 10, 1, 1, 0))

    # save the input offset field for the record
    self._insar.setOffsetField(offField)
    self._insar.setRefinedOffsetField(offField)
Exemple #4
0
def runRgoffset(self):

    # dummy zero-valued offset field
    for pair in self._isce.pairsToCoreg:
        offField = OffsetField()
        for i in range(200):
            offField.addOffset(Offset(10 + i, 10 + i, 0, 0, 10, 1, 1, 0))

        # save the input offset field for the record
        self._isce.offsetFields[pair] = offField
        self._isce.refinedOffsetFields[pair] = offField
Exemple #5
0
    def getState(self):
        #Notice that we allocated a larger size since it was not known a priori, but when we retrieve the data we only retrieve the valid ones
        self.affineVec = fitoff.getAffineVector_Py()
        self.averageOffsetAcross = self.affineVec[4]
        self.averageOffsetDown = self.affineVec[5]
        self.numRefined = fitoff.getNumberOfRefinedOffsets_Py()
        retList = fitoff.getRefinedOffsetField_Py(self.numRefined)

        self.refinedOffsetField = OffsetField()
        for value in retList:
            oneoff = Offset(value[0], value[1], value[2], value[3], value[4],
                            value[5], value[6], value[7])
            self.refinedOffsetField.addOffset(oneoff)

        return
    def getOffsetField(self):
        """Return and OffsetField object instead of an array of results"""
        offsets = OffsetField()
        for i in range(len(self.locationAcross)):
            across = self.locationAcross[i]
            down = self.locationDown[i]
            acrossOffset = self.locationAcrossOffset[i]
            downOffset = self.locationDownOffset[i]
            snr = self.snrRet[i]
            offset = Offset()
            offset.setCoordinate(across,down)
            offset.setOffset(acrossOffset,downOffset)
            offset.setSignalToNoise(snr)
            offsets.addOffset(offset)

        return offsets
Exemple #7
0
def cullOffsetbyMean(offsets, azimuthOffsetMean, threshold):
    import isce
    import isceobj
    from isceobj.Location.Offset import OffsetField, Offset

    culledOffsetField = OffsetField()
    i = 0
    for offset in offsets:
        if abs(offset.dy - azimuthOffsetMean) > threshold:
            i += 1
        else:
            culledOffsetField.addOffset(offset)

    print("{} offsets culled, with azimuth mean offset: {} and threshold: {}".
          format(i, azimuthOffsetMean, threshold))
    return culledOffsetField
Exemple #8
0
    def getRefinedOffsetField(self):
        offsets = OffsetField()

        indxA = self.indexArray
        for j in range(len(indxA)):
            offset = Offset()
            across = self.locationAcross[indxA[j]]
            down = self.locationDown[indxA[j]]
            acrossOffset = self.locationAcrossOffset[indxA[j]]
            downOffset = self.locationDownOffset[indxA[j]]
            snr = self.snr[indxA[j]]
            offset.setCoordinate(across, down)
            offset.setOffset(acrossOffset, downOffset)
            offset.setSignalToNoise(snr)
            offsets.addOffset(offset)

        return offsets
Exemple #9
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
Exemple #10
0
    def resample(self,frame,doppler):
        """
        Resample the VH and VV polarizations by 0.5 pixels in azimuth.

        @param frame (\a isceobj.Scene.Frame) the Frame object for the SAR data
        """
        import isceobj
        import stdproc
        from isceobj import Constants
        from isceobj.Location.Offset import Offset, OffsetField

        instrument = frame.instrument
        fs = instrument.getRangeSamplingRate()
        pixelSpacing = Constants.SPEED_OF_LIGHT/(2.0*fs) #2013-06-03 Kosal: change in constant name
        filename = frame.getImage().getFilename()
        slcFilename = filename.replace('.raw','.slc')
        resampledFilename = filename.replace('.raw','.resampled.slc')

        # Create the SLC image
        slcImage = isceobj.createSlcImage()
        slcImage.setFilename(slcFilename)
        slcImage.setAccessMode('read')
        slcImage.setDataType('CFLOAT')
        slcImage.setWidth(self.width)
        slcImage.createImage()

        # Create the resampled SLC image
        resampledSlcImage = isceobj.createSlcImage()
        resampledSlcImage.setFilename(resampledFilename)
        resampledSlcImage.setAccessMode('write')
        resampledSlcImage.setDataType('CFLOAT')
        resampledSlcImage.setWidth(self.width)
        resampledSlcImage.createImage()

        # Create an offset field with constant 0.5 pixel shifts in azimuth
        offsetField = OffsetField()
        for i in range(0, self.length,100):
            for j in range(0, self.width,100):
                dx = 0.0
                dy = -0.5
                offset = Offset()
                offset.setCoordinate(j,i)
                offset.setOffset(dx,dy)
                offset.setSignalToNoise(10.0)
                offsetField.addOffset(offset)

        self.logger.debug("width: %s" % (self.width))
        self.logger.debug("length: %s" % (self.length))
        self.logger.debug("Pixel Spacing: %s" % (pixelSpacing))
        self.logger.debug("doppler : %s" % (doppler))
        fp = open('offsetField','w')
        fp.write(str(offsetField))
        fp.close()

        #2013-06-03 Kosal: change resamp_only to resamp_slc, which resamples only an SLC
        #(took resamp_only from revision 747)
        resamp = stdproc.createResamp_slc()
        resamp.setNumberLines(self.length)
        resamp.setNumberRangeBin(self.width)
        resamp.setNumberFitCoefficients(1)
        resamp.setSlantRangePixelSpacing(pixelSpacing)
        resamp.setDopplerCentroidCoefficients([doppler, 0.0, 0.0, 0.0])
        resamp.wireInputPort(name='offsets', object=offsetField)
        resamp.wireInputPort(name='instrument', object=instrument)

        # updated 07/24/2012
        resamp.stdWriter = self._writer_set_file_tags(
            "resamp_slc", "log", "err", "out"
            )

        # updated 07/24/2012
        resamp.resamp_slc(slcImage, resampledSlcImage)
        #Kosal

        slcImage.finalizeImage()
        resampledSlcImage.finalizeImage()

        # Rename the resampled slcs
        os.rename(resampledFilename,slcFilename)
Exemple #11
0
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
                        print('azimuthPoly._normRange: {}'.format(
                            azimuthPoly._normRange))
                        print('azimuthPoly._meanAzimuth: {}'.format(
                            azimuthPoly._meanAzimuth))
                        print('azimuthPoly._normAzimuth: {}'.format(
                            azimuthPoly._normAzimuth))
                        print()

                else:
                    offsets = readOffset(
                        os.path.join(dateDirs[idate], frameDir, swathDir,
                                     'cull.off'))
                    #                                                   x1                      x2                 x3
                    #                                                   y1                      y2                 y3
                    #create new offset field to save offsets: swathReferenceResampled --> swathReference --> swathSecondary
                    offsetsUpdated = OffsetField()

                    for offset in offsets:
                        offsetUpdate = Offset()

                        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