コード例 #1
0
def main():
    #need actual or soft link to alos.int and dem.la
    referenceOrbit = sys.argv[1]  #look for reference_orbit.txt
    fin1 = open(referenceOrbit)
    allLines = fin1.readlines()
    s_mocomp = []
    for line in allLines:
        lineS = line.split()
        s_mocomp.append(float(lineS[2]))
    fin1.close()
    from isceobj import Image as IF

    demNameXml = 'la.dem.xml'
    from iscesys.Parsers.FileParserFactory import createFileParser
    parser = createFileParser('xml')
    #get the properties from the file init file
    prop = parser.parse(demNameXml)[0]
    objDem = IF.createDemImage()
    objDem.initProperties(prop)
    objDem.createImage()
    obj = Topo()
    obj.setReferenceOrbit(s_mocomp)
    intImage = IF.createIntImage()
    width = 1328
    filename = 'alos.int'
    intImage.initImage(filename, 'read', width)
    intImage.createImage()
    obj.wireInputPort(name='interferogram', object=intImage)
    obj.wireInputPort(name='dem', object=objDem)
    obj.pegLatitude = 0.58936848339144254
    obj.pegLongitude = -2.1172133973559606
    obj.pegHeading = -0.22703294510994310
    obj.planetLocalRadius = 6356638.1714100000
    # Frame information
    obj.slantRangePixelSpacing = 9.3685142500000005
    obj.prf = 1930.502000000000
    obj.radarWavelength = 0.23605699999999999
    obj.rangeFirstSample = 750933.00000000000
    # Doppler information
    # Make_raw information
    obj.spacecraftHeight = 698594.96239000000
    obj.bodyFixedVelocity = 7595.2060428100003
    obj.isMocomp = 3072
    obj.numberRangeLooks = 1
    obj.numberAzimuthLooks = 4
    obj.dopplerCentroidConstantTerm = .0690595
    obj.topo()
    minLat = obj.getMinimumLatitude()
    maxLat = obj.getMaximumLatitude()
    minLon = obj.getMinimumLongitude()
    maxLon = obj.getMaximumLongitude()
    azspace = obj.getAzimuthSpacing()
    s0 = obj.getSCoordinateFirstLine()
    print(minLat, maxLat, minLon, maxLon, azspace, s0)
    #squintShift = obj.getSquintShift()
    #for el in squintShift:
    #print(el)
    intImage.finalizeImage()
    objDem.finalizeImage()
コード例 #2
0
 def createImages(self):
     
     if self.heightSchImage is None and not self.heightSchFilename == '':
         self.heightSchImage = IF.createImage()
         accessMode = 'read'
         dataType = 'FLOAT'
         width = self.width
         self.heightSchImage.initImage(
             self.heightSchFilename, accessMode, width, dataType
         )
     elif self.heightSchImage is None:
         # this should never happen, atleast when using the  
         # correct method. same for other images
         self.logger.error(
         'Must either pass the heightSchImage in the call or set self.heightSchFilename.'
         )
         raise Exception
     
     if (
         self.topophaseFlatImage is None and
         not self.topophaseFlatFilename == ''
         ):
         self.topophaseFlatImage = IF.createIntImage()
         accessMode = 'write'
         width = self.width
         self.topophaseFlatImage.initImage(self.topophaseFlatFilename,
                                           accessMode,
                                           width)
     elif self.topophaseFlatImage is None:
         self.logger.error(
             'Must either pass the topophaseFlatImage in the call or set self.topophaseMphFilename.'
             )
     
     if (
         self.topophaseMphImage is None and
         not self.topophaseMphFilename == ''
         ):
         self.topophaseMphImage = IF.createIntImage()
         accessMode = 'write'
         width = self.width
         self.topophaseMphImage.initImage(self.topophaseMphFilename,
                                          accessMode,
                                          width)
     elif self.topophaseMphImage is None:
         self.logger.error(
             'Must either pass the topophaseMphImage in the call or set self.topophaseMphFilename.'
             )
         #one way or another when it gets here the images better be defined
     self.intImage.createImage()#this is passed but call createImage and finalizeImage from here
     self.heightSchImage.createImage()
     self.topophaseFlatImage.createImage()
     self.topophaseMphImage.createImage()
