Exemplo n.º 1
0
    def extractImage(self):
        # just in case there was only one image and it was passed as a str
        #instead of a list with only one element
        if (isinstance(self._imageFileList, str)):
            self._imageFileList = [self._imageFileList]
            self._leaderFileList = [self._leaderFileList]
        if (len(self._imageFileList) != len(self._leaderFileList)):
            self.logger.error(
                "Number of leader files different from number of image files.")
            raise RuntimeError
        self.frameList = []
        for i in range(len(self._imageFileList)):
            appendStr = "_" + str(i)
            #if only one file don't change the name
            if (len(self._imageFileList) == 1):
                appendStr = ''

            self.frame = Frame()
            self.frame.configure()

            self._leaderFile = self._leaderFileList[i]
            self._imageFile = self._imageFileList[i]
            self.leaderFile = LeaderFile(file=self._leaderFile)
            self.imageFile = ImageFile(self)

            try:
                self.leaderFile.parse()
                self.imageFile.parse(calculateRawDimensions=False)
                outputNow = self.output + appendStr
                if not (self._resampleFlag == ''):
                    filein = self.output + '__tmp__'
                    self.imageFile.extractImage(filein)
                    self.populateMetadata()
                    objResample = None
                    if (self._resampleFlag == 'single2dual'):
                        objResample = ALOS_fbs2fbdPy()
                    else:
                        objResample = ALOS_fbd2fbsPy()
                    objResample.wireInputPort('frame', object=self.frame)
                    objResample.setInputFilename(filein)
                    objResample.setOutputFilename(outputNow)
                    objResample.run()
                    objResample.updateFrame(self.frame)
                    os.remove(filein)
                else:
                    self.imageFile.extractImage(outputNow)
                    self.populateMetadata()
                width = self.frame.getImage().getWidth()
                self.readOrbitPulse(self._leaderFile, outputNow, width)
                self.frameList.append(self.frame)
            except IOError:
                return
            pass
        ## refactor this with __init__.tkfunc
        return tkfunc(self)
Exemplo n.º 2
0
    def extractImage(self):
        """Extract the raw image data"""
        import os
        from ctypes import cdll, c_char_p
        extract_csk = cdll.LoadLibrary(os.path.dirname(__file__)+'/csk.so')
        # Prepare and run the C-based extractor

        #check if the input is a string. if so put it into one element list
        if(isinstance(self.hdf5FileList,str)):
            self.hdf5FileList = [self.hdf5FileList]

        for i in range(len(self.hdf5FileList)):
            #need to create a new instance every time
            self.frame = Frame()
            self.frame.configure()
            appendStr = '_' + str(i)
            # if more than one file to contatenate that create different outputs
            # but suffixing _i
            if(len(self.hdf5FileList) == 1):
                appendStr = ''
            outputNow = self.output + appendStr
            self.hdf5 = self.hdf5FileList[i]
            inFile_c = c_char_p(bytes(self.hdf5,'utf-8'))
            outFile_c = c_char_p(bytes(outputNow,'utf-8'))

            extract_csk.extract_csk(inFile_c,outFile_c)
            # Now, populate the metadata
            try:
                fp = h5py.File(self.hdf5,'r')
            except Exception as strerror:
                self.logger.error("IOError: %s\n" % strerror)
                return
            self.populateMetadata(file=fp)
            self.populateImage(outputNow)
            self._populateExtras(fp)

            fp.close()
            self.frameList.append(self.frame)
            createAuxFile(self.frame,outputNow + '.aux')
        self._imageFileList = self.hdf5FileList
        return tkfunc(self)