Exemple #1
0
def unpack(hdf5, slcname, deskew=False, polarization='HH'):
    '''
    Unpack HDF5 to binary SLC file.
    '''

    imgname = glob.glob(os.path.join(hdf5,
                                     '*/IMG-{}*'.format(polarization)))[0]
    ldrname = glob.glob(os.path.join(hdf5, '*/LED*'))[0]
    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)
    obj = createSensor('ALOS2')
    obj.configure()
    obj._leaderFile = ldrname
    obj._imageFile = imgname

    if deskew:
        obj.output = os.path.join(slcname, date + '_orig.slc')
    else:
        obj.output = os.path.join(slcname, date + '.slc')

    print(obj._leaderFile)
    print(obj._imageFile)
    print(obj.output)
    obj.extractImage()
    obj.frame.getImage().renderHdr()

    coeffs = obj.doppler_coeff
    dr = obj.frame.getInstrument().getRangePixelSize()
    r0 = obj.frame.getStartingRange()

    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(coeffs) - 1)
    poly.setCoeffs(coeffs)

    fcoeffs = obj.azfmrate_coeff
    fpoly = Poly1D.Poly1D()
    fpoly.initPoly(order=len(fcoeffs) - 1)
    fpoly.setCoeffs(fcoeffs)

    if deskew:
        pickName = os.path.join(slcname, 'original')
    else:
        pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly
        db['fmrate'] = fpoly
        db['info'] = obj.leaderFile.facilityRecord.metadata

    print(poly._coeffs)
    print(fpoly._coeffs)
    return obj
Exemple #2
0
def unpack(RSATdir, slcname):
    '''
    Unpack RADARSAT2 data to binary SLC file. assume HH only for now
    '''

    ###Search for imagery and XML files in input directory
    imgname = glob.glob(os.path.join(RSATdir, 'imagery*.tif'))[0]
    xmlname = glob.glob(os.path.join(RSATdir, 'product.xml'))[0]

    ####Create output SLC directory if needed
    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)

    #####Create an Radarsat2 object and wire it
    obj = createSensor('Radarsat2')
    obj.configure()
    obj.xml = xmlname
    obj.tiff = imgname
    obj.output = os.path.join(slcname, date + '.slc')

    ####Extract the image and write the XML file for the SLC
    obj.extractImage()
    obj.frame.getImage().renderHdr()

    ####Save the doppler polynomial
    ####CEOS already provides doppler polynomial
    ####as a function of range pixel
    coeffs = obj.doppler_coeff
    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(coeffs) - 1)
    poly.setCoeffs(coeffs)

    ####Save the FMrate polynomial
    ####CEOS already provides FMrate polynomial
    ####as a function of range pixel
    fcoeffs = obj.azfmrate_coeff
    #    fcoeffs = [0.0, 0.0, 0.0]  # zero-Doppler geometry, so this is not used
    fpoly = Poly1D.Poly1D()
    fpoly.initPoly(order=len(fcoeffs) - 1)
    fpoly.setCoeffs(fcoeffs)

    ####Save required metadata for further use
    ####All data is output to a shelve file
    pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly
        db['fmrate'] = fpoly