コード例 #3
0
ファイル: pyAPSCorrect.py プロジェクト: torresal/tropmap
    def correctUnw(self, prefix):
        '''
        Correct the unwrapped interferogram using the estimated delay map.
        '''
        try:
            Oamp = ts.load_mmap(self.unw, self.width, self.length, map='BIL', nchannels=2, channel=1,datatype=np.float32, quiet=True)
            Oifg = ts.load_mmap(self.unw, self.width, self.length, map='BIL', nchannels=2, channel=1,datatype=np.float32, quiet=True)
        except Exception as e:
            toContext(process,ErrorCodes['Memmap Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Memmap Error'])

        try:
            Aifg = ts.load_mmap(self.outfile+'.rdr', self.width, self.length, datatype=np.float32,quiet=True)
        except Exception as e:
            toContext(process,ErrorCodes['Memmap Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Memmap Error'])

        corrname = '{0}_{1}'.format(prefix, self.unw)

        try:
            fout = open(corrname, 'w')
            for kk in xrange(self.length):
                dat = Oifg[kk,:] * Aifg[kk,:]
                amp = Omap[kk,:]
                amp.tofile(fout)
                dat.tofile(fout)
        except Exception as e:
            toContext(process,ErrorCodes['Write Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Write Error'])

        fout.close()
        ifImage = IF.createImage()
        accessMode = 'read'
        dataType = 'CFLOAT'
        ifImage.initImage(corrname,accessMode,self.width,dataType)
        descr = 'Troposheric corrected unwrapped flattened interferogram'
        ifImage.setImageType('cpx')
        ifImage.addDescription(descr)
        ifImage.renderHdr()
        self.insar._insar.correctedTopophaseFilename = corrname
        fp = open(self.pickle,'w')
        cp.dump(self.insar,fp)
        fp.close()
        toContext(process,0,'pyAPSCorrections applied')
コード例 #4
0
    def createImages(self):
       
        #assume that even if an image is passed, the createImage and finalizeImage are called here
        if self.demImage is None and not self.demFilename == '':
            self.demImage = IF.createDemImage()
            demAccessMode = 'read'
            demWidth = self.demWidth
            self.demImage.initImage(self.demFilename,demAccessMode,demWidth)
        elif self.demImage is None:#this should never happen, atleast when using the  correct method. same for other images

            self.logger.error('Must either pass the demImage in the call or set self.demFilename.')
            raise Exception
        
        if(self.latImage == None and not self.latFilename == ''):
            self.latImage = IF.createImage()
            accessMode = 'write'
            dataType = 'DOUBLE'
            width = self.width
            self.latImage.initImage(self.latFilename,accessMode,width,dataType)
        elif(self.latImage == None):
            self.logger.error('Must either pass the latImage in the call or set self.latFilename.')
            raise Exception
        
        if(self.lonImage == None and not self.lonFilename == ''):
            self.lonImage = IF.createImage()
            accessMode = 'write'
            dataType = 'DOUBLE'
            width = self.width
            self.lonImage.initImage(self.lonFilename,accessMode,width,dataType)
        elif(self.lonImage == None):
            self.logger.error('Must either pass the lonImage in the call or set self.lonFilename.')
            raise Exception

        if(self.heightImage == None and not self.heightFilename == ''):
            self.heightImage = IF.createImage()
            accessMode = 'write'
            dataType = 'DOUBLE'
            width = self.width
            self.heightImage.initImage(self.heightFilename,accessMode,width,dataType)
        elif(self.heightImage == None):
            self.logger.error('Must either pass the heightImage in the call or set self.heightFilename.')
            raise Exception

        ####User provided an input file name for slant range to work with
        if(self.slantRangeImage == None and not self.slantRangeFilename == ''):

            if self.rangeFirstSample:
                raise Exception('Cannot provide both slant range image and range first sample as input')

            if self.slantRangePixelSpacing:
                raise Exception('Cannot provide both slant range image and slant range pixel spacing as input')

            self.slantRangeImage = IF.createImage()
            self.slantRangeImage.load(self.slantRangeFilename + '.xml')
            self.slantRangeImage.setAccessMode = 'READ'

            if self.slantRangeImage.width != self.width:
                raise Exception('Slant Range Image width {0} does not match input width {1}'.format(self.slantRangeImage.width, self.width))

            if self.slantRangeImage.length != self.length:
                raise Exception('Slant Range Image length {0} does not match input length {1}'.format(self.slantRangeImage.length, self.length))

            self.slantRangeImage.createImage()
            ###Set these to zero since not used but bindings need it - PSA
            self.rangeFirstSample = 0.0
            self.slantRangePixelSpacing = 0.0

        ####User provided an image like object (maybe polynomial)
        elif self.slantRangeImage is not None:
            if self.slantRangeImage.width != self.width:
                raise Exception('Slant Range Image width {0} does not match input width {1}'.format(self.slantRangeImage.width, self.width))

            if self.slantRangeImage.length != self.length:
                raise Exception('Slant Range Image length {0} does not match input length {1}'.format(self.slantRangeImage.length, self.length))

        #####Standard operation
        else:
            r0 = self.rangeFirstSample
            dr = self.slantRangePixelSpacing*self.numberRangeLooks
            self.slantRangeImage = Poly2D.Poly2D()
            self.slantRangeImage.setWidth(self.width)
            self.slantRangeImage.setLength(self.length)
            self.slantRangeImage.setNormRange(1.0)
            self.slantRangeImage.setNormAzimuth(1.0)
            self.slantRangeImage.setMeanRange(0.0)
            self.slantRangeImage.setMeanAzimuth(0.0)
            self.slantRangeImage.initPoly(rangeOrder=1, azimuthOrder=0, coeffs=[[r0,dr]])



        if(self.losImage == None and not self.losFilename == ''):
            self.losImage = IF.createImage()
            accessMode = 'write'
            dataType ='FLOAT'
            bands = 2
            scheme = 'BIL'
            width = self.width
            self.losImage.initImage(self.losFilename,accessMode,width,dataType,bands=bands,scheme=scheme)

        if (self.incImage == None and not self.incFilename == ''):
            self.incImage = IF.createImage()
            accessMode = 'write'
            dataType = 'FLOAT'
            bands = 2
            scheme = 'BIL'
            width = self.width
            self.incImage.initImage(self.incFilename, accessMode, width, dataType, bands=bands, scheme=scheme)

        if (self.maskImage == None and not self.maskFilename == ''):
            self.maskImage = IF.createImage()
            accessMode = 'write'
            dataType = 'BYTE'
            bands = 1
            scheme = 'BIL'
            width = self.width
            self.maskImage.initImage(self.maskFilename, accessMode, width, dataType, bands=bands, scheme=scheme)

        #the dem image could have different datatype so create a caster here
        #the short is the data type used in the fortran. 
        self.demImage.setCaster('read','FLOAT')
        self.demImage.createImage()
        self.latImage.createImage()
        self.lonImage.createImage()
        self.heightImage.createImage()
        self.losImage.createImage()

        if self.incImage:
            self.incImage.createImage()

        if self.maskImage:
            self.maskImage.createImage()

        return
