Ejemplo n.º 1
0
def estimateOffsetField(master, slave, inps=None):
    '''
    Estimate offset field between burst and simamp.
    '''

    ###Loading the slave image object
    sim = isceobj.createSlcImage()
    sim.load(slave + '.xml')
    sim.setAccessMode('READ')
    sim.createImage()

    ###Loading the master image object
    sar = isceobj.createSlcImage()
    sar.load(master + '.xml')
    sar.setAccessMode('READ')
    sar.createImage()

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

    objOffset = DenseAmpcor(name='dense')
    objOffset.configure()

    #   objOffset.numberThreads = 6
    objOffset.setWindowSizeWidth(inps.winwidth)
    objOffset.setWindowSizeHeight(inps.winhgt)
    objOffset.setSearchWindowSizeWidth(inps.srcwidth)
    objOffset.setSearchWindowSizeHeight(inps.srchgt)
    objOffset.skipSampleAcross = inps.skipwidth
    objOffset.skipSampleDown = inps.skiphgt
    objOffset.margin = inps.margin
    objOffset.oversamplingFactor = inps.oversample

    objOffset.setAcrossGrossOffset(inps.rgshift)
    objOffset.setDownGrossOffset(inps.azshift)

    ##  For Debug
    #    print(vars(inps))
    #    pprint(vars(inps))
    #    print(stop)

    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)

    #    print(sar.dataType)
    if sar.dataType.startswith('C'):
        objOffset.setImageDataType1('mag')
    else:
        objOffset.setImageDataType1('real')

    if sim.dataType.startswith('C'):
        objOffset.setImageDataType2('mag')
    else:
        objOffset.setImageDataType2('real')

    objOffset.offsetImageName = inps.outprefix + '.bil'
    objOffset.snrImageName = inps.outprefix + '_snr.bil'

    objOffset.denseampcor(sar, sim)

    sar.finalizeImage()
    sim.finalizeImage()
    return objOffset
