def estCpxCoherence(slc1_file, slc2_file, cpx_coh_file, alks=3, rlks=9): from isceobj.TopsProc.runBurstIfg import computeCoherence from mroipac.looks.Looks import Looks # get the full resolution file name if alks * rlks == 1: cpx_coh_file_full = cpx_coh_file else: cpx_coh_file_full = cpx_coh_file + '.full' # calculate complex coherence in full resolution computeCoherence(slc1_file, slc2_file, cpx_coh_file_full) # multilook if alks * rlks > 1: print('Multilooking {0} ...'.format(cpx_coh_file_full)) inimg = isceobj.createImage() inimg.load(cpx_coh_file_full + '.xml') lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(cpx_coh_file) lkObj.looks() # remove full resolution coherence file os.remove(cpx_coh_file_full) return
def multilook(infile, outname=None, alks=5, rlks=15): ''' Take looks. ''' from mroipac.looks.Looks import Looks print('Multilooking {0} ...'.format(infile)) inimg = isceobj.createImage() inimg.load(infile + '.xml') if outname is None: spl = os.path.splitext(inimg.filename) ext = '.{0}alks_{1}rlks'.format(alks, rlks) outname = spl[0] + ext + spl[1] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outname) lkObj.looks() return outname
def main(iargs=None): inps = cmdLineParse(iargs) if inps.filtfile is None: inps.filtfile = 'filt_' + inps.infile runFilter(inps.infile, inps.filtfile, inps.filterstrength) estCoherence(inps.filtfile, inps.cohfile) if inps.slc1 and inps.slc2: computeCoherence(inps.slc1,inps.slc2,inps.cpx_cohfile) from mroipac.looks.Looks import Looks print('Multilooking {0} ...'.format(inps.cpx_cohfile)) infile=inps.cpx_cohfile inimg = isceobj.createImage() inimg.load(infile + '.xml') alks=inps.numberAzlooks rlks=inps.numberRangelooks spl = os.path.splitext(inimg.filename) #ext = '.{0}alks_{1}rlks'.format(alks, rlks) #outname = spl[0] + ext + spl[1] outname=spl[0] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outname) lkObj.looks() fullfilename=inps.cpx_cohfile ret=os.system('rm '+fullfilename)
def multilook(infile, outname=None, alks=5, rlks=15, multilook_tool="isce", no_data=None): ''' Take looks. ''' if multilook_tool=="gdal": from osgeo import gdal print("multi looking using gdal ...") if outname is None: spl = os.path.splitext(infile) ext = '.{0}alks_{1}rlks'.format(alks, rlks) outname = spl[0] + ext + spl[1] print(infile) ds = gdal.Open(infile + ".vrt", gdal.GA_ReadOnly) xSize = ds.RasterXSize ySize = ds.RasterYSize outXSize = xSize/int(rlks) outYSize = ySize/int(alks) if no_data: gdalTranslateOpts = gdal.TranslateOptions(format="ENVI", width=outXSize, height=outYSize, noData=no_data) else: gdalTranslateOpts = gdal.TranslateOptions(format="ENVI", width=outXSize, height=outYSize) gdal.Translate(outname, ds, options=gdalTranslateOpts) ds = None ds = gdal.Open(outname, gdal.GA_ReadOnly) gdal.Translate(outname+".vrt", ds, options=gdal.TranslateOptions(format="VRT")) ds = None else: from mroipac.looks.Looks import Looks print('Multilooking {0} ...'.format(infile)) inimg = isceobj.createImage() inimg.load(infile + '.xml') if outname is None: spl = os.path.splitext(inimg.filename) ext = '.{0}alks_{1}rlks'.format(alks, rlks) outname = spl[0] + ext + spl[1] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outname) lkObj.looks() return outname
def multilook(infile, outname=None, alks=5, rlks=15, multilook_tool="isce", no_data=None): ''' Take looks. ''' # default output filename if outname is None: spl = os.path.splitext(infile) ext = '.{0}alks_{1}rlks'.format(alks, rlks) outname = spl[0] + ext + spl[1] if multilook_tool == "gdal": # remove existing *.hdr files, to avoid the following gdal error: # ERROR 1: Input and output dataset sizes or band counts do not match in GDALDatasetCopyWholeRaster() fbase = os.path.splitext(outname)[0] print(f'remove {fbase}*.hdr') for fname in glob.glob(f'{fbase}*.hdr'): os.remove(fname) print(f"multilooking {rlks} x {alks} using gdal for {infile} ...") ds = gdal.Open(infile + '.vrt', gdal.GA_ReadOnly) xSize = ds.RasterXSize ySize = ds.RasterYSize outXSize = int(xSize / int(rlks)) outYSize = int(ySize / int(alks)) srcXSize = outXSize * int(rlks) srcYSize = outYSize * int(alks) options_str = f'-of ENVI -outsize {outXSize} {outYSize} -srcwin 0 0 {srcXSize} {srcYSize} ' options_str += f'-a_nodata {no_data}' if no_data else '' gdal.Translate(outname, ds, options=options_str) # generate VRT file gdal.Translate(outname + ".vrt", outname, options='-of VRT') else: from mroipac.looks.Looks import Looks print(f'multilooking {rlks} x {alks} using isce2 for {infile} ...') inimg = isceobj.createImage() inimg.load(infile + '.xml') lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outname) lkObj.looks() return outname
def downLook(infile, outfile, alks, rlks): inImage = isceobj.createImage() inImage.load(infile + '.xml') inImage.filename = infile lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inImage) lkObj.setOutputFilename(outfile) lkObj.looks()
def main(inps): ''' The main driver. ''' if inps.infile.endswith('.xml'): inFileXml = inps.infile inFile = os.path.splitext(inps.infile)[0] else: inFile = inps.infile inFileXml = inps.infile + '.xml' if inps.outfile is None: spl = os.path.splitext(inFile) ext = '.{0}alks_{1}rlks'.format(inps.azlooks, inps.rglooks) outFile = spl[0] + ext + spl[1] elif inps.outfile.endswith('.xml'): outFile = os.path.splitext(inps.outfile)[0] else: outFile = inps.outfile print('Output filename : {0}'.format(outFile)) #hackish, just to know the image type to instantiate the correct type #until we put the info about how to generate the instance in the xml from iscesys.Parsers.FileParserFactory import createFileParser FP = createFileParser('xml') tmpProp, tmpFact, tmpMisc = FP.parse(inFileXml) if ('image_type' in tmpProp and tmpProp['image_type'] == 'dem'): inImage = createDemImage() else: inImage = createImage() inImage.load(inFileXml) inImage.filename = inFile lkObj = Looks() lkObj.setDownLooks(inps.azlooks) lkObj.setAcrossLooks(inps.rglooks) lkObj.setInputImage(inImage) lkObj.setOutputFilename(outFile) lkObj.looks() return outFile
def takeLooks(inimg, alks, rlks): ''' Take looks. ''' from mroipac.looks.Looks import Looks spl = os.path.splitext(inimg.filename) ext = '.{0}alks_{1}rlks'.format(alks, rlks) outfile = spl[0] + ext + spl[1] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outfile) lkObj.looks() return outfile
def runMultilook(in_dir, out_dir, alks, rlks): print( 'generate multilooked geometry files with alks={} and rlks={}'.format( alks, rlks)) from iscesys.Parsers.FileParserFactory import createFileParser FP = createFileParser('xml') if not os.path.isdir(out_dir): os.makedirs(out_dir) print('create directory: {}'.format(out_dir)) for fbase in [ 'hgt', 'incLocal', 'lat', 'lon', 'los', 'shadowMask', 'waterMask' ]: fname = '{}.rdr'.format(fbase) in_file = os.path.join(in_dir, fname) out_file = os.path.join(out_dir, fname) if os.path.isfile(in_file): xmlProp = FP.parse(in_file + '.xml')[0] if ('image_type' in xmlProp and xmlProp['image_type'] == 'dem'): inImage = isceobj.createDemImage() else: inImage = isceobj.createImage() inImage.load(in_file + '.xml') inImage.filename = in_file lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inImage) lkObj.setOutputFilename(out_file) lkObj.looks() # copy the full resolution xml/vrt file from ./merged/geom_master to ./geom_master # to facilitate the number of looks extraction # the file path inside .xml file is not, but should, updated shutil.copy(in_file + '.xml', out_file + '.full.xml') shutil.copy(in_file + '.vrt', out_file + '.full.vrt') return out_dir
def multilook(infile, outname=None, alks=5, rlks=15): """ Take looks. """ logger.info("Multilooking {} ...".format(infile)) inimg = isceobj.createImage() inimg.load(infile + ".xml") if outname is None: spl = os.path.splitext(inimg.filename) ext = ".{0}alks_{1}rlks".format(alks, rlks) outname = spl[0] + ext + spl[1] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outname) lkObj.looks() return outname
def takeLooks(inimg, alks, rlks): ''' Take looks. ''' from mroipac.looks.Looks import Looks img = isceobj.createImage() img.load(inimg + '.xml') img.setAccessMode('READ') spl = os.path.splitext(inimg) ext = '.{0}alks_{1}rlks'.format(alks, rlks) outfile = spl[0] + ext + spl[1] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(img) lkObj.setOutputFilename(outfile) lkObj.looks() return outfile
def estCpxCoherence(slc1_file, slc2_file, cpx_coh_file, alks=3, rlks=9): from isceobj.TopsProc.runBurstIfg import computeCoherence from mroipac.looks.Looks import Looks # calculate complex coherence in full resolution computeCoherence(slc1_file, slc2_file, cpx_coh_file) # multilook print('Multilooking {0} ...'.format(cpx_coh_file)) inimg = isceobj.createImage() inimg.load(cpx_coh_file + '.xml') outname = os.path.splitext(inimg.filename)[0] lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inimg) lkObj.setOutputFilename(outname) lkObj.looks() # remove full resolution coherence file ret = os.system('rm ' + cpx_coh_file) return
numberAzimuthLooks2, 3, 0, 1) #creat xml create_xml(multilookLatitude, width2, length2, 'double') create_xml(multilookLongitude, width2, length2, 'double') create_xml(multilookHeight, width2, length2, 'double') #los has two bands, use look program in isce instead #cmd = "looks.py -i {} -o {} -r {} -a {}".format(self._insar.los, self._insar.multilookLos, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2) #runCmd(cmd) #replace the above system call with function call from mroipac.looks.Looks import Looks from isceobj.Image import createImage inImage = createImage() inImage.load(los + '.xml') lkObj = Looks() lkObj.setDownLooks(numberAzimuthLooks2) lkObj.setAcrossLooks(numberRangeLooks2) lkObj.setInputImage(inImage) lkObj.setOutputFilename(multilookLos) lkObj.looks() #water body #this looking operation has no problems where there is only water and land, but there is also possible no-data area #look(self._insar.wbdOut, self._insar.multilookWbdOut, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 0, 0, 1) #create_xml(self._insar.multilookWbdOut, width2, length2, 'byte') #use waterBodyRadar instead to avoid the problems of no-data pixels in water body waterBodyRadar(multilookLatitude, multilookLongitude, wbdFile, multilookWbdOut) os.chdir('../')
def runMultilook(in_dir, out_dir, alks, rlks, in_ext='.rdr', out_ext='.rdr', method='gdal', fbase_list=[ 'hgt', 'incLocal', 'lat', 'lon', 'los', 'shadowMask', 'waterMask' ]): """ Multilook geometry files. """ from iscesys.Parsers.FileParserFactory import createFileParser from mroipac.looks.Looks import Looks msg = 'generate multilooked geometry files with alks={} and rlks={}'.format( alks, rlks) if method == 'isce': msg += ' using mroipac.looks.Looks() ...' else: msg += ' using gdal.Translate() ...' print('-' * 50 + '\n' + msg) # create 'geom_reference' directory os.makedirs(out_dir, exist_ok=True) # multilook files one by one for fbase in fbase_list: in_file = os.path.join(in_dir, '{}{}'.format(fbase, in_ext)) out_file = os.path.join(out_dir, '{}{}'.format(fbase, out_ext)) if all(os.path.isfile(in_file + ext) for ext in ['', '.vrt', '.xml']): print('multilook {}'.format(in_file)) # option 1 - Looks module (isce) if method == 'isce': xmlProp = createFileParser('xml').parse(in_file + '.xml')[0] if ('image_type' in xmlProp and xmlProp['image_type'] == 'dem'): inImage = isceobj.createDemImage() else: inImage = isceobj.createImage() inImage.load(in_file + '.xml') inImage.filename = in_file lkObj = Looks() lkObj.setDownLooks(alks) lkObj.setAcrossLooks(rlks) lkObj.setInputImage(inImage) lkObj.setOutputFilename(out_file) lkObj.looks() # option 2 - gdal_translate (gdal) elif method == 'gdal': ds = gdal.Open(in_file, gdal.GA_ReadOnly) in_wid = ds.RasterXSize in_len = ds.RasterYSize out_wid = int(in_wid / rlks) out_len = int(in_len / alks) src_wid = out_wid * rlks src_len = out_len * alks options_str = '-of ENVI -a_nodata 0 -outsize {ox} {oy} -srcwin 0 0 {sx} {sy} '.format( ox=out_wid, oy=out_len, sx=src_wid, sy=src_len) gdal.Translate(out_file, ds, options=options_str) # generate ISCE .xml file if not os.path.isfile(out_file + '.xml'): cmd = 'gdal2isce_xml.py -i {}.vrt'.format(out_file) print(cmd) os.system(cmd) else: raise ValueError( 'un-supported multilook method: {}'.format(method)) # copy the full resolution xml/vrt file from ./merged/geom_reference to ./geom_reference # to facilitate the number of looks extraction # the file path inside .xml file is not, but should, updated if in_file != out_file + '.full': shutil.copy(in_file + '.xml', out_file + '.full.xml') shutil.copy(in_file + '.vrt', out_file + '.full.vrt') return out_dir
def runLook(self): '''take looks ''' catalog = isceobj.Catalog.createCatalog(self._insar.procDoc.name) self.updateParamemetersFromUser() #referenceTrack = self._insar.loadTrack(reference=True) #secondaryTrack = self._insar.loadTrack(reference=False) wbdFile = os.path.abspath(self._insar.wbd) insarDir = 'insar' os.makedirs(insarDir, exist_ok=True) os.chdir(insarDir) amp = isceobj.createImage() amp.load(self._insar.amplitude + '.xml') width = amp.width length = amp.length width2 = int(width / self._insar.numberRangeLooks2) length2 = int(length / self._insar.numberAzimuthLooks2) if not ((self._insar.numberRangeLooks2 == 1) and (self._insar.numberAzimuthLooks2 == 1)): #take looks look(self._insar.differentialInterferogram, self._insar.multilookDifferentialInterferogram, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 4, 0, 1) look(self._insar.amplitude, self._insar.multilookAmplitude, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 4, 1, 1) look(self._insar.latitude, self._insar.multilookLatitude, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 3, 0, 1) look(self._insar.longitude, self._insar.multilookLongitude, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 3, 0, 1) look(self._insar.height, self._insar.multilookHeight, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 3, 0, 1) #creat xml create_xml(self._insar.multilookDifferentialInterferogram, width2, length2, 'int') create_xml(self._insar.multilookAmplitude, width2, length2, 'amp') create_xml(self._insar.multilookLatitude, width2, length2, 'double') create_xml(self._insar.multilookLongitude, width2, length2, 'double') create_xml(self._insar.multilookHeight, width2, length2, 'double') #los has two bands, use look program in isce instead #cmd = "looks.py -i {} -o {} -r {} -a {}".format(self._insar.los, self._insar.multilookLos, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2) #runCmd(cmd) #replace the above system call with function call from mroipac.looks.Looks import Looks from isceobj.Image import createImage inImage = createImage() inImage.load(self._insar.los + '.xml') lkObj = Looks() lkObj.setDownLooks(self._insar.numberAzimuthLooks2) lkObj.setAcrossLooks(self._insar.numberRangeLooks2) lkObj.setInputImage(inImage) lkObj.setOutputFilename(self._insar.multilookLos) lkObj.looks() #water body #this looking operation has no problems where there is only water and land, but there is also possible no-data area #look(self._insar.wbdOut, self._insar.multilookWbdOut, width, self._insar.numberRangeLooks2, self._insar.numberAzimuthLooks2, 0, 0, 1) #create_xml(self._insar.multilookWbdOut, width2, length2, 'byte') #use waterBodyRadar instead to avoid the problems of no-data pixels in water body waterBodyRadar(self._insar.multilookLatitude, self._insar.multilookLongitude, wbdFile, self._insar.multilookWbdOut) os.chdir('../') catalog.printToLog(logger, "runLook") self._insar.procDoc.addAllFromCatalog(catalog)