コード例 #5
0
    def createImages(self):

        #assume that even if an image is passed, the createImage and finalizeImage are called here
        if self.demImage is None and not self.demFilename == '':
            self.demImage = IF.createDemImage()
            demAccessMode = 'read'
            demWidth = self.demWidth
            self.demImage.initImage(self.demFilename, demAccessMode, demWidth)
        elif self.demImage is None:  #this should never happen, atleast when using the  correct method. same for other images

            self.logger.error(
                'Must either pass the demImage in the call or set self.demFilename.'
            )
            raise Exception

        if (self.latImage == None and not self.latFilename == ''):
            self.latImage = IF.createImage()
            accessMode = 'write'
            dataType = 'DOUBLE'
            width = self.width
            self.latImage.initImage(self.latFilename, accessMode, width,
                                    dataType)
        elif (self.latImage == None):
            self.logger.error(
                'Must either pass the latImage in the call or set self.latFilename.'
            )
            raise Exception

        if (self.lonImage == None and not self.lonFilename == ''):
            self.lonImage = IF.createImage()
            accessMode = 'write'
            dataType = 'DOUBLE'
            width = self.width
            self.lonImage.initImage(self.lonFilename, accessMode, width,
                                    dataType)
        elif (self.lonImage == None):
            self.logger.error(
                'Must either pass the lonImage in the call or set self.lonFilename.'
            )
            raise Exception

        if (self.heightRImage == None and not self.heightRFilename == ''):
            self.heightRImage = IF.createImage()
            accessMode = 'write'
            dataType = 'FLOAT'
            width = self.width
            self.heightRImage.initImage(self.heightRFilename, accessMode,
                                        width, dataType)
        elif (self.heightRImage == None):
            self.logger.error(
                'Must either pass the heightRImage in the call or set self.heightRFilename.'
            )
            raise Exception

        if (self.heightSchImage == None and not self.heightSchFilename == ''):
            self.heightSchImage = IF.createImage()
            accessMode = 'write'
            dataType = 'FLOAT'
            width = self.width
            self.heightSchImage.initImage(self.heightSchFilename, accessMode,
                                          width, dataType)
        elif (self.heightSchImage == None):
            self.logger.error(
                'Must either pass the heightSchImage in the call or set self.heightSchFilename.'
            )
            raise Exception

        if (self.losImage == None and not self.losFilename == ''):
            self.losImage = IF.createImage()
            accessMode = 'write'
            dataType = 'FLOAT'
            bands = 2
            scheme = 'BIL'
            width = self.width
            self.losImage.initImage(self.losFilename,
                                    accessMode,
                                    width,
                                    dataType,
                                    bands=bands,
                                    scheme=scheme)

        if (self.incImage == None and not self.incFilename == ''):
            self.incImage = IF.createImage()
            accessMode = 'write'
            dataType = 'FLOAT'
            bands = 1
            scheme = 'BIL'
            width = self.width
            self.incImage.initImage(self.incFilename,
                                    accessMode,
                                    width,
                                    dataType,
                                    bands=bands,
                                    scheme=scheme)

        #self.intImage.createImage()
        #the dem image could have different datatype so create a caster here
        #the short is the data type used in the fortran.
        self.demImage.setCaster('read', 'FLOAT')
        self.demImage.createImage()
        self.latImage.createImage()
        self.lonImage.createImage()
        self.heightRImage.createImage()
        self.heightSchImage.createImage()
        self.losImage.createImage()

        if self.incImage:
            self.incImage.createImage()
