コード例 #1
0
def tkfunc(self):
    from isceobj.Scene.Track import Track
    tk = Track()
    if (len(self._imageFileList) > 1):
        self.frame = tk.combineFrames(self.output, self.frameList)
        for i in range(len(self._imageFileList)):
            try:
                print(self.output + "_" + str(i))
                os.remove(self.output + "_" + str(i))
            except OSError:
                print("Error. Cannot remove temporary file",
                      self.output + "_" + str(i))
                raise OSError
            pass
        pass
    pass
コード例 #2
0
def main():
    output = 'test.raw'
    frame1 = createERSFrame(leaderFile='/Users/szeliga/data/InSAR/raw/ers/track134/frame2961/930913/SARLEADER199309132961f134t',
                   imageryFile='/Users/szeliga/data/InSAR/raw/ers/track134/frame2961/930913/IMAGERY199309132961f134t',
                   output='frame2961.raw')
    frame2 = createERSFrame(leaderFile='/Users/szeliga/data/InSAR/raw/ers/track134/frame2979/930913/SARLEADER199309132979f134t',
                   imageryFile='/Users/szeliga/data/InSAR/raw/ers/track134/frame2979/930913/IMAGERY199309132979f134t',
                   output='frame2979.raw')

    track = Track()
    track.addFrame(frame1)
    track.addFrame(frame2)
    track.createTrack(output)
コード例 #3
0
ファイル: ERS.py プロジェクト: HBaldwin3/isce_v2.0.0
    def extractImage(self):
        import array
        import math
        # 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 Exception

        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.leaderFile.parse()

            self.imageFile = ImageFile(self)

            try:
                outputNow = self.output + appendStr
                out = open(outputNow,'wb')
            except IOError as strerr:
                self.logger.error("IOError: %s" % strerr)
                return

            self.imageFile.extractImage(output=out)
            out.close()

            rawImage = isceobj.createRawImage()
            rawImage.setByteOrder('l')
            rawImage.setAccessMode('read')
            rawImage.setFilename(outputNow)
            rawImage.setWidth(self.imageFile.width)
            rawImage.setXmin(0)
            rawImage.setXmax(self.imageFile.width)
            self.frame.setImage(rawImage)
            self.populateMetadata()
            self.frameList.append(self.frame)
            #jng Howard Z at this point adjusts the sampling starting time for imagery generated from CRDC_SARDPF facility.
            # for now create the orbit aux file based in starting time and prf
            prf = self.frame.getInstrument().getPulseRepetitionFrequency()
            senStart = self.frame.getSensingStart()
            numPulses = int(math.ceil(DTU.timeDeltaToSeconds(self.frame.getSensingStop()-senStart)*prf))
            # the aux files has two entries per line. day of the year and microseconds in the day
            musec0 = (senStart.hour*3600 + senStart.minute*60 + senStart.second)*10**6 + senStart.microsecond
            maxMusec = (24*3600)*10**6#use it to check if we went across  a day. very rare
            day0 = (datetime.datetime(senStart.year,senStart.month,senStart.day) - datetime.datetime(senStart.year,1,1)).days + 1
            outputArray  = array.array('d',[0]*2*numPulses)
            self.frame.auxFile = outputNow + '.aux'
            fp = open(self.frame.auxFile,'wb')
            j = -1
            for i1 in range(numPulses):
                j += 1
                musec = round((j/prf)*10**6) + musec0
                if musec >= maxMusec:
                    day0 += 1
                    musec0 = musec%maxMusec
                    musec = musec0
                    j = 0
                outputArray[2*i1] = day0
                outputArray[2*i1+1] = musec

            outputArray.tofile(fp)
            fp.close()

        tk = Track()
        if(len(self._imageFileList) > 1):
            self.frame = tk.combineFrames(self.output,self.frameList)

            for i in range(len(self._imageFileList)):
                try:
                    os.remove(self.output + "_" + str(i))
                except OSError:
                    print("Error. Cannot remove temporary file",self.output + "_" + str(i))
                    raise OSError