Ejemplo n.º 2
0
def runDenseOffsetCPU(self):
    '''
    Estimate dense offset field between a pair of SLCs.
    '''
    from mroipac.ampcor.DenseAmpcor import DenseAmpcor
    from isceobj.Alos2Proc.Alos2ProcPublic import runCmd

    ####For this module currently, we need to create an actual file on disk
    for infile in [
            self._insar.referenceSlc, self._insar.secondarySlcCoregistered
    ]:
        if os.path.isfile(infile):
            continue
        cmd = 'gdal_translate -of ENVI {0}.vrt {0}'.format(infile)
        runCmd(cmd)

    m = isceobj.createSlcImage()
    m.load(self._insar.referenceSlc + '.xml')
    m.setAccessMode('READ')

    s = isceobj.createSlcImage()
    s.load(self._insar.secondarySlcCoregistered + '.xml')
    s.setAccessMode('READ')

    #objOffset.numberThreads = 1
    print('\n************* dense offset estimation parameters *************')
    print('reference SLC: %s' % (self._insar.referenceSlc))
    print('secondary SLC: %s' % (self._insar.secondarySlcCoregistered))
    print('dense offset estimation window width: %d' %
          (self.offsetWindowWidth))
    print('dense offset estimation window hight: %d' %
          (self.offsetWindowHeight))
    print('dense offset search window width: %d' %
          (self.offsetSearchWindowWidth))
    print('dense offset search window hight: %d' %
          (self.offsetSearchWindowHeight))
    print('dense offset skip width: %d' % (self.offsetSkipWidth))
    print('dense offset skip hight: %d' % (self.offsetSkipHeight))
    print('dense offset covariance surface oversample factor: %d' %
          (self.offsetCovarianceOversamplingFactor))
    print('dense offset covariance surface oversample window size: %d\n' %
          (self.offsetCovarianceOversamplingWindowsize))

    objOffset = DenseAmpcor(name='dense')
    objOffset.configure()

    if m.dataType.startswith('C'):
        objOffset.setImageDataType1('complex')
    else:
        objOffset.setImageDataType1('real')
    if s.dataType.startswith('C'):
        objOffset.setImageDataType2('complex')
    else:
        objOffset.setImageDataType2('real')

    objOffset.offsetImageName = self._insar.denseOffset
    objOffset.snrImageName = self._insar.denseOffsetSnr
    objOffset.covImageName = self._insar.denseOffsetCov

    objOffset.setWindowSizeWidth(self.offsetWindowWidth)
    objOffset.setWindowSizeHeight(self.offsetWindowHeight)
    #NOTE: actual number of resulting correlation pixels: self.offsetSearchWindowWidth*2+1
    objOffset.setSearchWindowSizeWidth(self.offsetSearchWindowWidth)
    objOffset.setSearchWindowSizeHeight(self.offsetSearchWindowHeight)
    objOffset.setSkipSampleAcross(self.offsetSkipWidth)
    objOffset.setSkipSampleDown(self.offsetSkipHeight)
    objOffset.setOversamplingFactor(self.offsetCovarianceOversamplingFactor)
    objOffset.setZoomWindowSize(self.offsetCovarianceOversamplingWindowsize)
    objOffset.setAcrossGrossOffset(0)
    objOffset.setDownGrossOffset(0)
    #these are azimuth scaling factor
    #Matching Scale for Sample/Line Directions (-) = 1.000000551500 1.000002373200
    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)

    objOffset.denseampcor(m, s)

    ### Store params for later
    self._insar.offsetImageTopoffset = objOffset.locationDown[0][0]
    self._insar.offsetImageLeftoffset = objOffset.locationAcross[0][0]

    #change band order
    width = objOffset.offsetCols
    length = objOffset.offsetLines

    offset1 = np.fromfile(self._insar.denseOffset,
                          dtype=np.float32).reshape(length * 2, width)
    offset2 = np.zeros((length * 2, width), dtype=np.float32)
    offset2[0:length * 2:2, :] = offset1[1:length * 2:2, :]
    offset2[1:length * 2:2, :] = offset1[0:length * 2:2, :]

    os.remove(self._insar.denseOffset)
    os.remove(self._insar.denseOffset + '.vrt')
    os.remove(self._insar.denseOffset + '.xml')

    offset2.astype(np.float32).tofile(self._insar.denseOffset)
    outImg = isceobj.createImage()
    outImg.setDataType('FLOAT')
    outImg.setFilename(self._insar.denseOffset)
    outImg.setBands(2)
    outImg.scheme = 'BIL'
    outImg.setWidth(width)
    outImg.setLength(length)
    outImg.addDescription(
        'two-band pixel offset file. 1st band: range offset, 2nd band: azimuth offset'
    )
    outImg.setAccessMode('read')
    outImg.renderHdr()

    return (objOffset.offsetCols, objOffset.offsetLines)
Ejemplo n.º 3
0
def estimateOffsetField(master, slave, denseOffsetFileName,
                        ww=64, wh=64,
                        sw=20, shh=20,
                        kw=32, kh=32):
    '''
    Estimate offset field between burst and simamp.
    '''

    ###Loading the slave image object
    sim = isceobj.createSlcImage()
    sim.load(slave+'.xml')
    sim.setAccessMode('READ')
    sim.createImage()

    ###Loading the master image object
    sar = isceobj.createSlcImage()
    sar.load(master + '.xml')
    sar.setAccessMode('READ')
    sar.createImage()

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

    objOffset = DenseAmpcor(name='dense')
    objOffset.configure()

#   objOffset.numberThreads = 6
    objOffset.setWindowSizeWidth(ww) #inps.winwidth)
    objOffset.setWindowSizeHeight(wh) #inps.winhgt)
    objOffset.setSearchWindowSizeWidth(sw) #inps.srcwidth)
    objOffset.setSearchWindowSizeHeight(shh) #inps.srchgt)
    objOffset.skipSampleAcross = kw #inps.skipwidth
    objOffset.skipSampleDown = kh #inps.skiphgt
    objOffset.margin = 50 #inps.margin
    objOffset.oversamplingFactor = 32  #inps.oversample

    objOffset.setAcrossGrossOffset(0) #inps.rgshift)
    objOffset.setDownGrossOffset(0) #inps.azshift)

    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)
    if sar.dataType.startswith('C'):
        objOffset.setImageDataType1('mag')
    else:
        objOffset.setImageDataType1('real')

    if sim.dataType.startswith('C'):
        objOffset.setImageDataType2('mag')
    else:
        objOffset.setImageDataType2('real')

    
    objOffset.offsetImageName = denseOffsetFileName + '.bil'
    objOffset.snrImageName = denseOffsetFileName +'_snr.bil'


    objOffset.denseampcor(sar, sim)

    sar.finalizeImage()
    sim.finalizeImage()
    return (objOffset.locationDown[0][0], objOffset.locationAcross[0][0])
