Esempio n. 1
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]]
            #sign = self.sig[indxA[j]]
            offset.setCoordinate(across, down)
            offset.setOffset(acrossOffset, downOffset)
            offset.setSignalToNoise(snr)
            offsets.addOffset(offset)

        return offsets
Esempio n. 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
Esempio n. 3
0
def readOffset(filename):

    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
Esempio n. 4
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)
Esempio n. 5
0
class Fitoff(Component):

    logging_name = "mroipac.fitoff"

    dictionaryOfVariables = {
        'NUMBER_OF_SIGMAS': ['nSigma', float, True],
        'MAX_RMS': ['maxRMS', float, True],
        'NUM_POINTS': ['numPoints', int, True],
        'MIN_ITER': ['minIter', int, True],
        'MAX_ITER': ['maxIter', int, True],
        'MIN_PONTS': ['minPoints', int, True],
    }
    dictionaryOfOutputVariables = {
        'AFFINE_TRANSFORM': 'affineTransform',
        'AVERAGE_OFFSET_DOWN': 'averageOffsetDown',
        'AVERAGE_OFFSET_ACROSS': 'averageOffsetAcross'
    }

    @dov
    @logged
    def __init__(self):
        super(Fitoff, self).__init__()
        self.numPoints = 0
        self.maxRMS = 0.08
        self.nSigma = 1.5
        self.minPoints = 50
        self.minIter = 3
        self.maxIter = 30
        self.useL1norm = True
        self.affineTransform = []
        self.averageOffsetDown = None
        self.averageOffsetAcross = None
        self.numPoints = None
        self.locationAcross = []
        self.locationAcrossOffset = []
        self.locationDown = []
        self.locationDownOffset = []
        self.distance = None
        self.snr = []
        self.cov_across = []
        self.cov_down = []
        self.cov_cross = []
        self.numRefined = None
        self.refinedOffsetField = None
        self.createPorts()
        #        self.stdWriter = None
        return None

    def createPorts(self):
        self._inputPorts.add(Port(name='offsets', method=self.addOffsets))
        return None

    def fitoff(self):
        for port in self._inputPorts:
            method = port.getMethod()
            method()

        self.numPoints = len(self.locationAcross)
        self.allocateArrays()

        self.setState()
        fitoff.fitoff_Py()
        self.getState()
        self.deallocateArrays()

    def setState(self):
        fitoff.setStdWriter_Py(int(self.stdWriter))
        fitoff.setLocationAcross_Py(self.locationAcross, self.numPoints)
        fitoff.setLocationAcrossOffset_Py(self.locationAcrossOffset,
                                          self.numPoints)
        fitoff.setLocationDown_Py(self.locationDown, self.numPoints)
        fitoff.setLocationDownOffset_Py(self.locationDownOffset,
                                        self.numPoints)
        fitoff.setSNR_Py(self.snr, self.numPoints)
        fitoff.setCovDown_Py(self.cov_down, self.numPoints)
        fitoff.setCovAcross_Py(self.cov_across, self.numPoints)
        fitoff.setCovCross_Py(self.cov_cross, self.numPoints)
        fitoff.setMaxRms_Py(self.maxRMS)
        fitoff.setNSig_Py(self.nSigma)
        fitoff.setMinPoint_Py(self.minPoints)
        fitoff.setL1normFlag_Py(int(self.useL1norm))
        fitoff.setMinIter_Py(self.minIter)
        fitoff.setMaxIter_Py(self.maxIter)

    def setNumberOfPoints(self, var):
        self.numPoints = int(var)

    def setLocationAcross(self, var):
        self.locationAcross = var

    def setLocationAcrossOffset(self, var):
        self.locationAcrossOffset = var

    def setLocationDown(self, var):
        self.locationDown = var

    def setLocationDownOffset(self, var):
        self.locationDownOffset = var

    def setCov_Across(self, var):
        self.cov_across = var

    def setCov_Down(self, var):
        self.covDown = var

    def setCov_Cross(self, var):
        self.cov_cross = var

    def setNSigma(self, var):
        self.nSigma = var

    def setMaxRMS(self, var):
        self.maxRms = var

    def setSNR(self, var):
        self.snr = var

    def setMinPoints(self, var):
        self.minPoints = var

#    def stdWriter(self, var):
#        self.stdWriter = var

    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 getAverageOffsetDown(self):
        return self.averageOffsetDown

    def getAverageOffsetAcross(self):
        return self.averageOffsetAcross

    def getRefinedLocations(self):
        indxA = self.indexArray
        numArrays = 6
        retList = [[0] * len(indxA) for i in range(numArrays)]
        for j in range(len(retList[0])):
            retList[0][j] = self.locationAcross[indxA[j]]
            retList[1][j] = self.locationAcrossOffset[indxA[j]]
            retList[2][j] = self.locationDown[indxA[j]]
            retList[3][j] = self.locationDownOffset[indxA[j]]
            retList[4][j] = self.snr[indxA[j]]
            retList[5][j] = self.sig[indxA[j]]

        return retList

    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

    def allocateArrays(self):
        if self.numPoints is None:
            self.numPoints = len(self.locationAcross)

        fitoff.setNumberLines_Py(int(self.numPoints))
        fitoff.allocateArrays_Py(int(self.numPoints))
        return

    def deallocateArrays(self):
        fitoff.deallocateArrays_Py()

    def addOffsets(self):
        offsets = self._inputPorts.getPort('offsets').getObject()
        if offsets:
            try:
                for offset in offsets:
                    across, down = offset.getCoordinate()
                    acrossOffset, downOffset = offset.getOffset()
                    snr = offset.getSignalToNoise()
                    cova, covd, covx = offset.getCovariance()
                    self.locationAcross.append(across)
                    self.locationDown.append(down)
                    self.locationAcrossOffset.append(acrossOffset)
                    self.locationDownOffset.append(downOffset)
                    self.snr.append(snr)
                    self.cov_across.append(
                        cova)  # Sigmas used in the inversion
                    self.cov_down.append(covd)
                    self.cov_cross.append(covx)
            except AttributeError as strerr:
                self.logger.error(strerr)
                raise AttributeError("Unable to wire Offset port")
            pass
        pass

    pass
Esempio n. 6
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
Esempio n. 7
0
                        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