コード例 #6
0
ファイル: testCorrect.py プロジェクト: HBaldwin3/isce_v2.0.0
def main():
    #need actual or soft link to alos.int and dem.la
    referenceOrbit = sys.argv[1] #look for reference_orbit.txt
    fin1 = open(referenceOrbit)
    allLines = fin1.readlines()
    s_mocomp = []
    for line in allLines:
        lineS = line.split()
        s_mocomp.append(float(lineS[2]))
    fin1.close()
    
  
    fp1 = open(sys.argv[3])#mocompbaseline.out
    fp2 = open(sys.argv[4])#mocomppositions.out
    all1 = fp1.readlines()
    all2 = fp2.readlines()
    fp1.close()
    fp2.close()
    mocbase = []
    midpoint = []
    for line in all1:
        ls = line.split()
        mocbase.append([float(ls[1]),float(ls[2]),float(ls[3])])
        midpoint.append([float(ls[5]),float(ls[6]),float(ls[7])])

    sch1 = []
    sch2 = []
    sc = []
    for line in all2:
        ls = line.split()
        sch1.append([float(ls[0]),float(ls[1]),float(ls[2])])
        sch2.append([float(ls[3]),float(ls[4]),float(ls[5])])
        sc.append([float(ls[6]),float(ls[7]),float(ls[8])])

    from  isceobj import Image as IF
    
    obj = Correct()
    obj.setReferenceOrbit(s_mocomp)
    obj.setMocompBaseline(mocbase)
    obj.setMidpoint(midpoint)
    obj.setSch1(sch1)
    obj.setSch2(sch2)
    obj.setSc(sc)
    intImage = IF.createIntImage()
    width = 1328
    filename = 'alos.int'
    intImage.initImage(filename,'read',width)
    intImage.createImage()       
    obj.wireInputPort(name='interferogram',object=intImage)    
    obj.pegLatitude = 0.58936848339144254
    obj.pegLongitude = -2.1172133973559606
    obj.pegHeading = -0.22703294510994310
    obj.planetLocalRadius = 6356638.1714100000
    # Frame information
    obj.slantRangePixelSpacing =  9.3685142500000005
    obj.prf = 1930.502000000000
    obj.radarWavelength =  0.23605699999999999 
    obj.rangeFirstSample =   750933.00000000000
    # Doppler information
    # Make_raw information
    obj.spacecraftHeight = 698594.96239000000
    obj.bodyFixedVelocity = 7595.2060428100003
    obj.isMocomp = 3072
    obj.numberRangeLooks = 1
    obj.numberAzimuthLooks = 4 
    obj.dopplerCentroidConstantTerm = .0690595
    obj.setHeightSchFilename('zsch')
    obj.setTopophaseFlatFilename('topophase.flat')
    obj.setTopophaseMphFilename('topophase.mph')
    obj.correct()
    #squintShift = obj.getSquintShift()
    #for el in squintShift:
        #print(el)
    intImage.finalizeImage()
