Exemplo n.º 1
0
def mskLooks(inps):

    inWidth = getWidth(inps.input + '.xml')
    inLength = getLength(inps.input + '.xml')
    outWidth = int(inWidth / inps.rlks)
    outLength = int(inLength / inps.alks)

    #look_msk infile outfile nrg nrlks nalks
    #run program here
    cmd = '$INSAR_ZERODOP_BIN/look_msk {} {} {} {} {}'.format(
        inps.input, inps.output, inWidth, inps.rlks, inps.alks)
    runCmd(cmd)

    #get xml file for interferogram
    image = isceobj.createImage()
    accessMode = 'read'
    dataType = 'BYTE'
    bands = 1
    scheme = 'BIL'
    width = outWidth
    image.initImage(inps.output,
                    accessMode,
                    width,
                    dataType,
                    bands=bands,
                    scheme=scheme)
    descr = 'Radar shadow-layover mask. 1 - Radar Shadow. 2 - Radar Layover. 3 - Both.'
    image.addDescription(descr)
    image.renderHdr()
Exemplo n.º 2
0
def intLooks(inps):

    inWidth = getWidth(inps.input + '.xml')
    inLength = getLength(inps.input + '.xml')
    outWidth = int(inWidth / inps.rlks)
    outLength = int(inLength / inps.alks)

    #run program here
    cmd = '$INSAR_ZERODOP_BIN/look {} {} {} {} {} 4 0 0'.format(
        inps.input, inps.output, inWidth, inps.rlks, inps.alks)
    runCmd(cmd)

    #get xml file for interferogram
    create_xml(inps.output, outWidth, outLength, 'int')
Exemplo n.º 3
0
def ampLooks(inps):

    inWidth = getWidth(inps.input + '.xml')
    inLength = getLength(inps.input + '.xml')
    outWidth = int(inWidth / inps.rlks)
    outLength = int(inLength / inps.alks)

    #run it
    #cmd = 'echo -e "{}\n{}\n{} {}\n{} {}\n" | $INSAR_ZERODOP_BIN/rilooks'.format(inps.input, inps.output, inWidth, inLength, inps.rlks, inps.alks)
    #it seems that echo does not require -e in this situation, strange
    cmd = '$INSAR_ZERODOP_BIN/look {} {} {} {} {} 4 1 0'.format(
        inps.input, inps.output, inWidth, inps.rlks, inps.alks)
    runCmd(cmd)

    #get xml file for amplitude image
    create_xml(inps.output, outWidth, outLength, 'amp')
Exemplo n.º 4
0
def hgtLooks(inps):

    inWidth = getWidth(inps.input + '.xml')
    inLength = getLength(inps.input + '.xml')
    outWidth = int(inWidth / inps.rlks)
    outLength = int(inLength / inps.alks)

    #look_msk infile outfile nrg nrlks nalks
    #run program here
    cmd = '$INSAR_ZERODOP_BIN/look {} {} {} {} {} 3 0 1'.format(
        inps.input, inps.output, inWidth, inps.rlks, inps.alks)
    runCmd(cmd)

    #get xml
    image = isceobj.createImage()
    accessMode = 'read'
    dataType = 'DOUBLE'
    width = outWidth
    image.initImage(inps.output, accessMode, width, dataType)

    image.addDescription('Pixel-by-pixel height in meters.')
    image.renderHdr()
Exemplo n.º 5
0
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':

    inps = cmdLineParse()

    with open(inps.mframe, 'rb') as fid:
        masterFrame = pickle.load(fid)

    slantRangePixelSpacing = inps.rlks * 0.5 * SPEED_OF_LIGHT / masterFrame.rangeSamplingRate
    radarWavelength = masterFrame.radarWavelegth

    intfWidth = getWidth(inps.intf + '.xml')
    intfLength = getLength(inps.intf + '.xml')

    #run it
    cmd = "$INSAR_ZERODOP_BIN/flat {} {} {} {} {}".format(
        inps.intf, inps.rgoff, inps.dintf, slantRangePixelSpacing,
        radarWavelength)
    #print("{}".format(cmd))
    runCmd(cmd)

    #get xml file for interferogram
    create_xml(inps.dintf, intfWidth, intfLength, 'int')

    #./flat.py -m 20130927.slc.pck -i 20130927-20141211.int -r 20130927-20141211_rg.off -d diff_20130927-20141211.int
