Пример #1
0
    def createImages(self):
        #the fortran code use to read in short, convert to float and convert back to short.
        #let's use the image api and teh casters to do that
        if (self._inImage is None) or (self._inImage.dataType.upper() !=
                                       'FLOAT'):
            print('Creating input Image')
            inImage = createDemImage()
            if self._inType.upper() == 'SHORT':
                inImage.initImage(self.inputFilename,
                                  'read',
                                  self.width,
                                  'SHORT',
                                  caster='ShortToFloatCaster')
            elif self._inType.upper() == 'INT':
                inImage.initImage(self.inputFilename,
                                  'read',
                                  self.width,
                                  'INT',
                                  caster='IntToFloatCaster')
            else:
                inImage.initImage(self.inputFilename, 'read', self.width,
                                  'FLOAT')

            inImage.createImage()
            self._inImage = inImage
        else:
            if self._inImage.width != self.width:
                raise Exception('Input Image width inconsistency.')

            if self._inImage.length != self.numberLines:
                raise Exception('Input Image length inconsistency.')

            if self._inImage.getImagePointer() is None:
                self._inImage.createImage()

        if self._outImage is None:
            outImage = createDemImage()
            #manages float and writes out short
            outImage.initImage(self.outputFilename, 'write', self._outWidth,
                               'FLOAT')
            outImage.createImage()
            self._outImage = outImage
        else:
            if self._outImage.width != self._outWidth:
                raise Exception('Output Image width inconsistency.')

            if self._outImage.length != self._outNumberLines:
                raise Exception('Output Image length inconsistency.')

        return
Пример #2
0
    def createImage(self, outname):
        from isceobj.Image import createDemImage

        demImage = createDemImage()

        try:
            os.makedirs(self._downloadDir)
        except:
            #dir already exists
            pass

        width = self._width
        demImage.initImage(outname, 'read', width)
        demImage.dataType = 'BYTE'
        length = demImage.getLength()
        deltaLat = (self._lastLatitude - self._firstLatitude) / (length - 1.0)
        deltaLon = (self._lastLongitude - self._firstLongitude) / (width - 1.0)
        dictProp = {
            'REFERENCE': self._reference,
            'Coordinate1': {
                'size': width,
                'startingValue': self._firstLongitude,
                'delta': deltaLon
            },
            'Coordinate2': {
                'size': length,
                'startingValue': self._firstLatitude,
                'delta': -deltaLat
            },
            'FILE_NAME': outname
        }
        #no need to pass the dictionaryOfFacilities since init will use the default one
        demImage.init(dictProp)
        self._image = demImage
        return demImage
Пример #3
0
def create_dem_header(dem_file, rsc_file=None, datum="EGM96"):
    from isceobj.Image import createDemImage

    if rsc_file is None:
        rsc_file = dem_file + ".rsc"

    rsc_dict = sario.load(rsc_file)
    width, length = rsc_dict["width"], rsc_dict["file_length"]

    demImage = createDemImage()
    demImage.initImage(dem_file, "read", width)
    demImage.dataType = "BYTE"

    dictProp = {
        "REFERENCE": datum,
        "Coordinate1": {
            "size": width,
            "startingValue": rsc_dict["x_first"],
            "delta": rsc_dict["x_step"],
        },
        "Coordinate2": {
            "size": length,
            "startingValue": rsc_dict["y_first"],
            "delta": rsc_dict["y_step"],
        },
        "FILE_NAME": dem_file,
    }
    # no need to pass the dictionaryOfFacilities since init will use the default one
    demImage.init(dictProp)
    demImage.renderHdr()
Пример #4
0
    def createImages(self):
        if self.demCropFilename:
            self.demCropImage = createDemImage()
            demAccessMode = 'write'
            demWidth = self.computeGeoImageWidth()
            self.demCropImage.initImage(self.demCropFilename, demAccessMode,
                                        demWidth)
            self.demCropImage.createImage()
            self.demCropAccessor = self.demCropImage.getImagePointer()
        else:
            self.demCropAccessor = 0

        if self.geoFilename is None:
            raise ValueError('Output geoFilename not specified')

        #the topophase files have the same format as the int file. just reuse the previous info
        self.geoImage = createIntImage()
        IU.copyAttributes(self.inputImage, self.geoImage)
        self.geoImage.imageType = self.inputImage.imageType
        self.geoImage.setFilename(self.geoFilename)
        self.geoImage.setAccessMode('write')
        self.geoImage.setWidth(demWidth)

        if not self.geoImage.dataType.upper().count('FLOAT'):
            self.geoImage.setCaster('write', 'FLOAT')

        self.geoImage.createImage()
        self.geoAccessor = self.geoImage.getImagePointer()

        self.polyDopplerAccessor = self.polyDoppler.exportToC()