コード例 #7
0
ファイル: pyAPSCorrect.py プロジェクト: torresal/tropmap
    def __init__(self, geoflag=False,pickleFile='insar.cpk'):
        '''Construct all the required geometry information from the pickled
        insarProc object.'''
        self.insar = load_pickle(pickleFile) 
        iobj = self.insar._insar
        self.pickle = pickleFile
        topo = iobj.getTopo()
        dem = iobj._demImage
        self.ifg = iobj.topophaseFlatFilename
        ifgImage = IF.createImage()
        ifgImage.load(self.ifg + '.xml')
        ####Processing in radar coordinates
        if not geoflag:
            print 'Processing in radar coordinates'
            self.lat = topo.latFilename
            self.lon = topo.lonFilename
            self.hgt = topo.heightRFilename
            self.width  = ifgImage.width
            self.length = ifgImage.length
            self.minlat = topo.minimumLatitude
            self.maxlat = topo.maximumLatitude
            self.minlon = topo.minimumLongitude
            self.maxlon = topo.maximumLongitude
            self.daz = topo.azimuthSpacing
            self.drg = topo.slantRangePixelSpacing
            self.geo = geoflag
        else:
        #### Processing in geo coordinates
            print 'Processing geo coordinates'
            self.lat = None
            self.lon = None
            self.hgt = dem.filename
            self.width = dem.width
            self.length = dem.length
            self.maxlat = dem.firstLatitude
            self.minlon = dem.firstLongitude
            self.minlat = self.maxlat + dem.deltaLatitude*self.length
            self.maxlon = self.minlon + dem.deltaLongitude*self.width
            self.daz = 30.0
            self.drg = 30.0
            self.geo = geoflag

        rad = topo.planetLocalRadius
        hgt = topo.spacecraftHeight
        rng = topo.rangeFirstSample + 0.5*self.width*self.drg
        theta = np.pi - np.arccos(((rng*rng) + (rad*rad) - ((rad+hgt)*(rad+hgt))) / (2.*rng*rad))

        #####Change this to pixel-by-pixel LOS in future 
        #####If really needed
        self.inc = 180.0*theta/np.pi
        print 'Incidence angle in degrees: ', self.inc 
        self.wvl = iobj.radarWavelength
        #self.ifg = iobj._insar.getTopophaseFlatFilename()

        self.unw = iobj.getUnwrappedIntFilename()

        self.masterdate= iobj.getMasterFrame().sensingMid
        self.slavedate = iobj.getSlaveFrame().sensingMid

        self.flist = []
        self.model = None
        self.outfile = None
コード例 #8
0
ファイル: pyAPSCorrect.py プロジェクト: torresal/tropmap
    def estimateDelay(self):
        '''Estimate the delay using PyAPS.'''

        self.outfile = 'corrections_pyAPS_%s'%(self.model)
        print('Processing master delay')
        delay = np.zeros((self.length, self.width), dtype=np.float32)

        ######Processing in radar coordinates
        if not self.geo:
            try:
                atmobj = pyaps.PyAPS_rdr(self.flist[0],self.hgt,grib=self.model,demfmt='HGT')
                atmobj.getgeodelay(delay, lat=self.lat, lon=self.lon, inc=self.inc,wvl=self.wvl) 
            except Exception as e:
                toContext(process,ErrorCodes['Master Delay Estimation Failed'],str(e))
                print(e)
                sys.exit(ErrorCodes['Master Delay Estimation Failed'])
        else:
        #######Processing in geo coordinates
            try:
                atmobj = pyaps.PyAPS_geo(self.flist[0], self.hgt, grib=self.model,demfmt='HGT')
                atmobj.getdelay(delay, inc=self.inc,wvl=sel.wvl)
            except Exception as e:
                toContext(process,ErrorCodes['Master Delay Estimation Failed'],str(e))
                print(e)
                sys.exit(ErrorCodes['Master Delay Estimation Failed'])

        del atmobj
        
        if(np.isnan(np.sum(delay))):
            print("pyAPSCorrect.py estimateDelay: found NaN. Aborting") 
            toContext(process,ErrorCodes['NaN Present'],"pyAPSCorrect.py estimateDelay: found NaN. Aborting")
            sys.exit(ErrorCodes['NaN Present'])

        
        print('Processing slave delay')
        delay_slav = np.zeros((self.length, self.width), dtype=np.float32)
        if not self.geo:
            try:
                atmobj = pyaps.PyAPS_rdr(self.flist[1],self.hgt,grib=self.model,demfmt='HGT')
                atmobj.getgeodelay(delay_slav, lat=self.lat, lon=self.lon, inc=self.inc,wvl=self.wvl)
            except Exception as e:
                print(e)
                toContext(process,ErrorCodes['Slave Delay Estimation Failed'],str(e))
                sys.exit(ErrorCodes['Slave Delay Estimation Failed'])
        else:
            try:
                atmobj = pyaps.PyAPS_geo(self.flist[1], self.hgt,grib=self.model,demfmt='HGT')
                atmobj.getdelay(delay_slav, inc=self.inc,wvl=self.wvl)
            except Exception as e:
                toContext(process,ErrorCodes['Slave Delay Estimation Failed'],str(e))
                print(e)
                sys.exit(ErrorCodes['Slave Delay Estimation Failed'])

        del atmobj

        if(np.isnan(np.sum(delay_slav))):
            print("pyAPSCorrect.py estimateDelay: found NaN. Aborting") 
            toContext(process,ErrorCodes['NaN Present'],"pyAPSCorrect.py estimateDelay: found NaN. Aborting")
            sys.exit(ErrorCodes['NaN'])
        delay -= delay_slav
        del delay_slav

        try:
            #import pdb
            #pdb.set_trace()
            self.insar._insar.correctionsFilename = self.outfile+'.rdr'
            delay.astype(np.float32).tofile(self.insar._insar.correctionsFilename)
            ifImage = IF.createImage()
            accessMode = 'read'
            dataType = 'FLOAT'
            ifImage.initImage(self.insar._insar.correctionsFilename,accessMode,self.width,dataType)
            descr = 'Troposheric corrections'
            ifImage.setImageType('sbi')
            ifImage.addDescription(descr)
            ifImage.renderHdr()
        except Exception as e:
            toContext(process,ErrorCodes['Write Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Write Error'])
        
        cJ = np.complex64(1.0j)
        delay = np.exp(cJ*(delay))
        try:
            delay.tofile(self.outfile+'.mph')
        except Exception as e:
            toContext(process,ErrorCodes['Write Error'],str(e))
            print(e)
            sys.exit(ErrorCodes['Write Error'])
        #since some time this is the only stage executed dump the pickle
        #if there are other stages they'll be overwritten
        fp = open(self.pickle,'w')
        cp.dump(self.insar,fp)
        fp.close()
        toContext(process,0,'pyAPSCorrections delay created')