Exemplo n.º 6
0
            help = 'number of azimuth looks of the interferograms and amplitudes. default: 1')

    if len(sys.argv) <= 1:
        print('')
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':
    
    inps = cmdLineParse()

    masterWidth = getWidth(inps.master + '.xml')
    masterLength = getLength(inps.master + '.xml')

    slaveWidth = getWidth(inps.slave + '.xml')
    slaveLength = getLength(inps.slave + '.xml')


    if inps.offsetfile != None:
        refinedOffsets = readOffset(inps.offsetfile)

        if inps.slaveframe == None:
            slaveFrameName = inps.slave + '.pck'
        else:
            slaveFrameName = inps.slaveframe

        with open(slaveFrameName, 'rb') as f:
            slaveFrame = pickle.load(f)
Exemplo n.º 7
0
    if len(sys.argv) <= 1:
        print('')
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':
    
    inps = cmdLineParse()

    #get information
    masterWidth = getWidth(inps.master + '.xml')
    masterLength = getLength(inps.master + '.xml')

    #run interf
    cmd = "$INSAR_ZERODOP_BIN/interf {} {} {} {} {}".format(inps.master, inps.slave, inps.intf, inps.amp, masterWidth)
    #print("{}".format(cmd))
    runCmd(cmd)

    #get xml file for interferogram
    create_xml(inps.intf, masterWidth, masterLength, 'int')
    #get xml file for amplitude image
    create_xml(inps.amp, masterWidth, masterLength, 'amp')


    #./interf.py -m 20130927.slc -s 20141211.slc -i 20130927-20141211.int -a 20130927-20141211.amp

Exemplo n.º 8
0
                        help='azimuth looks')

    if len(sys.argv) <= 1:
        print('')
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':

    inps = cmdLineParse()

    ampWidth = getWidth(inps.amp + '.xml')
    ampLength = getLength(inps.amp + '.xml')
    lookAmpWidth = int(ampWidth / inps.rlks)
    lookAmpLength = int(ampLength / inps.alks)

    simWidth = getWidth(inps.sim + '.xml')
    simLength = getLength(inps.sim + '.xml')
    lookSimWidth = int(simWidth / inps.rlks)
    lookSimLength = int(simLength / inps.alks)

    #prepare parameters for ampcor
    lookAmp = 'float_{}rlks_{}alks.amp'.format(inps.rlks, inps.alks)
    lookSim = 'float_{}rlks_{}alks.sim'.format(inps.rlks, inps.alks)
    offsetFile = 'ampsim.off'

    numAzimuth = 30  #number of matches in azimuth
    numRange = 30  #number of matches in range
Exemplo n.º 9
0
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':

    inps = cmdLineParse()

    #ratio = 1.0e10
    ratio = inps.ratio
    print('master and slave scaling ratio: {}'.format(ratio))

    width = getWidth(inps.inf + '.xml')
    length = getLength(inps.inf + '.xml')

    #read master burst
    inf = np.fromfile(inps.inf, dtype=np.complex64).reshape(length, width)
    amp = np.fromfile(inps.amp, dtype=np.complex64).reshape(length, width)

    flag = (inf != 0) * (amp.real != 0) * (amp.imag != 0)
    nvalid = np.sum(flag, dtype=np.float64)

    mpwr1 = np.sqrt(
        np.sum(amp.real * amp.real * flag, dtype=np.float64) / nvalid)
    mpwr2 = np.sqrt(
        np.sum(amp.imag * amp.imag * flag, dtype=np.float64) / nvalid)

    amp.real = amp.real / ratio
    amp.imag = amp.imag / ratio * mpwr1 / mpwr2
Exemplo n.º 10
0
                        help='azimuth looks of the image')

    if len(sys.argv) <= 1:
        print('')
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':

    inps = cmdLineParse()

    inWidth = getWidth(inps.inimage + '.xml')
    inLength = getLength(inps.inimage + '.xml')
    outWidth = inWidth
    outLength = inLength

    with open(inps.aff) as f:
        lines = f.readlines()
        f.close

    i = 0
    for linex in lines:
        if 'Affine Matrix ' in linex:
            m11 = float(lines[i + 2].split()[0])
            m12 = float(lines[i + 2].split()[1])
            m21 = float(lines[i + 3].split()[0])
            m22 = float(lines[i + 3].split()[1])
            t1 = float(lines[i + 7].split()[0])