Exemple #3
0
    def extractDoppler(self):
        '''
        self.parse()
        Extract doppler information as needed by mocomp
        '''
        from isceobj.Util import Poly1D

        node = self._xml_root.find('dopplerCentroid/dcEstimateList')

        tdiff = 1.0e9
        dpoly = None

        for index, burst in enumerate(node):
            refTime = self.convertToDateTime(burst.find('azimuthTime').text)

            delta = abs((refTime - self.frame.sensingMid).total_seconds())
            if delta < tdiff:
                tdiff = delta
                r0 = 0.5 * Const.c * float(burst.find('t0').text)
                coeffs = [
                    float(val)
                    for val in burst.find('dataDcPolynomial').text.split()
                ]

                poly = Poly1D.Poly1D()
                poly.initPoly(order=len(coeffs) - 1)
                poly.setMean(r0)
                poly.setNorm(0.5 * Const.c)
                poly.setCoeffs(coeffs)

                dpoly = poly

        if dpoly is None:
            raise Exception(
                'Could not extract Doppler information for S1 scene')

        ###Part for insarApp
        ###Should be removed in the future
        rmid = self.frame.startingRange + 0.5 * self.frame.getNumberOfSamples(
        ) * self.frame.getInstrument().getRangePixelSize()

        quadratic = {}
        quadratic['a'] = dpoly(
            rmid) / self.frame.getInstrument().getPulseRepetitionFrequency()
        quadratic['b'] = 0.
        quadratic['c'] = 0.

        ###Actual Doppler Polynomial for accurate processing
        ###Will be used in roiApp
        pix = np.linspace(0,
                          self.frame.getNumberOfSamples(),
                          num=dpoly._order + 2)
        rngs = self.frame.startingRange + pix * self.frame.getInstrument(
        ).getRangePixelSize()
        evals = dpoly(rngs)
        fit = np.polyfit(pix, evals, dpoly._order)
        self.frame._dopplerVsPixel = list(fit[::-1])
        print('Doppler Fit : ', fit[::-1])

        return quadratic
Exemple #4
0
def unpack(hdf5, slcname, polar='RH', isfloat=False):
    '''
    Unpack HDF5 to binary SLC file.
    '''

    obj = createSensor('RISAT1_SLC')
    obj._imageFile = os.path.join(hdf5, 'scene_' + polar, 'dat_01.001')
    obj._leaderFile = os.path.join(hdf5, 'scene_' + polar, 'lea_01.001')

    if isfloat:
        obj._dataType = 'float'
    else:
        obj._dataType = 'short'

    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)
    obj.output = os.path.join(slcname, date + '.slc')

    obj.extractImage()
    obj.frame.getImage().renderHdr()

    coeffs = obj.doppler_coeff
    dr = obj.frame.getInstrument().getRangePixelSize()
    r0 = obj.frame.getStartingRange()

    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(coeffs) - 1)
    poly.setCoeffs(coeffs)

    fcoeffs = obj.azfmrate_coeff
    fpoly = Poly1D.Poly1D()
    fpoly.initPoly(order=len(fcoeffs) - 1)
    fpoly.setCoeffs(fcoeffs)

    pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly
        db['fmrate'] = fpoly

    print(poly._coeffs)
    print(fpoly._coeffs)