コード例 #9
0
def runGPUTopo(info,
               demImage,
               dop=None,
               nativedop=False,
               legendre=False,
               full=False):
    from zerodop.topozero import createTopozero
    from isceobj.Planet.Planet import Planet
    from gpu_topozero import PyTopozero
    from isceobj import Constants as CN

    if not os.path.isdir(info.outdir):
        os.mkdir(info.outdir)

    # Random vars
    r0 = info.rangeFirstSample + (
        (info.numberRangeLooks - 1) / 2) * info.slantRangePixelSpacing
    tbef = info.sensingStart + datetime.timedelta(seconds=(
        (info.numberAzimuthLooks - 1) / 2) / info.prf)
    pegHdg = np.radians(info.orbit.getENUHeading(tbef))
    width = info.width // info.numberRangeLooks
    length = info.length // info.numberAzimuthLooks
    dr = info.slantRangePixelSpacing * info.numberRangeLooks
    if legendre:
        omethod = 2  # LEGENDRE INTERPOLATION
    else:
        omethod = 0  # HERMITE INTERPOLATION
    # Images
    demImage.setCaster('read', 'FLOAT')
    demImage.createImage()

    if nativedop and (dop is not None):
        try:
            coeffs = dop._coeffs
        except:
            coeffs = dop
        polyDoppler = Poly2D()
        polyDoppler.setWidth(width)
        polyDoppler.setLength(length)
        polyDoppler.initPoly(rangeOrder=len(coeffs) - 1,
                             azimuthOrder=0,
                             coeffs=[coeffs])
    else:
        print('Zero doppler')
        #doppler = None
        polyDoppler = Poly2D(name=frame.name + '_dopplerPoly')
        polyDoppler.setWidth(width)
        polyDoppler.setLength(length)
        polyDoppler.setNormRange(1.0)
        polyDoppler.setNormAzimuth(1.0)
        polyDoppler.setMeanRange(0.0)
        polyDoppler.setMeanAzimuth(0.0)
        polyDoppler.initPoly(rangeOrder=0, azimuthOrder=0, coeffs=[[0.0]])
    polyDoppler.createPoly2D()

    slantRangeImage = Poly2D()
    slantRangeImage.setWidth(width)
    slantRangeImage.setLength(length)
    slantRangeImage.setNormRange(1.0)
    slantRangeImage.setNormAzimuth(1.0)
    slantRangeImage.setMeanRange(0.0)
    slantRangeImage.setMeanAzimuth(0.0)
    slantRangeImage.initPoly(rangeOrder=1, azimuthOrder=0, coeffs=[[r0, dr]])
    slantRangeImage.createPoly2D()

    latImage = IF.createImage()
    accessMode = 'write'
    dataType = 'DOUBLE'
    latImage.initImage(os.path.join(info.outdir, 'lat.rdr'), accessMode, width,
                       dataType)
    latImage.createImage()

    lonImage = IF.createImage()
    lonImage.initImage(os.path.join(info.outdir, 'lon.rdr'), accessMode, width,
                       dataType)
    lonImage.createImage()

    losImage = IF.createImage()
    dataType = 'FLOAT'
    bands = 2
    scheme = 'BIL'
    losImage.initImage(os.path.join(info.outdir, 'los.rdr'),
                       accessMode,
                       width,
                       dataType,
                       bands=bands,
                       scheme=scheme)
    losImage.setCaster('write', 'DOUBLE')
    losImage.createImage()

    heightImage = IF.createImage()
    dataType = 'DOUBLE'
    heightImage.initImage(os.path.join(info.outdir, 'z.rdr'), accessMode,
                          width, dataType)
    heightImage.createImage()

    if full:
        incImage = IF.createImage()
        dataType = 'FLOAT'
        incImage.initImage(os.path.join(info.outdir, 'inc.rdr'),
                           accessMode,
                           width,
                           dataType,
                           bands=bands,
                           scheme=scheme)
        incImage.createImage()
        incImagePtr = incImage.getImagePointer()

        maskImage = IF.createImage()
        dataType = 'BYTE'
        bands = 1
        maskImage.initImage(os.path.join(info.outdir, 'mask.rdr'),
                            accessMode,
                            width,
                            dataType,
                            bands=bands,
                            scheme=scheme)
        maskImage.createImage()
        maskImagePtr = maskImage.getImagePointer()
    else:
        incImagePtr = 0
        maskImagePtr = 0

    elp = Planet(pname='Earth').ellipsoid

    topo = PyTopozero()
    topo.set_firstlat(demImage.getFirstLatitude())
    topo.set_firstlon(demImage.getFirstLongitude())
    topo.set_deltalat(demImage.getDeltaLatitude())
    topo.set_deltalon(demImage.getDeltaLongitude())
    topo.set_major(elp.a)
    topo.set_eccentricitySquared(elp.e2)
    topo.set_rSpace(info.slantRangePixelSpacing)
    topo.set_r0(r0)
    topo.set_pegHdg(pegHdg)
    topo.set_prf(info.prf)
    topo.set_t0(DTU.seconds_since_midnight(tbef))
    topo.set_wvl(info.radarWavelength)
    topo.set_thresh(.05)
    topo.set_demAccessor(demImage.getImagePointer())
    topo.set_dopAccessor(polyDoppler.getPointer())
    topo.set_slrngAccessor(slantRangeImage.getPointer())
    topo.set_latAccessor(latImage.getImagePointer())
    topo.set_lonAccessor(lonImage.getImagePointer())
    topo.set_losAccessor(losImage.getImagePointer())
    topo.set_heightAccessor(heightImage.getImagePointer())
    topo.set_incAccessor(incImagePtr)
    topo.set_maskAccessor(maskImagePtr)
    topo.set_numIter(25)
    topo.set_idemWidth(demImage.getWidth())
    topo.set_idemLength(demImage.getLength())
    topo.set_ilrl(info.lookSide)
    topo.set_extraIter(10)
    topo.set_length(length)
    topo.set_width(width)
    topo.set_nRngLooks(info.numberRangeLooks)
    topo.set_nAzLooks(info.numberAzimuthLooks)
    topo.set_demMethod(5)  # BIQUINTIC METHOD
    topo.set_orbitMethod(omethod)
    # Need to simplify orbit stuff later
    nvecs = len(info.orbit.stateVectors.list)
    topo.set_orbitNvecs(nvecs)
    topo.set_orbitBasis(1)  # Is this ever different?
    topo.createOrbit(
    )  # Initializes the empty orbit to the right allocated size
    count = 0
    for sv in info.orbit.stateVectors.list:
        td = DTU.seconds_since_midnight(sv.getTime())
        pos = sv.getPosition()
        vel = sv.getVelocity()
        topo.set_orbitVector(count, td, pos[0], pos[1], pos[2], vel[0], vel[1],
                             vel[2])
        count += 1

    topo.runTopo()

    latImage.addDescription('Pixel-by-pixel latitude in degrees.')
    latImage.finalizeImage()
    latImage.renderHdr()

    lonImage.addDescription('Pixel-by-pixel longitude in degrees.')
    lonImage.finalizeImage()
    lonImage.renderHdr()

    heightImage.addDescription('Pixel-by-pixel height in meters.')
    heightImage.finalizeImage()
    heightImage.renderHdr()

    descr = '''Two channel Line-Of-Sight geometry image (all angles in degrees). Represents vector drawn from target to platform.
            Channel 1: Incidence angle measured from vertical at target (always +ve).
            Channel 2: Azimuth angle measured from North in Anti-clockwise direction.'''
    losImage.setImageType('bil')
    losImage.addDescription(descr)
    losImage.finalizeImage()
    losImage.renderHdr()

    demImage.finalizeImage()

    if full:
        descr = '''Two channel angle file.
                Channel 1: Angle between ray to target and the vertical at the sensor
                Channel 2: Local incidence angle accounting for DEM slope at target'''
        incImage.addDescription(descr)
        incImage.finalizeImage()
        incImage.renderHdr()

        descr = 'Radar shadow-layover mask. 1 - Radar Shadow. 2 - Radar Layover. 3 - Both.'
        maskImage.addDescription(descr)
        maskImage.finalizeImage()
        maskImage.renderHdr()
    if slantRangeImage:
        try:
            slantRangeImage.finalizeImage()
        except:
            pass