Exemplo n.º 11
0
def cal_offset(mframeFile, sframeFile, DEMfile):

    #master frame
    with open(mframeFile, 'rb') as f:
        mframe = pickle.load(f)

    #slave frame
    with open(sframeFile, 'rb') as f:
        sframe = pickle.load(f)

    #dem
    demImage = isceobj.createDemImage()
    demImage.load(DEMfile + '.xml')
    demImage.setAccessMode('read')

    latFile = 'tmp.lat'
    lonFile = 'tmp.lon'
    hgtFile = 'tmp.hgt'
    losFile = 'tmp.los'
    incFile = 'tmp.inc'
    mskFile = 'tmp.msk'

    rgoffFile = 'range.off'
    azoffFile = 'azimuth.off'

    ##########################################################################
    #offset calculation parameters
    masterOffsetFromStart = int(mframe.getNumberOfLines() /
                                2)  #number of lines
    masterNumberOfLines = 100  #number of lines
    slaveExtentionLines = 100000  #number of lines
    ##########################################################################

    #run topo
    runTopo(mframe,
            demImage,
            latName=latFile,
            lonName=lonFile,
            hgtName=hgtFile,
            losName=losFile,
            incName=incFile,
            mskName=mskFile,
            offsetFromStart=masterOffsetFromStart,
            numOfLines=masterNumberOfLines)

    latImage = isceobj.createImage()
    latImage.load(latFile + '.xml')
    latImage.setAccessMode('read')

    lonImage = isceobj.createImage()
    lonImage.load(lonFile + '.xml')
    lonImage.setAccessMode('read')

    hgtImage = isceobj.createDemImage()
    hgtImage.load(hgtFile + '.xml')
    hgtImage.setAccessMode('read')

    #run geo: extend file length by 2 * extentionLines, to make sure it overlaps with master
    runGeo2rdr(sframe,
               latImage,
               lonImage,
               hgtImage,
               rgoffName=rgoffFile,
               azoffName=azoffFile,
               extentionLines=slaveExtentionLines)

    #get range and azimuth offsets
    width = getWidth(rgoffFile + '.xml')
    length = getLength(rgoffFile + '.xml')
    rgoff = np.fromfile(rgoffFile, dtype=np.float32,
                        count=length * width).reshape(length, width)
    azoff = np.fromfile(azoffFile, dtype=np.float32,
                        count=length * width).reshape(length, width)

    #remove BAD_VALUE = -999999.0 as defined in geo2rdr.f90
    # http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.mean.html
    # In single precision, mean can be inaccurate
    # np.mean(a, dtype=np.float64)
    rgoffm = np.mean(rgoff[np.nonzero(rgoff != -999999.0)], dtype=np.float64)
    azoffm = np.mean(
        azoff[np.nonzero(azoff != -999999.0)],
        dtype=np.float64) - masterOffsetFromStart - slaveExtentionLines

    print('\noffsets from geometrical calculation:')
    print('++++++++++++++++++++++++++++++++++++++')
    print('range offset: {}'.format(rgoffm))
    print('azimuth offset: {}\n'.format(azoffm))

    #tidy up
    os.remove(latFile)
    os.remove(latFile + '.xml')
    os.remove(latFile + '.vrt')
    os.remove(lonFile)
    os.remove(lonFile + '.xml')
    os.remove(lonFile + '.vrt')
    os.remove(hgtFile)
    os.remove(hgtFile + '.xml')
    os.remove(hgtFile + '.vrt')
    os.remove(losFile)
    os.remove(losFile + '.xml')
    os.remove(losFile + '.vrt')
    os.remove(incFile)
    os.remove(incFile + '.xml')
    os.remove(incFile + '.vrt')
    os.remove(mskFile)
    os.remove(mskFile + '.xml')
    os.remove(mskFile + '.vrt')

    os.remove(rgoffFile)
    os.remove(rgoffFile + '.xml')
    os.remove(rgoffFile + '.vrt')
    os.remove(azoffFile)
    os.remove(azoffFile + '.xml')
    os.remove(azoffFile + '.vrt')

    return [rgoffm, azoffm]
Exemplo n.º 12
0
        'coherence threshhold for phase difference calculation. Default: 0.1')

    if len(sys.argv) <= 1:
        print('')
        parser.print_help()
        sys.exit(1)
    else:
        return parser.parse_args()