Пример #5
0
    def createXmlMetadata(self):
        from isceobj.Image import createDemImage

        demImage = createDemImage()
        demImage.dataType = 'FLOAT'
        outname = self._outputFilename
        demImage.initImage(outname, 'read', self._outWidth)
        length = demImage.getLength()
        deltaLon = self._deltaLongitude / (3600.0 * self.xFactor)
        deltaLat = self._deltaLatitude / (3600.0 * self.yFactor)

        dictProp = {
            'Coordinate1': {
                'size': self._outWidth,
                'startingValue': self._startLongitude,
                'delta': deltaLon
            },
            'Coordinate2': {
                'size': length,
                'startingValue': self._startLatitude,
                'delta': deltaLat
            },
            'FILE_NAME': outname
        }
        if self.reference:
            dictProp['REFERENCE'] = self.reference
        #no need to pass the dictionaryOfFacilities since init will use the default one
        demImage.init(dictProp)
        demImage.renderHdr()
        self._image = demImage
        return
Пример #6
0
    def createImage(self, lat, lon, source, outname):
        from isceobj.Image import createDemImage

        demImage = createDemImage()
        if source == 3:
            delta = 1 / 1200.0
        else:
            delta = 1 / 3600.0

        os.makedirs(self._downloadDir, exist_ok=True)

        width = self.getDemWidth(lon, source)
        demImage.initImage(outname, 'read', width)
        length = demImage.getLength()
        dictProp = {
            'METADATA_LOCATION': outname + '.xml',
            'REFERENCE': self._reference,
            'Coordinate1': {
                'size': width,
                'startingValue': min(lon[0], lon[1]),
                'delta': delta
            },
            'Coordinate2': {
                'size': length,
                'startingValue': max(lat[0], lat[1]),
                'delta': -delta
            },
            'FILE_NAME': outname
        }
        #no need to pass the dictionaryOfFacilities since init will use the default one
        demImage.init(dictProp)
        self._image = demImage
        return demImage
Пример #7
0
    def cropImage(self, geoname, inname, outname, which):
        im1 = createImage()
        im1.load(geoname)
        if which == 'dem':
            im2 = createDemImage()
        elif which == 'wbd':
            im2 = createImage()
        else:
            raise Exception('Unrecognized image type')
        im2.load(inname)

        latstart1 = im1.coord2.coordStart
        latsize1 = im1.coord2.coordSize
        latdelta1 = im1.coord2.coordDelta
        lonstart1 = im1.coord1.coordStart
        lonsize1 = im1.coord1.coordSize
        londelta1 = im1.coord1.coordDelta
        latstart2 = im2.coord2.coordStart
        latsize2 = im2.coord2.coordSize
        latdelta2 = im2.coord2.coordDelta
        lonstart2 = im2.coord1.coordStart
        lonsize2 = im2.coord1.coordSize
        londelta2 = im2.coord1.coordDelta
        ilatstart = abs(int(round((latstart2 - latstart1) / latdelta2)))
        ilatend = ilatstart + latsize1
        ilonstart = abs(int(round((lonstart2 - lonstart1) / londelta2)))
        ilonend = ilonstart + lonsize1
        imIn = im2.memMap(band=0)
        #if it the resolutions are different the ration will normally  be either twice or half
        #or some integer (or inverse integer ratio)
        if ((londelta2 / londelta1) > 1.5 or (londelta2 / londelta1) < .8):
            #make sure that is close to an int
            if (abs(londelta2 / londelta1 - round(londelta2 / londelta1)) <
                    .001 or abs(londelta1 / londelta2 -
                                round(londelta1 / londelta2)) < .001):
                imIn = self.resample((londelta2 / londelta1), imIn)
            else:
                raise Exception(
                    'Cannot resample DEM and water mask to data grid')

        #create mmap of goename size but dem data type
        imCrop = np.memmap(outname,
                           im2.toNumpyDataType(),
                           'w+',
                           shape=(latsize1, lonsize1))

        imCrop[:, :] = imIn[ilatstart:ilatend, ilonstart:ilonend]

        im3 = im2.clone()
        im3.filename = outname
        im3.coord2.coordStart = latstart1
        im3.coord2.coordSize = latsize1
        im3.coord2.coordDelta = latdelta1
        im3.coord2.coordEnd = latstart1 + latsize1 * latdelta1
        im3.coord1.coordStart = lonstart1
        im3.coord1.coordSize = lonsize1
        im3.coord1.coordDelta = londelta1
        im3.coord1.coordEnd = lonstart1 + lonsize1 * londelta1
        im3.renderHdr()
Пример #8
0
 def loadImage(self, imgxml, band=None):
     if imgxml == self._imgMap['dem']['name']:
         img = createDemImage()
     else:
         img = createImage()
     img.load(imgxml)
     img.filename = os.path.basename(img.filename)
     return img.memMap(band=band)
