コード例 #1
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
    def createAccessor(self):
        if (not self.filename and hasattr(self, 'metadatalocation')
                and self.metadatalocation
                and not self.accessMode.lower().count('write')):
            #it will only keep going if all ok
            self.filename = self.checkLocation()
        caster = '' or self.caster
        filename = self.filename
        scheme = self.scheme
        self.extraFilename = self.filename + '.' + self._extra_reader

        if self._accessor is None:  #to avoid creating duplicates
            selection = self.methodSelector()
            if selection == 'api':
                size = DA.getTypeSize(self.dataType)
                #to optimize bip access per band we read in memory all bands and then
                #set the right band and write the content back leaving the other bands untouched
                #this requires a read and write which only works if the file is opened in
                #writeread (or readwrite) mode and not just write
                if (self.accessMode.lower() == 'write'):
                    #if(self.scheme.lower() == 'bip' and self.accessMode.lower() == 'write'):
                    self.accessMode = 'writeread'
            elif selection == self._extra_reader:
                size = self.getGDALDataTypeId(self.dataType)
                filename = self._extraFilename
                #GDALAccessor handles all the different scheme in the same way since it reads
                #always in BSQ scheme regardless of the under laying scheme
                scheme = 'GDAL'
            else:
                print('Cannot select appropruiate image API')
                raise Exception
            self._accessor, self._factory = DA.createAccessor(
                filename, self.accessMode, size, self.bands, self.width,
                scheme, caster, self._extraInfo)
        return None
コード例 #2
0
 def createAccessor(self):
     if self._accessor is None:  #to avoid to creating duplicates
         size = DA.getTypeSize(self.dataType)
         caster = '' or self.caster
         self._accessor, self._factory = DA.createAccessor(
             self.filename, self.accessMode, size, self.bands, self.width,
             self.scheme, caster)
     return None
コード例 #3
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
    def finalizeAccessor(self):
        try:
            DA.finalizeAccessor(self._accessor, self._factory)
        except TypeError:
            message = "Image %s is already finalized" % str(self)
            if ERROR_CHECK_FINALIZE:
                raise RuntimeError(message)
            else:
                print(message)

        self._accessor = None
        self._factory = None
        return None
コード例 #4
0
    def finalize(self):
        from isceobj.Util import combinedlibmodule as CL
        CL.freeCPoly2D(self._poly)
        try:
            DA.finalizeAccessor(self._accessor, self._factory)
        except TypeError:
            message = "Poly2D %s is already finalized" % str(self)
            if ERROR_CHECK_FINALIZE:
                raise RuntimeError(message)
            else:
                print(message)

        self._accessor = None
        self._factory = None
        return None
コード例 #5
0
 def createPoly2D(self):
     if self._accessor is None:
         self._poly = self.exportToC()
         self._accessor, self._factory = DA.createPolyAccessor(
             self._poly, "poly2d", self._width, self._length,
             self._dataSize)
     else:
         print(
             'C pointer already created. Finalize and recreate if image dimensions changed.'
         )
コード例 #6
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
    def getFileLength(self):
        openedHere = False

        if self._accessor is None:
            openedHere = True
            self.initAccessor(self.filename, 'read', int(self.width),
                              self.dataType, int(self.bands), self.scheme)
            self.createAccessor()
        length = DA.getFileLength(self._accessor)

        if openedHere:
            self.finalizeAccessor()

        return length
コード例 #7
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
 def getTypeSizeS(type_):
     return DA.getTypeSize(type_)
コード例 #8
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
 def createFile(self, lines):
     DA.createFile(self._accessor, lines)
コード例 #9
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
 def rewind(self):
     DA.rewind(self._accessor)
コード例 #10
0
ファイル: DataAccessorPy.py プロジェクト: shakenbaby216/isce2
 def getTypeSize(self):
     return DA.getTypeSize(self.dataType)
コード例 #11
0
    def __init__(self):

        size = DA.getTypeSize(
            'LONG'
        )  #the size depends on the platform. the ImageAPI does e sizeof(long int) and returns the size
        #NOTE the unw  doent't need a datatype so put ''
        self._mapDataType = {
            'xml': {
                'BYTE': '-i1',
                'SHORT': '-i2',
                'CFLOAT': '-c8',
                'FLOAT': '-r4',
                'INT': '-i4',
                'LONG': '-i' + str(size),
                'DOUBLE': '-r8'
            },
            'rsc': {
                'cpx': '-c8',
                'rmg': '-r4',
                'scor': '-r4',
                'dem': '-i2',
                'byt': '-i1',
                'amp': '-r4',
                'unw': '-r4',
                'cor': ''
            }
        }

        self._docIn = [
            '  mdx.py  : displays one or more data files simultaneously by ',
            '            specifying their names as input. The maximun number,'
            '            of images that can be displayed depends on the machine',
            '            architecture and  mdx limits. If displayed (no -kml flag)',
            '            the images don\'t need to have the same extension, but need',
            '            to have same width.', ' ',
            '  filename: input file containing the image metadata.',
            '            Metadata files must be of format filename.{xml,rsc}',
            '            and must be  present in the same directory as filename.',
            '            Different formats (xml,rsc) can be mixed.', ' ',
            '  -wrap   : sets display scaling to wrap mode with a modules of Pi.',
            '            It must follow the filename to which the wrap is applied.',
            ' ',
            '  ...     : the command can be repeated for different images.',
            ' ',
            '  -z      : zoom factor (+ or -) to apply to all layers. It\'s optional',
            '            and can appear anywhere in the command sequence and must',
            '            appear only once.', ' ',
            '  -kml    : only for geocoded images it creates a klm file with all the',
            '            input images overlaid. Each layer can be turn on or off in ',
            '            Goolge Earth. It\'s optional and can appear anywhere in the ',
            '            command sequence and must appear only once. The images don\'t ',
            '             need to be co-registed.', ' ', '  Examples:',
            '  mdx.py 01_02.int                                  # Standard way to run mdx.py',
            '  mdx.py -P 01_02.int                               # Create a ppm image named out.ppm',
            '  mdx.py 03_04.int 05_06.int -z -8                  # Display two images; zoom out by 8',
            '  mdx.py 03_04.geo -z 8 05_06.geo -kml fileout.klm  # Create a kml file named fileout.kml with two',
            '                                                    # layers, one per image. Both images are zoomed in',
            '                                                    # by a factor of 8     ',
            '  mdx.py 03_04.int 05_06.int -wrap 6.28             # Display two images. Wrap the second modulo 2Pi',
            ' '
        ]
        # the input file is the image itself. Search for the same filename
        # and one of the extensions below to figure out the metadata type
        self._metaExtensions = ['.xml', '.rsc']
        self._ext = {}
        self._ext['cpx'] = ['slc', 'int', 'flat', 'mph', 'cpx']
        self._ext['rmg'] = ['hgt', 'hgt_holes', 'rect', 'rmg']
        self._ext['scor'] = ['scor']
        self._ext['dem'] = ['dem', 'dte', 'dtm']
        self._ext['unw'] = ['unw']
        self._ext['cor'] = ['cor']
        self._ext['byt'] = ['byt', 'flg']
        self._ext['amp'] = ['amp']
        self._ext['bil'] = ['bil']
        self._ext['bip'] = ['bip']
        self._ext['bsq'] = ['bsq']
        # save this quantities in the case we are dealing with a geo image
        self._startLat = []
        self._deltaLat = []
        self._startLon = []
        self._deltaLon = []
        self._length = []
        self._width = []
        self._names = []