Ejemplo n.º 4
0
def runDenseOffsetsCPU(self):
    '''
    Estimate dense offset field between merged master bursts and slave bursts.
    '''
    from mroipac.ampcor.DenseAmpcor import DenseAmpcor

    os.environ['VRT_SHARED_SOURCE'] = "0"

    print('\n============================================================')
    print('Configuring DenseAmpcor object for processing...\n')

    ### Determine appropriate filenames
    mf = 'master.slc'
    sf = 'slave.slc'

    if not ((self.numberRangeLooks == 1) and (self.numberAzimuthLooks == 1)):
        mf += '.full'
        sf += '.full'
    master = os.path.join(self._insar.mergedDirname, mf)
    slave = os.path.join(self._insar.mergedDirname, sf)

    ####For this module currently, we need to create an actual file on disk
    for infile in [master, slave]:
        if os.path.isfile(infile):
            continue
        cmd = 'gdal_translate -of ENVI {0}.vrt {0}'.format(infile)
        status = os.system(cmd)
        if status:
            raise Exception('{0} could not be executed'.format(status))

    ### Load the master object
    m = isceobj.createSlcImage()
    m.load(master + '.xml')
    m.setAccessMode('READ')
    #    m.createImage()

    ### Load the slave object
    s = isceobj.createSlcImage()
    s.load(slave + '.xml')
    s.setAccessMode('READ')
    #    s.createImage()

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

    objOffset = DenseAmpcor(name='dense')
    objOffset.configure()

    #    objOffset.numberThreads = 1
    ### Configure dense Ampcor object
    print('\nMaster frame: %s' % (mf))
    print('Slave frame: %s' % (sf))
    print('Main window size width: %d' % (self.winwidth))
    print('Main window size height: %d' % (self.winhgt))
    print('Search window size width: %d' % (self.srcwidth))
    print('Search window size height: %d' % (self.srchgt))
    print('Skip sample across: %d' % (self.skipwidth))
    print('Skip sample down: %d' % (self.skiphgt))
    print('Field margin: %d' % (self.margin))
    print('Oversampling factor: %d' % (self.oversample))
    print('Gross offset across: %d' % (self.rgshift))
    print('Gross offset down: %d\n' % (self.azshift))

    objOffset.setWindowSizeWidth(self.winwidth)
    objOffset.setWindowSizeHeight(self.winhgt)
    objOffset.setSearchWindowSizeWidth(self.srcwidth)
    objOffset.setSearchWindowSizeHeight(self.srchgt)
    objOffset.skipSampleAcross = self.skipwidth
    objOffset.skipSampleDown = self.skiphgt
    objOffset.oversamplingFactor = self.oversample
    objOffset.setAcrossGrossOffset(self.rgshift)
    objOffset.setDownGrossOffset(self.azshift)

    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)
    if m.dataType.startswith('C'):
        objOffset.setImageDataType1('mag')
    else:
        objOffset.setImageDataType1('real')
    if s.dataType.startswith('C'):
        objOffset.setImageDataType2('mag')
    else:
        objOffset.setImageDataType2('real')

    objOffset.offsetImageName = os.path.join(self._insar.mergedDirname,
                                             self._insar.offsetfile)
    objOffset.snrImageName = os.path.join(self._insar.mergedDirname,
                                          self._insar.snrfile)

    print('Output dense offsets file name: %s' % (objOffset.offsetImageName))
    print('Output SNR file name: %s' % (objOffset.snrImageName))
    print('\n======================================')
    print('Running dense ampcor...')
    print('======================================\n')

    objOffset.denseampcor(m, s)  ### Where the magic happens...

    ### Store params for later
    self._insar.offset_width = objOffset.offsetCols
    self._insar.offset_length = objOffset.offsetLines
    self._insar.offset_top = objOffset.locationDown[0][0]
    self._insar.offset_left = objOffset.locationAcross[0][0]