if __name__ == '__main__':

    inps = cmdLineParse()

    width = getWidth(inps.unwl + '.xml')
    length = getLength(inps.unwl + '.xml')

    unwl = (np.fromfile(inps.unwl,
                        dtype=np.float32).reshape(length * 2,
                                                  width))[1:length * 2:2, :]
    unwu = (np.fromfile(inps.unwu,
                        dtype=np.float32).reshape(length * 2,
                                                  width))[1:length * 2:2, :]
    cor = (np.fromfile(inps.cor,
                       dtype=np.float32).reshape(length * 2,
                                                 width))[1:length * 2:2, :]

    ccl = np.fromfile(inps.ccl, dtype=np.int8).reshape(length, width)
    ccu = np.fromfile(inps.ccu, dtype=np.int8).reshape(length, width)

    flag = (unwl != 0) * (unwu != 0) * (cor >= inps.cot) * (ccl > 0) * (ccu >
Exemplo n.º 13
0
def runFilter(inps):
    logger.info("Applying power-spectral filter")

    #get width from the header file of input interferogram
    width = getWidth(inps.intf + '.xml')
    length = getLength(inps.intf + '.xml')

    if shutil.which('psfilt1') != None:
        cmd = "psfilt1 {int} {filtint} {width} {filterstrength} 64 16".format(
               int = inps.intf,
               filtint = inps.fintf,
               width = width,
               filterstrength = inps.alpha
               )
        runCmd(cmd)

        #get xml file for interferogram
        create_xml(inps.fintf, width, length, 'int')
    else:
        #create flattened interferogram
        intImage = isceobj.createIntImage()
        intImage.setFilename(inps.intf)
        intImage.setWidth(width)
        intImage.setAccessMode('read')
        intImage.createImage()

        #create the filtered interferogram
        filtImage = isceobj.createIntImage()
        filtImage.setFilename(inps.fintf)
        filtImage.setWidth(width)
        filtImage.setAccessMode('write')
        filtImage.createImage()

        #create filter and run it
        objFilter = Filter()
        objFilter.wireInputPort(name='interferogram',object=intImage)
        objFilter.wireOutputPort(name='filtered interferogram',object=filtImage)
        objFilter.goldsteinWerner(alpha=inps.alpha)

        intImage.finalizeImage()
        filtImage.finalizeImage()
        del filtImage


    #recreate filt image to read
    filtImage = isceobj.createIntImage()
    filtImage.setFilename(inps.fintf)
    filtImage.setWidth(width)
    filtImage.setAccessMode('read')
    filtImage.createImage()

    #create amplitude image
    ampImage = isceobj.createAmpImage()
    ampImage.setFilename(inps.amp)
    ampImage.setWidth(width)
    ampImage.setAccessMode('read')
    ampImage.createImage()

    #create phase sigma correlation file here
    phsig_tmp = 'tmp.phsig'
    phsigImage = isceobj.createImage()
    phsigImage.setFilename(phsig_tmp)
    phsigImage.setWidth(width)
    phsigImage.dataType='FLOAT'
    phsigImage.bands = 1
    phsigImage.setImageType('cor')#the type in this case is not for mdx.py displaying but for geocoding method
    phsigImage.setAccessMode('write')
    phsigImage.createImage()

    #create icu and run it
    icuObj = Icu(name='insarapp_filter_icu')
    icuObj.configure()
    icuObj.unwrappingFlag = False
    icuObj.icu(intImage = filtImage, ampImage=ampImage, phsigImage=phsigImage)
    
    phsigImage.renderHdr()

    filtImage.finalizeImage()
    ampImage.finalizeImage()
    phsigImage.finalizeImage()

    # #add an amplitude channel to phsig file
    # cmd = "imageMath.py -e='sqrt(a_0*a_1)*(b!=0);b' --a={amp} --b={phsig_tmp} -o {phsig} -s BIL".format(
    #        amp = inps.amp,
    #        phsig_tmp = phsig_tmp,
    #        phsig = inps.phsig
    #        )

    #add an amplitude channel to phsig file
    cmd = "imageMath.py -e='sqrt(a_0*a_1)*(b!=0);b' --a={amp} --b={phsig_tmp} -o {phsig} -s BIL".format(
           amp = inps.amp,
           phsig_tmp = phsig_tmp,
           phsig = inps.phsig
           )


    runCmd(cmd)

    #remove the original phsig file
    os.remove(phsig_tmp)
    os.remove(phsig_tmp + '.xml')
    os.remove(phsig_tmp + '.vrt')

    
    #rename original filtered interferogram
    filt_tmp = 'filt_tmp.int'
    os.rename(inps.fintf, filt_tmp)
    os.rename(inps.fintf + '.xml', filt_tmp + '.xml')
    os.rename(inps.fintf + '.vrt', filt_tmp + '.vrt')
    
    #do the numpy calculations
    #replace the magnitude of the filtered interferogram with magnitude of original interferogram
    #mask output file using layover mask (values 2 and 3).
    # cmd = "imageMath.py -e='a/(abs(a)+(abs(a)==0))*abs(b)*(c<2)' --a={0} --b={1} --c={2} -t CFLOAT -o={3}".format(
    #       filt_tmp,
    #       inps.intf,
    #       inps.msk,
    #       inps.fintf
    #     )

    #replacing magnitude is not good for phase unwrapping using snaphu
    cmd = "imageMath.py -e='a*(b<2)' --a={0} --b={1} -t CFLOAT -o={2}".format(
          filt_tmp,
          inps.msk,
          inps.fintf
        )

    runCmd(cmd)
    
    #remove the original filtered interferogram
    os.remove(filt_tmp)
    os.remove(filt_tmp + '.xml')
    os.remove(filt_tmp + '.vrt')