Пример #9
0
 def createImage(self,lats,lons,filename):
     img = createDemImage()
     lons = np.sort(lons)
     img.initImage(filename,'read',self._tileWidth*int(np.diff(lons)[0]))
     img._metadataLocation = filename + '.xml'
     img.coord1.coordStart = lons[0]
     img.coord1.coordDelta = 1./self._tileWidth
     img.coord2.coordStart = np.sort(lats)[-1]
     img.coord2.coordDelta = -1./self._tileWidth
     return img
Пример #10
0
    def createImages(self):
        demWidth = self.computeGeoImageWidth()
        demLength = self.computeGeoImageLength()

        if self.demCropFilename:
            self.demCropImage = createDemImage()
            demAccessMode = 'write'
            self.demCropImage.initImage(self.demCropFilename, demAccessMode,
                                        demWidth)
            self.demCropImage.createImage()
            self.demCropAccessor = self.demCropImage.getImagePointer()
        else:
            self.demCropAccessor = 0

        if self.geoFilename is None:
            raise ValueError('Output geoFilename not specified')

        #the topophase files have the same format as the int file. just reuse the previous info
        self.geoImage = createIntImage()
        IU.copyAttributes(self.inputImage, self.geoImage)
        self.geoImage.imageType = self.inputImage.imageType
        self.geoImage.setFilename(self.geoFilename)
        self.geoImage.setAccessMode('write')
        self.geoImage.setWidth(demWidth)
        self.geoImage.coord1.coordEnd = None
        self.geoImage.coord2.coordEnd = None

        if not self.geoImage.dataType.upper().count('FLOAT'):
            self.geoImage.setCaster('write', 'FLOAT')
        self.geoImage.createImage()
        self.geoImage.createFile(demLength)

        self.geoAccessor = self.geoImage.getImagePointer()
        if (self.losImage == None and self.losFilename not in ('', None)):
            self.losImage = createImage()
            accessMode = 'write'
            dataType = 'FLOAT'
            bands = 2
            scheme = 'BIL'
            width = demWidth
            self.losImage.initImage(self.losFilename,
                                    accessMode,
                                    width,
                                    dataType,
                                    bands=bands,
                                    scheme=scheme)
            self.losImage.createImage()
            self.losAccessor = self.losImage.getImagePointer()

        self.polyDopplerAccessor = self.polyDoppler.exportToC()
Пример #11
0
 def getDemAndWbd(self, geoname, names):
     image = createDemImage()
     image.load(geoname)
     latmax = ceil(image.coord2.coordStart)
     latmin = floor(image.coord2.coordStart +
                    image.coord2.coordSize * image.coord2.coordDelta)
     lonmin = floor(image.coord1.coordStart)
     lonmax = ceil(image.coord1.coordStart +
                   image.coord1.coordSize * image.coord1.coordDelta)
     bbox = ''.join(str([latmin, latmax, lonmin, lonmax]).split())
     command = 'stitcher.py stitcher.xml stitcher.demStitcher.bbox=' + bbox \
             + ' stitcher.demStitcher.outputfile=' + names[0] + " > sticher.log"
     print(command)
     os.system(command)
     command = 'wbdStitcher.py swbdStitcher.xml wbdstitcher.wbdstitcher.bbox=' + bbox \
             + ' wbdstitcher.wbdstitcher.outputfile=' + names[1] + " > wdbStitcher.log"
     print(command)
     os.system(command)
Пример #12
0
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
Пример #13
0
    def createXmlMetadata(self):
        from isceobj.Image import createDemImage

        demImage = createDemImage()

        outname = self._outputFilename
        demImage.initImage(outname, 'read', self._width, self._dataType)
        length = demImage.getLength()
        deltaLon = self._deltaLongitude
        deltaLat = self._deltaLatitude

        dictProp = {'REFERENCE':self.reference,'Coordinate1': \
                   {'size':self._width,'startingValue':self._startLongitude,'delta':deltaLon}, \
                   'Coordinate2':{'size':length,'startingValue':self._startLatitude, \
                   'delta':deltaLat},'FILE_NAME':outname}
        #no need to pass the dictionaryOfFacilities since init will use the default one
        demImage.init(dictProp)
        demImage.renderHdr()
        self._image = demImage
Пример #14
0
    return values

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

    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.endswith('.xml'):
        outFile = os.path.splitext(inps.outfile)[0]
    else:
        outFile = inps.outfile

    parser = createFileParser('xml')
    prop, fac, misc = parser.parse(inFileXml)


    inImage = createDemImage()
    inImage.init(prop,fac,misc)
    inImage.filename = inFile 
    inImage.createImage()

    upsampObj = UpsampleDem()
    upsampObj.method = inps.method
    upsampObj.setOutputFilename(outFile)
    upsampObj.upsampledem(demImage=inImage, yFactor=inps.factor[0], xFactor=inps.factor[1])