Exemple #5
0
    def extractDoppler(self):
        """
        Return the doppler centroid as defined in the ASAR file.
        """
        quadratic = {}

        r0 = self.frame.getStartingRange()
        dr = self.frame.instrument.getRangePixelSize()
        width = self.frame.getNumberOfSamples()

        midr = r0 + (width/2.0) * dr
        midtime = 2 * midr/ Const.c - self.rangeRefTime

        fd_mid = 0.0
        tpow = midtime
        for kk in self.dopplerRangeTime:
            fd_mid += kk * tpow
            tpow *= midtime


        ####For insarApp
        quadratic['a'] = fd_mid/self.frame.getInstrument().getPulseRepetitionFrequency()
        quadratic['b'] = 0.
        quadratic['c'] = 0.

        
        ####For roiApp
        ####More accurate
        from isceobj.Util import Poly1D
        
        coeffs = self.dopplerRangeTime
        dr = self.frame.getInstrument().getRangePixelSize()
        rref = 0.5 * Const.c * self.rangeRefTime 
        r0 = self.frame.getStartingRange()
        norm = 0.5*Const.c/dr

        dcoeffs = []
        for ind, val in enumerate(coeffs):
            dcoeffs.append( val / (norm**ind))


        poly = Poly1D.Poly1D()
        poly.initPoly(order=len(coeffs)-1)
        poly.setMean( (rref - r0)/dr - 1.0)
        poly.setCoeffs(dcoeffs)


        pix = np.linspace(0, self.frame.getNumberOfSamples(), num=len(coeffs)+1)
        evals = poly(pix)
        fit = np.polyfit(pix,evals, len(coeffs)-1)
        self.frame._dopplerVsPixel = list(fit[::-1])
        print('Doppler Fit: ', fit[::-1])


        return quadratic
    def extractDoppler(self):
        '''
        self.parse()
        Extract doppler information as needed by mocomp
        '''
        ins = self.frame.getInstrument()
        dc = self.product.imageGenerationParameters.dopplerCentroid
        quadratic = {}

        r0 = self.frame.startingRange
        fs = ins.getRangeSamplingRate()
        tNear = 2 * r0 / Const.c

        tMid = tNear + 0.5 * self.frame.getNumberOfSamples() / fs
        t0 = dc.dopplerCentroidReferenceTime
        poly = dc.dopplerCentroidCoefficients

        fd_mid = 0.0
        for kk in range(len(poly)):
            fd_mid += poly[kk] * (tMid - t0)**kk

        ####For insarApp
        quadratic['a'] = fd_mid / ins.getPulseRepetitionFrequency()
        quadratic['b'] = 0.
        quadratic['c'] = 0.

        ####For roiApp
        ####More accurate
        from isceobj.Util import Poly1D

        coeffs = poly
        dr = self.frame.getInstrument().getRangePixelSize()
        rref = 0.5 * Const.c * t0
        r0 = self.frame.getStartingRange()
        norm = 0.5 * Const.c / dr

        dcoeffs = []
        for ind, val in enumerate(coeffs):
            dcoeffs.append(val / (norm**ind))

        poly = Poly1D.Poly1D()
        poly.initPoly(order=len(coeffs) - 1)
        poly.setMean((rref - r0) / dr - 1.0)
        poly.setCoeffs(dcoeffs)

        pix = np.linspace(0,
                          self.frame.getNumberOfSamples(),
                          num=len(coeffs) + 1)
        evals = poly(pix)
        fit = np.polyfit(pix, evals, len(coeffs) - 1)
        self.frame._dopplerVsPixel = list(fit[::-1])
        print('Doppler Fit: ', fit[::-1])

        return quadratic
def unpack(hdf5, slcname):
    '''
    Unpack HDF5 to binary SLC file.
    '''

    fname = glob.glob(os.path.join(hdf5,'ASA*.N1'))[0]
    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)

    obj = createSensor('ENVISAT_SLC')
    obj._imageFileName = fname
    obj.orbitDir = '/Users/agram/orbit/VOR'
    obj.instrumentDir = '/Users/agram/orbit/INS_DIR'
    obj.output = os.path.join(slcname, date+'.slc')

    obj.extractImage()
    obj.frame.getImage().renderHdr()


    ######Numpy polynomial manipulation
    pc = obj._dopplerCoeffs[::-1]
    
    inds = np.linspace(0, obj.frame.numberOfSamples-1, len(pc) + 1)+1
    rng = obj.frame.getStartingRange() + inds * obj.frame.instrument.getRangePixelSize()
    dops = np.polyval(pc, 2*rng/Const.c-obj._dopplerTime)

    print('Near range doppler: ', dops[0])
    print('Far range doppler: ', dops[-1])
   
    dopfit = np.polyfit(inds, dops, len(pc)-1)
    
    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(pc)-1)
    poly.setCoeffs(dopfit[::-1])

    print('Poly near range doppler: ', poly(1))
    print('Poly far range doppler: ', poly(obj.frame.numberOfSamples))

#    width = obj.frame.getImage().getWidth()
#    midrange = r0 + 0.5 * width * dr
#    dt = datetime.timedelta(seconds = midrange / Const.c)

