Ejemplo 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()
Ejemplo 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')
Ejemplo n.º 3
0
def coherence(inps, method="phase_gradient"):

    #logger.info("Calculating Coherence")

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

    # Initialize the amplitude
    ampImage = isceobj.createAmpImage()
    ampImage.setFilename(inps.amp)
    ampImage.setWidth(width)
    ampImage.setAccessMode('read')
    ampImage.createImage()
    #ampImage = self.insar.getResampOnlyAmp().copy(access_mode='read')

    # Initialize the flattened inteferogram
    intImage = isceobj.createIntImage()
    intImage.setFilename(inps.intf)
    intImage.setWidth(width)
    intImage.setAccessMode('read')
    intImage.createImage()

    # Create the coherence image
    #there is no coherence image in the isceobj/Image
    cohImage = isceobj.createOffsetImage()
    cohImage.setFilename(inps.cor)
    cohImage.setWidth(width)
    cohImage.setAccessMode('write')
    cohImage.createImage()

    cor = Correlation()
    cor.configure()
    cor.wireInputPort(name='interferogram', object=intImage)
    cor.wireInputPort(name='amplitude', object=ampImage)
    cor.wireOutputPort(name='correlation', object=cohImage)
    cor.windowSize = inps.winsize

    cohImage.finalizeImage()
    intImage.finalizeImage()
    ampImage.finalizeImage()

    try:
        CORRELATION_METHOD[method](cor)
    except KeyError:
        print("Unrecognized correlation method")
        sys.exit(1)
        pass
    return None
Ejemplo n.º 4
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')
Ejemplo n.º 5
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()
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    parser.add_argument('-alks', dest='alks', type=int, default=1,
            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:
Ejemplo n.º 8
0
            help = '(output) amplitudes of master and slave SLCs')

    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
Ejemplo n.º 9
0
                        default=1,
                        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
Ejemplo n.º 10
0
        print('')
        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
Ejemplo n.º 11
0
                        default=1,
                        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])
Ejemplo n.º 12
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]
Ejemplo n.º 13
0
        help=
        '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)
Ejemplo n.º 14
0
def runUnwrap(inps,
              costMode=None,
              initMethod=None,
              defomax=None,
              initOnly=None):

    if costMode is None:
        costMode = 'DEFO'

    if initMethod is None:
        initMethod = 'MST'

    if defomax is None:
        defomax = 4.0

    if initOnly is None:
        initOnly = False

    #get earth radius and altitude using master's orbit
    with open(inps.mframe, 'rb') as f:
        mframe = pickle.load(f)

    azti = 1.0 / mframe.PRF
    tmid = mframe.getSensingStart() + datetime.timedelta(
        seconds=azti * (mframe.getNumberOfLines() / 2.0))
    orbit = mframe.getOrbit()
    peg = orbit.interpolateOrbit(tmid, method='hermite')

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    hdg = orbit.getHeading(tmid)
    #change to the following after updated to the newest version of isce
    #hdg = orbit.getENUHeading(tmid)
    refElp.setSCH(llh[0], llh[1], hdg)
    earthRadius = refElp.pegRadCur
    altitude = llh[2]

    wrapName = inps.inf
    unwrapName = inps.unw
    corrfile = inps.cor

    width = getWidth(wrapName + '.xml')
    wavelength = mframe.getInstrument().getRadarWavelength()
    rangeLooks = inps.rlks
    azimuthLooks = inps.alks

    #calculate azimuth resolution and pixel size
    azres = mframe.platform.antennaLength / 2.0
    vel = np.sqrt(peg.velocity[0] * peg.velocity[0] +
                  peg.velocity[1] * peg.velocity[1] +
                  peg.velocity[2] * peg.velocity[2])
    hgt = np.sqrt(peg.position[0] * peg.position[0] +
                  peg.position[1] * peg.position[1] +
                  peg.position[2] * peg.position[2])
    azimuthPixelSpacing = earthRadius / hgt * vel * azti
    azfact = azres / azimuthPixelSpacing

    #calculate range resolution and pixel size
    rBW = mframe.instrument.pulseLength * mframe.instrument.chirpSlope
    rgres = abs(SPEED_OF_LIGHT / (2.0 * rBW))
    slantRangePixelSpacing = 0.5 * SPEED_OF_LIGHT / mframe.rangeSamplingRate
    rngfact = rgres / slantRangePixelSpacing

    print('azfact: {}, rngfact: {}'.format(azfact, rngfact))
    corrLooks = azimuthLooks * rangeLooks / (azfact * rngfact)

    maxComponents = 20

    snp = Snaphu()
    snp.setInitOnly(initOnly)  # follow
    snp.setInput(wrapName)
    snp.setOutput(unwrapName)
    snp.setWidth(width)
    snp.setCostMode(costMode)  # follow
    snp.setEarthRadius(earthRadius)
    snp.setWavelength(wavelength)
    snp.setAltitude(altitude)
    snp.setCorrfile(corrfile)
    snp.setInitMethod(initMethod)  # follow
    snp.setCorrLooks(corrLooks)
    snp.setMaxComponents(maxComponents)
    snp.setDefoMaxCycles(defomax)  # follow
    snp.setRangeLooks(rangeLooks)
    snp.setAzimuthLooks(azimuthLooks)
    #snp.setCorFileFormat('FLOAT_DATA')
    snp.prepare()
    snp.unwrap()

    ######Render XML
    outImage = isceobj.Image.createUnwImage()
    outImage.setFilename(unwrapName)
    outImage.setWidth(width)
    outImage.setAccessMode('read')
    outImage.renderVRT()
    outImage.createImage()
    outImage.finalizeImage()
    outImage.renderHdr()

    #####Check if connected components was created
    if snp.dumpConnectedComponents:
        connImage = isceobj.Image.createImage()
        connImage.setFilename(unwrapName + '.conncomp')
        #At least one can query for the name used
        #self._insar.connectedComponentsFilename = unwrapName+'.conncomp'
        connImage.setWidth(width)
        connImage.setAccessMode('read')
        connImage.setDataType('BYTE')
        connImage.renderVRT()
        connImage.createImage()
        connImage.finalizeImage()
        connImage.renderHdr()

    return
Ejemplo n.º 15
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')