コード例 #10
0
ファイル: Correct.py プロジェクト: zybbbbbox/isce2
    def createImages(self):

        if self.heightSchImage is None and not self.heightSchFilename == '':
            self.heightSchImage = IF.createImage()
            accessMode = 'read'
            dataType = 'FLOAT'
            width = self.width
            self.heightSchImage.initImage(self.heightSchFilename, accessMode,
                                          width, dataType)
        elif self.heightSchImage is None:
            # this should never happen, atleast when using the
            # correct method. same for other images
            self.logger.error(
                'Must either pass the heightSchImage in the call or set self.heightSchFilename.'
            )
            raise Exception

        if self.intImage is not None:
            if (self.topophaseFlatImage is None
                    and not self.topophaseFlatFilename == ''):
                self.topophaseFlatImage = IF.createIntImage()
                accessMode = 'write'
                width = self.width
                self.topophaseFlatImage.initImage(self.topophaseFlatFilename,
                                                  accessMode, width)
            elif self.topophaseFlatImage is None:
                self.logger.error(
                    'Must either pass the topophaseFlatImage in the call or set self.topophaseMphFilename.'
                )

        if (self.topophaseMphImage is None
                and not self.topophaseMphFilename == ''):
            self.topophaseMphImage = IF.createIntImage()
            accessMode = 'write'
            width = self.width
            self.topophaseMphImage.initImage(self.topophaseMphFilename,
                                             accessMode, width)
        elif self.topophaseMphImage is None:
            self.logger.error(
                'Must either pass the topophaseMphImage in the call or set self.topophaseMphFilename.'
            )

        if self.dumpRangeFiles:
            if (self.slaveRangeImage is None
                    and not self.slaveRangeFilename == ''):
                self.slaveRangeImage = IF.createImage()
                self.slaveRangeImage.setFilename(self.slaveRangeFilename)
                self.slaveRangeImage.setAccessMode('write')
                self.slaveRangeImage.dataType = 'FLOAT'
                self.slaveRangeImage.setWidth(self.width)
                self.slaveRangeImage.bands = 1
                self.slaveRangeImage.scheme = 'BIL'

            if (self.masterRangeImage is None
                    and not self.masterRangeFilename == ''):
                self.masterRangeImage = IF.createImage()
                self.masterRangeImage.setFilename(self.masterRangeFilename)
                self.masterRangeImage.setAccessMode('write')
                self.masterRangeImage.dataType = 'FLOAT'
                self.masterRangeImage.setWidth(self.width)
                self.masterRangeImage.bands = 1
                self.masterRangeImage.scheme = 'BIL'

        if self.polyDoppler is None:
            self.logger.error(
                'Must pass doppler polynomial in the call to correct')

            #one way or another when it gets here the images better be defined
        if self.intImage is not None:
            self.intImage.createImage(
            )  #this is passed but call createImage and finalizeImage from here
            self.topophaseFlatImage.createImage()

        self.heightSchImage.createImage()
        self.topophaseMphImage.createImage()

        if self.dumpRangeFiles:
            self.masterRangeImage.createImage()
            self.slaveRangeImage.createImage()

        self.polyDoppler.createPoly2D()