#    obj.frame.sensingStart = obj.frame.sensingStart - dt
#    obj.frame.sensingStop = obj.frame.sensingStop - dt
#    obj.frame.sensingMid = obj.frame.sensingMid - dt


    pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly 
    def extractDoppler(self):
        """
        Return the doppler centroid as defined in the HDF5 file.
        """
        quadratic = {}
        midtime = (self.rangeLastTime +
                   self.rangeFirstTime) * 0.5 - self.rangeRefTime

        fd_mid = 0.0
        x = 1.0
        for ind, coeff in enumerate(self.dopplerRangeTime):
            fd_mid += coeff * x
            x *= midtime

        ####insarApp style
        quadratic['a'] = fd_mid / self.frame.getInstrument(
        ).getPulseRepetitionFrequency()
        quadratic['b'] = 0.
        quadratic['c'] = 0.

        ###For roiApp more accurate
        ####Convert stuff to pixel wise coefficients
        from isceobj.Util import Poly1D

        coeffs = self.dopplerRangeTime
        dr = self.frame.getInstrument().getRangePixelSize()
        rref = 0.5 * Const.c * self.rangeRefTime
        r0 = self.frame.getStartingRange()
        norm = 0.5 * Const.c / dr

        dcoeffs = []
        for ind, val in enumerate(coeffs):
            dcoeffs.append(val / (norm**ind))

        poly = Poly1D.Poly1D()
        poly.initPoly(order=len(coeffs) - 1)
        poly.setMean((rref - r0) / dr - 1.0)
        poly.setCoeffs(dcoeffs)

        pix = np.linspace(0,
                          self.frame.getNumberOfSamples(),
                          num=len(coeffs) + 1)
        evals = poly(pix)
        fit = np.polyfit(pix, evals, len(coeffs) - 1)
        self.frame._dopplerVsPixel = list(fit[::-1])
        print('Doppler Fit: ', fit[::-1])

        return quadratic
def unpack(hdf5, slcname):
    '''
    Unpack HDF5 to binary SLC file.
    '''

    imgname = glob.glob(os.path.join(hdf5, 'DAT*'))[0]
    ldrname = glob.glob(os.path.join(hdf5, 'LEA*'))[0]
    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)
    obj = createSensor('ERS_SLC')
    obj.configure()
    obj._leaderFile = ldrname
    obj._imageFile = imgname
    obj._orbitType = 'ODR'
    obj._orbitDir = '/Users/agram/orbit/ODR/ERS2'
    obj.output = os.path.join(slcname, date + '.slc')

    print(obj._leaderFile)
    print(obj._imageFile)
    print(obj.output)
    obj.extractImage()
    obj.frame.getImage().renderHdr()

    coeffs = obj.doppler_coeff
    #    coeffs = [0.,0.]
    dr = obj.frame.getInstrument().getRangePixelSize()
    r0 = obj.frame.getStartingRange()

    print(coeffs)
    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(coeffs) - 1)
    poly.setCoeffs(coeffs)

    pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly
Exemple #10
0
def unpack(hdf5, slcname):
    '''
    Unpack HDF5 to binary SLC file.
    '''

    fname = glob.glob(os.path.join(hdf5, '*.h5'))[0]
    if not os.path.isdir(slcname):
        os.mkdir(slcname)

    date = os.path.basename(slcname)

    obj = createSensor('KOMPSAT5')
    obj.hdf5 = fname
    obj.output = os.path.join(slcname, date + '.slc')

    obj.extractImage()
    obj.frame.getImage().renderHdr()

    coeffs = obj.dopplerCoeffs
    dr = obj.frame.getInstrument().getRangePixelSize()
    rref = 0.5 * Const.c * obj.rangeRefTime
    r0 = obj.frame.getStartingRange()
    norm = 0.5 * Const.c / dr

    dcoeffs = []
    for ind, val in enumerate(coeffs):
        dcoeffs.append(val / (norm**ind))

    poly = Poly1D.Poly1D()
    poly.initPoly(order=len(coeffs) - 1)
    poly.setMean((rref - r0) / dr - 1.0)
    poly.setCoeffs(dcoeffs)

    pickName = os.path.join(slcname, 'data')
    with shelve.open(pickName) as db:
        db['frame'] = obj.frame
        db['doppler'] = poly