Ejemplo n.º 5
0
def runDenseOffsets(self):
    '''
    Estimate dense offset field between merged master bursts and slave bursts.
    '''

    os.environ['VRT_SHARED_SOURCE'] = "0"

    if not self.doDenseOffsets:
        print('Dense offsets not requested. Skipping ....')
        return

    print('\n============================================================')
    print('Configuring DenseAmpcor object for processing...\n')

    ### Determine appropriate filenames
    mf = 'master.slc'
    sf = 'slave.slc'
    if not ((self.numberRangeLooks == 1) and (self.numberAzimuthLooks == 1)):
        mf += '.full'
        sf += '.full'
    master = os.path.join(self._insar.mergedDirname, mf)
    slave = os.path.join(self._insar.mergedDirname, sf)

    ### Load the master object
    m = isceobj.createSlcImage()
    m.load(master + '.xml')
    m.setAccessMode('READ')
    #    m.createImage()

    ### Load the slave object
    s = isceobj.createSlcImage()
    s.load(slave + '.xml')
    s.setAccessMode('READ')
    #    s.createImage()

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

    objOffset = DenseAmpcor(name='dense')
    objOffset.configure()

    #    objOffset.numberThreads = 1
    ### Configure dense Ampcor object
    print('\nMaster frame: %s' % (mf))
    print('Slave frame: %s' % (sf))
    print('Main window size width: %d' % (self.winwidth))
    print('Main window size height: %d' % (self.winhgt))
    print('Search window size width: %d' % (self.srcwidth))
    print('Search window size height: %d' % (self.srchgt))
    print('Skip sample across: %d' % (self.skipwidth))
    print('Skip sample down: %d' % (self.skiphgt))
    print('Field margin: %d' % (self.margin))
    print('Oversampling factor: %d' % (self.oversample))
    print('Gross offset across: %d' % (self.rgshift))
    print('Gross offset down: %d\n' % (self.azshift))

    objOffset.setWindowSizeWidth(self.winwidth)
    objOffset.setWindowSizeHeight(self.winhgt)
    objOffset.setSearchWindowSizeWidth(self.srcwidth)
    objOffset.setSearchWindowSizeHeight(self.srchgt)
    objOffset.skipSampleAcross = self.skipwidth
    objOffset.skipSampleDown = self.skiphgt
    objOffset.oversamplingFactor = self.oversample
    objOffset.setAcrossGrossOffset(self.rgshift)
    objOffset.setDownGrossOffset(self.azshift)

    objOffset.setFirstPRF(1.0)
    objOffset.setSecondPRF(1.0)
    if m.dataType.startswith('C'):
        objOffset.setImageDataType1('mag')
    else:
        objOffset.setImageDataType1('real')
    if s.dataType.startswith('C'):
        objOffset.setImageDataType2('mag')
    else:
        objOffset.setImageDataType2('real')

    objOffset.offsetImageName = os.path.join(self._insar.mergedDirname,
                                             self._insar.offsetfile)
    objOffset.snrImageName = os.path.join(self._insar.mergedDirname,
                                          self._insar.snrfile)

    print('Output dense offsets file name: %s' % (objOffset.offsetImageName))
    print('Output SNR file name: %s' % (objOffset.snrImageName))
    print('\n======================================')
    print('Running dense ampcor...')
    print('======================================\n')

    objOffset.denseampcor(m, s)  ### Where the magic happens...

    ### Store params for later
    self._insar.offset_width = objOffset.offsetCols
    self._insar.offset_length = objOffset.offsetLines
    self._insar.offset_top = objOffset.locationDown[0][0]
    self._insar.offset_left = objOffset.locationAcross[0][0]