def createImages(self): #the fortran code used to read in short, convert to float and convert back to short. #let's use the image api and the casters to do that. The image in input can be of any # comptible type inImage = self._dem.clone() #reads short and convert to float inImage.initImage(self.inputFilename,'read',self.width,self.dataType) #create a suitable caster from self.dataType to self._dataTypeBindings inImage.setCaster('read',self._dataTypeBindings) inImage.createImage() self._numberLines = inImage.getLength() outImage = Image() #if name not provided assume overwrite of input import random if(not self.outputFilename): self.outputFilename = os.path.basename(self.inputFilename) + str(int(random.random()*100000)) #add 6 digit random number to input filename self.overwriteInputFileFlag = True #manages float and writes out short outImage.initImage(self.outputFilename,'write',self.width,self.dataType) outImage.metadatalocation = self.outputFilename #create a suitable caster from self._dataTypeBindings to self.dataType outImage.setCaster('write',self._dataTypeBindings) outImage.createImage() return inImage,outImage
def AmpcorPrep(self): """ Prepare to be used in ampcor. Ampcor package in ISCE uses a special file pointer for accessing geotiff data. Therefore, we need ISCE module "Image" for this purpose. """ import isce from isceobj.Image.Image import Image # ==== need a vrt file # >= Python 3.4 from pathlib import Path vrtpath = Path(self.fpath + '.vrt') if not vrtpath.is_file(): print('Calling gdalbuildvrt...') gdalbuildvrt_cmd = 'gdalbuildvrt ' + self.fpath + '.vrt ' + self.fpath print(gdalbuildvrt_cmd) retcode = subprocess.call(gdalbuildvrt_cmd, shell=True) if retcode != 0: print( 'gdalbuildvrt failed. Please check if all the input parameters are properly set.' ) sys.exit(retcode) # ==================== obj = Image() obj.setFilename(self.fpath) obj.setWidth(self.GetRasterXSize()) # gdalinfo, first number if self.GetDataType() <= 3: obj.setDataType('SHORT') elif 4 <= self.GetDataType() <= 5: obj.setDataType('LONG') elif self.GetDataType() == 6: obj.setDataType('FLOAT') elif self.GetDataType() == 7: obj.setDataType('DOUBLE') # SHORT, LONG, FLOAT, DOUBLE, etc else: obj.setDataType('CFLOAT') # not totally right, may be wrong # obj.setBands(1) # "self" requires a single band # obj.setAccessMode('read') obj.setCaster('read', 'FLOAT') # fixed as float obj.createImage() self.iscepointer = obj