Exemple #11
0
    def populateBurstSpecificMetadata(self):
        '''
        Extract burst specific metadata from the xml file.
        '''

        burstList = self.getxmlelement('swathTiming/burstList')
        for index, burst in enumerate(burstList.getchildren()):
            bb = self.bursts[index]
            bb.sensingStart = self.convertToDateTime(
                burst.find('azimuthTime').text)
            deltaT = datetime.timedelta(seconds=(bb.numberOfLines - 1) *
                                        bb.azimuthTimeInterval)
            bb.sensingStop = bb.sensingStart + deltaT

            bb.sensingMid = bb.sensingStart + datetime.timedelta(
                seconds=0.5 * deltaT.total_seconds())

            bb.startUTC = self.convertToDateTime(
                burst.find('sensingTime').text)
            deltaT = datetime.timedelta(seconds=(bb.numberOfLines - 1) /
                                        bb.prf)
            bb.stopUTC = bb.startUTC + deltaT
            bb.midUTC = bb.startUTC + datetime.timedelta(
                seconds=0.5 * deltaT.total_seconds())

            firstValidSample = [
                int(val)
                for val in burst.find('firstValidSample').text.split()
            ]
            lastValidSample = [
                int(val) for val in burst.find('lastValidSample').text.split()
            ]

            first = False
            last = False
            count = 0
            for ii, val in enumerate(firstValidSample):
                if (val >= 0) and (not first):
                    first = True
                    bb.firstValidLine = ii

                if (val < 0) and (first) and (not last):
                    last = True
                    bb.numValidLines = ii - bb.firstValidLine

            lastLine = bb.firstValidLine + bb.numValidLines - 1

            bb.firstValidSample = max(firstValidSample[bb.firstValidLine],
                                      firstValidSample[lastLine])
            lastSample = min(lastValidSample[bb.firstValidLine],
                             lastValidSample[lastLine])

            bb.numValidSamples = lastSample - bb.firstValidSample

        ####Read in fm rates separately
        fmrateList = self.getxmlelement('generalAnnotation/azimuthFmRateList')
        fmRates = []
        for index, burst in enumerate(fmrateList.getchildren()):
            r0 = 0.5 * Const.c * float(burst.find('t0').text)
            try:
                c0 = float(burst.find('c0').text)
                c1 = float(burst.find('c1').text)
                c2 = float(burst.find('c2').text)
                coeffs = [c0, c1, c2]
            except AttributeError:
                coeffs = [
                    float(val) for val in burst.find(
                        'azimuthFmRatePolynomial').text.split()
                ]

            refTime = self.convertToDateTime(burst.find('azimuthTime').text)
            poly = Poly1D.Poly1D()
            poly.initPoly(order=len(coeffs) - 1)
            poly.setMean(r0)
            poly.setNorm(0.5 * Const.c)
            poly.setCoeffs(coeffs)

            fmRates.append((refTime, poly))

        for index, burst in enumerate(self.bursts):

            dd = [
                np.abs((burst.sensingMid - val[0]).total_seconds())
                for val in fmRates
            ]

            arg = np.argmin(dd)
            burst.azimuthFMRate = fmRates[arg][1]