コード例 #4
0
    def extractImage(self):
        import array
        import math

        self.frameList = []

        for i in range(len(self._imageFileList)):
            appendStr = "_" + str(i)  #intermediate raw files suffix
            if (len(self._imageFileList) == 1):
                appendStr = ''  #if only one file don't change the name

            outputNow = self.output + appendStr
            auxImage = isceobj.createImage()  # unused
            widthAux = 2  # unused
            auxName = outputNow + '.aux'

            self.imageFile = self._imageFileList[i]
            self.frame = Frame()
            self.frame.configure()

            self.frame.auxFile = auxName  #add the auxFile as part of the frame and diring the stitching create also a combined aux file # HB: added from Envisat.py
            imageFileParser = ImageFile(fileName=self.imageFile)
            self._imageFileData = imageFileParser.parse(
            )  # parse image and get swst values and new width

            try:
                outputNow = self.output + appendStr
                out = open(outputNow, 'wb')
            except IOError as strerr:
                self.logger.error("IOError: %s" % strerr)
                return

            imageFileParser.extractIQ(
                output=out)  # IMPORTANT for ERS Envisat-type data
            out.close()

            self.populateMetadata(
            )  # populate Platform, Instrument, Frame, and Orbit
            self._populateImage(outputNow)
            self.frameList.append(self.frame)

            ### Below: create a aux file
            # for now create the orbit aux file based in starting time and prf
            prf = self.frame.getInstrument().getPulseRepetitionFrequency()
            senStart = self.frame.getSensingStart()
            numPulses = int(
                math.ceil(
                    DTU.timeDeltaToSeconds(self.frame.getSensingStop() -
                                           senStart) * prf))
            # the aux files has two entries per line. day of the year and microseconds in the day
            musec0 = (senStart.hour * 3600 + senStart.minute * 60 +
                      senStart.second) * 10**6 + senStart.microsecond
            maxMusec = (
                24 * 3600
            ) * 10**6  # use it to check if we went across a day. very rare
            day0 = (datetime.datetime(senStart.year, senStart.month,
                                      senStart.day) -
                    datetime.datetime(senStart.year, 1, 1)).days + 1
            outputArray = array.array('d', [0] * 2 * numPulses)
            self.frame.auxFile = outputNow + '.aux'
            fp = open(self.frame.auxFile, 'wb')
            j = -1
            for i1 in range(numPulses):
                j += 1
                musec = round((j / prf) * 10**6) + musec0
                if musec >= maxMusec:
                    day0 += 1
                    musec0 = musec % maxMusec
                    musec = musec0
                    j = 0
                outputArray[2 * i1] = day0
                outputArray[2 * i1 + 1] = musec

            outputArray.tofile(fp)
            fp.close()

        ## refactor this with __init__.tkfunc
        tk = Track()
        if (len(self._imageFileList) > 1):
            self.frame = tk.combineFrames(self.output, self.frameList)

            for i in range(len(self._imageFileList)):
                try:
                    os.remove(self.output + "_" + str(i))
                except OSError:
                    print("Error. Cannot remove temporary file",
                          self.output + "_" + str(i))
                    raise OSError
コード例 #5
0
    def extractImage(self):
        from datetime import datetime as dt
        import tempfile as tf
        lib = ctypes.cdll.LoadLibrary(
            os.path.dirname(__file__) + '/envisat.so')
        #check if input file is a string or a list (then do concatenation)
        #ussume that one orbit and one instrument is enough for all the frame in the list
        #        if isinstance(self._imageryFileList,str):
        #            self._imageryFileList = [self._imageryFileList]
        self.frameList = []
        for i in range(len(self._imageryFileList)):
            appendStr = '_' + str(i)  #intermediate raw files suffix
            if len(self._imageryFileList) == 1:
                appendStr = ''  # no suffix if only one file

            outputNow = self.output + appendStr
            auxImage = isceobj.createImage()
            widthAux = 2
            auxName = outputNow + '.aux'
            self.imageryFile = self._imageryFileList[i]
            self.frame = Frame()
            self.frame.configure()

            #add the auxFile as part of the frame and diring the stitching create also a combined aux file
            self.frame.auxFile = auxName
            self.parse()

            #Declare the types of the arguments to asa_im_decode
            lib.asa_im_decode.argtypes = [
                ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p,
                ctypes.c_char_p, ctypes.c_int, ctypes.c_ushort, ctypes.c_int,
                ctypes.POINTER(ctypes.c_int),
                ctypes.POINTER(ctypes.c_int)
            ]

            #Set the daysToRemove variable for the call to asa_im_decode
            sensingYear = self.frame.getSensingStart().year
            daysToRemove = ctypes.c_int(
                (dt(sensingYear - 1, 12, 31) - dt(2000, 1, 1)).days)

            #Create memory for pointers nsamps and nlines to be set by
            #asa_im_decode
            a = 1
            b = 2
            nsamps = ctypes.pointer(ctypes.c_int(a))
            nlines = ctypes.pointer(ctypes.c_int(b))

            #Variables for outType and windowStartTimeCodeword0 passed to
            #asa_im_decode
            c = 1
            d = 0

            lib.asa_im_decode(
                ctypes.c_char_p(bytes(self.imageryFile, 'utf-8')),
                ctypes.c_char_p(bytes(self.instrumentFile, 'utf-8')),
                ctypes.c_char_p(bytes(outputNow, 'utf-8')),
                ctypes.c_char_p(bytes(auxName, 'utf-8')), ctypes.c_int(c),
                ctypes.c_ushort(d), daysToRemove, nsamps, nlines)

            #Create the outStruct for the call to populateImage
            outStruct = ImageOutput(nsamps[0], nlines[0])

            self._populateImage(outStruct, outputNow)
            self.frameList.append(self.frame)
            pass

        ## refactor this with __init__.tkfunc
        tk = Track()
        if (len(self._imageryFileList) > 1):
            self.frame = tk.combineFrames(self.output, self.frameList)

            for i in range(len(self._imageryFileList)):
                try:
                    os.remove(self.output + "_" + str(i))
                except OSError:
                    print("Error. Cannot remove temporary file",
                          self.output + "_" + str(i))
                    raise OSError
                pass
            pass
        pass