#            print('FM rate matching: Burst %d to Poly %d'%(index, arg))

        dcList = self.getxmlelement('dopplerCentroid/dcEstimateList')
        dops = []
        for index, burst in enumerate(dcList.getchildren()):

            r0 = 0.5 * Const.c * float(burst.find('t0').text)
            refTime = self.convertToDateTime(burst.find('azimuthTime').text)
            coeffs = [
                float(val)
                for val in burst.find('dataDcPolynomial').text.split()
            ]
            poly = Poly1D.Poly1D()
            poly.initPoly(order=len(coeffs) - 1)
            poly.setMean(r0)
            poly.setNorm(0.5 * Const.c)
            poly.setCoeffs(coeffs)

            dops.append((refTime, poly))

        for index, burst in enumerate(self.bursts):

            dd = [
                np.abs((burst.sensingMid - val[0]).total_seconds())
                for val in dops
            ]

            arg = np.argmin(dd)
            burst.doppler = dops[arg][1]
    def extractDoppler(self):
        """
        Return the doppler centroid as defined in the HDF5 file.
        """
        import numpy as np

        quadratic = {}
        midtime = (self.rangeLastTime +
                   self.rangeFirstTime) * 0.5 - self.rangeRefTime

        fd_mid = 0.0
        x = 1.0
        for ind, coeff in enumerate(self.dopplerRangeTime):
            fd_mid += coeff * x
            x *= midtime

        ####insarApp style
        quadratic['a'] = fd_mid / self.frame.getInstrument(
        ).getPulseRepetitionFrequency()
        quadratic['b'] = 0.
        quadratic['c'] = 0.

        ####For roiApp more accurate
        ####Convert stuff to pixel wise coefficients
        from isceobj.Util import Poly1D

        coeffs = self.dopplerRangeTime
        dr = self.frame.getInstrument().getRangePixelSize()
        rref = 0.5 * Const.c * self.rangeRefTime
        r0 = self.frame.getStartingRange()
        norm = 0.5 * Const.c / dr

        dcoeffs = []
        for ind, val in enumerate(coeffs):
            dcoeffs.append(val / (norm**ind))

        poly = Poly1D.Poly1D()
        poly.initPoly(order=len(coeffs) - 1)
        poly.setMean((rref - r0) / dr - 1.0)
        poly.setCoeffs(dcoeffs)

        pix = np.linspace(0,
                          self.frame.getNumberOfSamples(),
                          num=len(coeffs) + 1)
        evals = poly(pix)
        fit = np.polyfit(pix, evals, len(coeffs) - 1)
        self.frame._dopplerVsPixel = list(fit[::-1])
        print('Doppler Fit: ', fit[::-1])

        #EMG - 20160420 This section was introduced in the populateMetadata method by EJF in r2022
        #Its pupose seems to be to set self.doppler_coeff and self.azfmrate_coeff, which don't seem
        #to be used anywhere in ISCE. Need to take time to understand the need for this and consult
        #with EJF.
        #
        ## save the Doppler centroid coefficients, converting units from .h5 file
        ## units in the file are quadratic coefficients in Hz, Hz/sec, and Hz/(sec^2)
        ## ISCE expects Hz, Hz/(range sample), Hz/(range sample)^2
        ## note that RS2 Doppler values are estimated at time dc.dopplerCentroidReferenceTime,
        ## so the values might need to be adjusted for ISCE usage
        ## adapted from RS2 version EJF 2015/09/05
        #        poly = self.frame._dopplerVsPixel
        #        rangeSamplingRate = self.frame.getInstrument().getPulseRepetitionFrequency()
        #        # need to convert units
        #        poly[1] = poly[1]/rangeSamplingRate
        #        poly[2] = poly[2]/rangeSamplingRate**2
        #        self.doppler_coeff = poly
        #
        ## similarly save Doppler azimuth fm rate values, converting units
        ## units in the file are quadratic coefficients in Hz, Hz/sec, and Hz/(sec^2)
        ## units are already converted below
        ## Guessing that ISCE expects Hz, Hz/(azimuth line), Hz/(azimuth line)^2
        ## note that RS2 Doppler values are estimated at time dc.dopplerRateReferenceTime,
        ## so the values might need to be adjusted for ISCE usage
        ## modified from RS2 version EJF 2015/09/05
        ## CSK Doppler azimuth FM rate not yet implemented in reading section, set to zero for now
        #
        #        fmpoly = self.dopplerRateCoeffs
        #        # don't need to convert units
        ##        fmpoly[1] = fmpoly[1]/rangeSamplingRate
        ##        fmpoly[2] = fmpoly[2]/rangeSamplingRate**2
        #        self.azfmrate_coeff = fmpoly
        #EMG - 20160420

        return quadratic