Exemplo n.º 1
0
def extract_tops_metadata(xml_file):
    """Read metadata from xml file for Sentinel-1/TOPS
    Parameters: xml_file : str, path of the .xml file, i.e. master/IW1.xml
    Returns:    meta     : dict, metadata
    """
    import isce
    from isceobj.Planet.Planet import Planet

    obj = load_product(xml_file)
    burst = obj.bursts[0]
    burstEnd = obj.bursts[-1]

    metadata = {}
    metadata['prf'] = burst.prf
    metadata['startUTC'] = burst.burstStartUTC
    metadata['stopUTC'] = burstEnd.burstStopUTC
    metadata['radarWavelength'] = burst.radarWavelength
    metadata['rangePixelSize'] = burst.rangePixelSize
    metadata['startingRange'] = burst.startingRange
    metadata['passDirection'] = burst.passDirection
    metadata['polarization'] = burst.polarization
    metadata['trackNumber'] = burst.trackNumber
    metadata['orbitNumber'] = burst.orbitNumber

    time_seconds = (burst.burstStartUTC.hour * 3600.0 +
                    burst.burstStartUTC.minute * 60.0 +
                    burst.burstStartUTC.second)
    metadata['CENTER_LINE_UTC'] = time_seconds

    orbit = burst.orbit
    peg = orbit.interpolateOrbit(burst.sensingMid, method='hermite')

    Vs = np.linalg.norm(peg.getVelocity())
    metadata['satelliteSpeed'] = Vs
    metadata['azimuthPixelSize'] = Vs*burst.azimuthTimeInterval

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(burst.sensingMid))
    metadata['earthRadius'] = refElp.pegRadCur
    metadata['altitude'] = llh[2]

    # for Sentinel-1
    metadata['beam_mode'] = 'IW'
    metadata['swathNumber'] = burst.swathNumber
    # 1. multipel subswaths
    xml_files = glob.glob(os.path.join(os.path.dirname(xml_file), 'IW*.xml'))
    if len(xml_files) > 1:
        swath_num = [load_product(fname).bursts[0].swathNumber for fname in xml_files]
        metadata['swathNumber'] = ''.join(str(i) for i in sorted(swath_num))

    # 2. calculate ASF frame number for Sentinel-1
    metadata['firstFrameNumber'] = int(0.2 * (burst.burstStartUTC - obj.ascendingNodeTime).total_seconds())
    metadata['lastFrameNumber'] = int(0.2 * (burstEnd.burstStopUTC - obj.ascendingNodeTime).total_seconds())
    return metadata
Exemplo n.º 2
0
def extract_stripmap_metadata(meta_file):
    """Read metadata from shelve file for StripMap stack from ISCE
    Parameters: meta_file : str, path of the shelve file, i.e. masterShelve/data.dat
    Returns:    meta      : dict, metadata
    """
    import isce
    import isceobj
    import isceobj.StripmapProc.StripmapProc as St
    from isceobj.Planet.Planet import Planet

    if os.path.basename(meta_file) == "data.dat":    #shelve file from stripmapStack
        fbase = os.path.splitext(meta_file)[0]
        with shelve.open(fbase, flag='r') as mdb:
            frame = mdb['frame']

    elif meta_file.endswith(".xml"):   #XML file from stripmapApp
        frame = load_product(meta_file)

    metadata = {}
    metadata['prf'] = frame.PRF
    metadata['startUTC'] = frame.sensingStart
    metadata['stopUTC'] = frame.sensingStop
    metadata['radarWavelength'] = frame.radarWavelegth
    metadata['rangePixelSize'] = frame.instrument.rangePixelSize
    metadata['startingRange'] = frame.startingRange
    metadata['polarization'] = frame.polarization.replace('/', '')
    if metadata['polarization'].startswith("b'"):
        metadata['polarization'] = metadata['polarization'][2:4]
    metadata['trackNumber'] = frame.trackNumber
    metadata['orbitNumber'] = frame.orbitNumber

    time_seconds = (frame.sensingStart.hour*3600.0 + 
                    frame.sensingStart.minute*60.0 + 
                    frame.sensingStart.second)
    metadata['CENTER_LINE_UTC'] = time_seconds

    orbit = frame.orbit
    peg = orbit.interpolateOrbit(frame.sensingMid, method='hermite')

    Vs = np.linalg.norm(peg.getVelocity())
    metadata['satelliteSpeed'] = Vs
    metadata['azimuthPixelSize'] = Vs/frame.PRF

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(frame.sensingMid))
    metadata['earthRadius'] = refElp.pegRadCur
    metadata['altitude'] = llh[2]

    # for StripMap
    metadata['beam_mode'] = 'SM'
    return metadata
Exemplo n.º 3
0
def extract_tops_metadata(xml_file):
    """Read metadata from xml file for Sentinel-1/TOPS
    Parameters: xml_file : str, path of the .xml file, i.e. master/IW1.xml
    Returns:    meta     : dict, metadata
    """
    import isce
    import isceobj
    from isceobj.Planet.Planet import Planet

    obj = load_product(xml_file)
    burst = obj.bursts[0]
    burstEnd = obj.bursts[-1]

    metadata = {}
    metadata['prf'] = burst.prf
    metadata['startUTC'] = burst.burstStartUTC
    metadata['stopUTC'] = burstEnd.burstStopUTC
    metadata['radarWavelength'] = burst.radarWavelength
    metadata['startingRange'] = burst.startingRange
    metadata['passDirection'] = burst.passDirection
    metadata['polarization'] = burst.polarization
    metadata['trackNumber'] = burst.trackNumber
    metadata['orbitNumber'] = burst.orbitNumber

    time_seconds = (burst.burstStartUTC.hour * 3600.0 +
                    burst.burstStartUTC.minute * 60.0 +
                    burst.burstStartUTC.second)
    metadata['CENTER_LINE_UTC'] = time_seconds

    orbit = burst.orbit
    peg = orbit.interpolateOrbit(burst.sensingMid, method='hermite')

    # Sentinel-1 TOPS pixel spacing
    Vs = np.linalg.norm(peg.getVelocity())  #satellite speed
    metadata['azimuthPixelSize'] = Vs * burst.azimuthTimeInterval
    metadata['rangePixelSize'] = burst.rangePixelSize

    # Sentinel-1 TOPS spatial resolution
    iw_str = 'IW2'
    if os.path.basename(xml_file).startswith('IW'):
        iw_str = os.path.splitext(os.path.basename(xml_file))[0]
    metadata['azimuthResolution'] = S1_TOPS_RESOLUTION[iw_str][
        'azimuthResolution']
    metadata['rangeResolution'] = S1_TOPS_RESOLUTION[iw_str]['rangeResolution']

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(burst.sensingMid))
    metadata['earthRadius'] = refElp.pegRadCur
    metadata['altitude'] = llh[2]

    # for Sentinel-1
    metadata['beam_mode'] = 'IW'
    metadata['swathNumber'] = burst.swathNumber
    # 1. multipel subswaths
    xml_files = glob.glob(os.path.join(os.path.dirname(xml_file), 'IW*.xml'))
    if len(xml_files) > 1:
        swath_num = [
            load_product(fname).bursts[0].swathNumber for fname in xml_files
        ]
        metadata['swathNumber'] = ''.join(str(i) for i in sorted(swath_num))

    # 2. calculate ASF frame number for Sentinel-1
    metadata['firstFrameNumber'] = int(
        0.2 * (burst.burstStartUTC - obj.ascendingNodeTime).total_seconds())
    metadata['lastFrameNumber'] = int(
        0.2 * (burstEnd.burstStopUTC - obj.ascendingNodeTime).total_seconds())
    return metadata, burst
Exemplo n.º 4
0
    def rdr2geo(self, aztime, rng, height=0.,
            doppler = None, wvl = None,
            planet=None, side=-1):
        '''
        Returns point on ground at given height and doppler frequency.
        Never to be used for heavy duty computing.
        '''

        from isceobj.Planet.Planet import Planet

        ####Setup doppler for the equations
        dopfact = 0.0

        hdg = self.getENUHeading(time=aztime)

        sv = self.interpolateOrbit(aztime, method='hermite')
        pos = sv.getPosition()
        vel = sv.getVelocity()
        vmag = np.linalg.norm(vel)

        if doppler is not None:
            dopfact = doppler(DTU.seconds_since_midnight(aztime), rng) * 0.5 * wvl * rng/vmag

        if planet is None:
            refElp = Planet(pname='Earth').ellipsoid
        else:
            refElp = planet.ellipsoid

        ###Convert position and velocity to local tangent plane
        satLLH = refElp.xyz_to_llh(pos)

        refElp.setSCH(satLLH[0], satLLH[1], hdg)
        radius = refElp.pegRadCur

        #####Setup ortho normal system right below satellite
        satVec = np.array(pos)
        velVec = np.array(vel)

        ###Setup TCN basis
        clat = np.cos(np.radians(satLLH[0]))
        slat = np.sin(np.radians(satLLH[0]))
        clon = np.cos(np.radians(satLLH[1]))
        slon = np.sin(np.radians(satLLH[1]))
        nhat = np.array([-clat*clon, -clat*slon, -slat])
        temp = np.cross(nhat, velVec)
        chat = temp / np.linalg.norm(temp)
        temp = np.cross(chat, nhat)
        that = temp / np.linalg.norm(temp)
        vhat = velVec / np.linalg.norm(velVec)

        ####Solve the range doppler eqns iteratively
        ####Initial guess
        zsch = height

        for ii in range(10):

            ###Near nadir tests
            if (satLLH[2]-zsch) >= rng:
                return None 

            a = (satLLH[2] + radius)
            b = (radius + zsch)

            costheta = 0.5*(a/rng + rng/a - (b/a)*(b/rng))
            sintheta = np.sqrt(1-costheta*costheta)

            gamma = rng*costheta
            alpha = dopfact - gamma*np.dot(nhat,vhat)/np.dot(vhat,that)
            beta = -side*np.sqrt(rng*rng*sintheta*sintheta - alpha*alpha)

            delta = alpha * that + beta * chat + gamma * nhat

            targVec = satVec + delta

            targLLH = refElp.xyz_to_llh(list(targVec))
            targXYZ = refElp.llh_to_xyz([targLLH[0], targLLH[1], height])
            targSCH = refElp.xyz_to_sch(targXYZ)

            zsch = targSCH[2]

            rdiff  = rng - np.linalg.norm(np.array(satVec) - np.array(targXYZ))

        return targLLH
Exemplo n.º 5
0
def runUnwrap(self,costMode = None,initMethod = None, defomax = None, initOnly = None):

    if costMode is None:
        costMode   = 'DEFO'
    
    if initMethod is None:
        initMethod = 'MST'
    
    if  defomax is None:
        defomax = 4.0
    
    if initOnly is None:
        initOnly = False
    

    wrapName = os.path.join( self._insar.mergedDirname, self._insar.filtFilename)
    unwrapName = os.path.join( self._insar.mergedDirname, self._insar.unwrappedIntFilename)

    img = isceobj.createImage()
    img.load(wrapName + '.xml')


    swathList = self._insar.getValidSwathList(self.swaths)

    for swath in swathList[0:1]:
        ifg = self._insar.loadProduct( os.path.join(self._insar.fineIfgDirname, 'IW{0}.xml'.format(swath)))


        wavelength = ifg.bursts[0].radarWavelength
        width      = img.getWidth()


        ####tmid 
        tstart = ifg.bursts[0].sensingStart
        tend   = ifg.bursts[-1].sensingStop
        tmid = tstart + 0.5*(tend - tstart) 

        orbit = ifg.bursts[0].orbit
        peg = orbit.interpolateOrbit(tmid, method='hermite')


        refElp = Planet(pname='Earth').ellipsoid
        llh = refElp.xyz_to_llh(peg.getPosition())
        hdg = orbit.getENUHeading(tmid)
        refElp.setSCH(llh[0], llh[1], hdg)

        earthRadius = refElp.pegRadCur

        altitude   = llh[2]

    corrfile  = os.path.join(self._insar.mergedDirname, self._insar.coherenceFilename)
    rangeLooks = self.numberRangeLooks
    azimuthLooks = self.numberAzimuthLooks

    azfact = 0.8
    rngfact = 0.8

    corrLooks = rangeLooks * azimuthLooks/(azfact*rngfact) 
    maxComponents = 20

    snp = Snaphu()
    snp.setInitOnly(initOnly)
    snp.setInput(wrapName)
    snp.setOutput(unwrapName)
    snp.setWidth(width)
    snp.setCostMode(costMode)
    snp.setEarthRadius(earthRadius)
    snp.setWavelength(wavelength)
    snp.setAltitude(altitude)
    snp.setCorrfile(corrfile)
    snp.setInitMethod(initMethod)
    snp.setCorrLooks(corrLooks)
    snp.setMaxComponents(maxComponents)
    snp.setDefoMaxCycles(defomax)
    snp.setRangeLooks(rangeLooks)
    snp.setAzimuthLooks(azimuthLooks)
    snp.setCorFileFormat('FLOAT_DATA')
    snp.prepare()
    snp.unwrap()

    ######Render XML
    outImage = isceobj.Image.createUnwImage()
    outImage.setFilename(unwrapName)
    outImage.setWidth(width)
    outImage.setAccessMode('read')
    outImage.renderVRT()
    outImage.createImage()
    outImage.finalizeImage()
    outImage.renderHdr()

    #####Check if connected components was created
    if snp.dumpConnectedComponents:
        connImage = isceobj.Image.createImage()
        connImage.setFilename(unwrapName+'.conncomp')
        #At least one can query for the name used
        self._insar.connectedComponentsFilename = unwrapName+'.conncomp'
        connImage.setWidth(width)
        connImage.setAccessMode('read')
        connImage.setDataType('BYTE')
        connImage.renderVRT()
        connImage.createImage()
        connImage.finalizeImage()
        connImage.renderHdr()

    return
Exemplo n.º 6
0
def extract_stripmap_metadata(meta_file):
    """Read metadata from shelve file for StripMap stack from ISCE
    Parameters: meta_file : str, path of the shelve file, i.e. masterShelve/data.dat
    Returns:    meta      : dict, metadata
    """
    SPEED_OF_LIGHT = 299792458  #m/s
    import isce
    import isceobj
    from isceobj.Planet.Planet import Planet

    if os.path.basename(
            meta_file) == "data.dat":  #shelve file from stripmapStack
        fbase = os.path.splitext(meta_file)[0]
        with shelve.open(fbase, flag='r') as mdb:
            frame = mdb['frame']

    elif meta_file.endswith(".xml"):  #XML file from stripmapApp
        frame = load_product(meta_file)

    else:
        raise ValueError(
            'un-recognized isce/stripmap metadata file: {}'.format(meta_file))

    metadata = {}
    metadata['prf'] = frame.PRF
    metadata['startUTC'] = frame.sensingStart
    metadata['stopUTC'] = frame.sensingStop
    metadata['radarWavelength'] = frame.radarWavelegth
    metadata['startingRange'] = frame.startingRange
    metadata['polarization'] = str(frame.polarization).replace('/', '')
    if metadata['polarization'].startswith("b'"):
        metadata['polarization'] = metadata['polarization'][2:4]
    metadata['trackNumber'] = frame.trackNumber
    metadata['orbitNumber'] = frame.orbitNumber

    time_seconds = (frame.sensingStart.hour * 3600.0 +
                    frame.sensingStart.minute * 60.0 +
                    frame.sensingStart.second)
    metadata['CENTER_LINE_UTC'] = time_seconds

    orbit = frame.orbit
    peg = orbit.interpolateOrbit(frame.sensingMid, method='hermite')

    Vs = np.linalg.norm(peg.getVelocity())  #satellite speed
    metadata['azimuthResolution'] = frame.platform.antennaLength / 2.0
    metadata['azimuthPixelSize'] = Vs / frame.PRF

    frame.getInstrument()
    rgBandwidth = frame.instrument.pulseLength * frame.instrument.chirpSlope
    metadata['rangeResolution'] = abs(SPEED_OF_LIGHT / (2.0 * rgBandwidth))
    metadata['rangePixelSize'] = frame.instrument.rangePixelSize

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    refElp.setSCH(llh[0], llh[1], orbit.getENUHeading(frame.sensingMid))
    metadata['earthRadius'] = refElp.pegRadCur
    metadata['altitude'] = llh[2]

    # for StripMap
    metadata['beam_mode'] = 'SM'
    return metadata, frame
Exemplo n.º 7
0
def extractInfo(xmlName, inps):
    '''
    Extract required information from pickle file.
    '''
    from isceobj.Planet.Planet import Planet
    from isceobj.Util.geo.ellipsoid import Ellipsoid

    # with open(pckfile, 'rb') as f:
    #    frame = pickle.load(f)

    #with shelve.open(pckfile,flag='r') as db:
    #    frame = db['swath']

    frame = ut.loadProduct(xmlName)

    burst = frame.bursts[0]
    planet = Planet(pname='Earth')
    elp = Ellipsoid(planet.ellipsoid.a, planet.ellipsoid.e2, 'WGS84')

    data = {}
    data['wavelength'] = burst.radarWavelength

    tstart = frame.bursts[0].sensingStart
    tend = frame.bursts[-1].sensingStop
    #tmid = tstart + 0.5*(tend - tstart)
    tmid = tstart

    orbit = burst.orbit
    peg = orbit.interpolateOrbit(tmid, method='hermite')

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    hdg = orbit.getENUHeading(tmid)
    refElp.setSCH(llh[0], llh[1], hdg)

    earthRadius = refElp.pegRadCur

    altitude = llh[2]

    #sv = burst.orbit.interpolateOrbit(tmid, method='hermite')
    #pos = sv.getPosition()
    #llh = elp.ECEF(pos[0], pos[1], pos[2]).llh()

    data['altitude'] = altitude  #llh.hgt

    #hdg = burst.orbit.getHeading()
    data[
        'earthRadius'] = earthRadius  #elp.local_radius_of_curvature(llh.lat, hdg)

    #azspacing  = burst.azimuthTimeInterval * sv.getScalarVelocity()
    #azres = 20.0

    #corrfile  = os.path.join(self._insar.mergedDirname, self._insar.coherenceFilename)
    rangeLooks = inps.rglooks
    azimuthLooks = inps.azlooks
    azfact = 0.8
    rngfact = 0.8

    corrLooks = rangeLooks * azimuthLooks / (azfact * rngfact)

    data[
        'corrlooks'] = corrLooks  #inps.rglooks * inps.azlooks * azspacing / azres
    data['rglooks'] = inps.rglooks
    data['azlooks'] = inps.azlooks

    return data
Exemplo n.º 8
0
def extract_isce_metadata(xmlFile, rscFile=None):
    import isce
    from isceobj.Planet.Planet import Planet

    print('extract metadata from xml file:', xmlFile)
    metadata = {}

    master = load_product(xmlFile)
    metadata['spacecraftName'] = master.spacecraftName

    burst = master.bursts[0]
    burstEnd = master.bursts[-1]
    metadata['radarWavelength'] = burst.radarWavelength
    metadata['rangePixelSize'] = burst.rangePixelSize
    metadata['prf'] = burst.prf
    metadata['startUTC'] = burst.burstStartUTC
    metadata['stopUTC'] = burstEnd.burstStopUTC
    metadata['startingRange'] = burst.startingRange
    metadata['passDirection'] = burst.passDirection
    metadata['polarization'] = burst.polarization
    metadata['trackNumber'] = burst.trackNumber
    metadata['orbitNumber'] = burst.orbitNumber

    metadata['swathNumber'] = burst.swathNumber
    # swathNumber for multipel subswaths
    xml_files = glob.glob(os.path.join(os.path.dirname(xmlFile), 'IW*.xml'))
    if len(xml_files) > 1:
        swath_num = []
        for xml_file in xml_files:
            swath_num.append(load_product(xml_file).bursts[0].swathNumber)
        metadata['swathNumber'] = ''.join(str(i) for i in sorted(swath_num))

    # calculate ASF frame number for Sentinel-1
    metadata['firstFrameNumber'] = int(
        np.floor(
            0.2 *
            (burst.burstStartUTC - master.ascendingNodeTime).total_seconds()))
    metadata['lastFrameNumber'] = int(
        np.floor(0.2 * (burstEnd.burstStopUTC -
                        master.ascendingNodeTime).total_seconds()))

    time_seconds = (burst.burstStartUTC.hour * 3600.0 +
                    burst.burstStartUTC.minute * 60.0 +
                    burst.burstStartUTC.second)
    metadata['CENTER_LINE_UTC'] = time_seconds

    Vs = np.linalg.norm(
        burst.orbit.interpolateOrbit(burst.sensingMid,
                                     method='hermite').getVelocity())
    metadata['satelliteSpeed'] = Vs
    metadata['azimuthTimeInterval'] = burst.azimuthTimeInterval
    metadata['azimuthPixelSize'] = Vs * burst.azimuthTimeInterval

    tstart = burst.sensingStart
    tend = burstEnd.sensingStop
    tmid = tstart + 0.5 * (tend - tstart)

    orbit = burst.orbit
    peg = orbit.interpolateOrbit(tmid, method='hermite')

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    hdg = orbit.getENUHeading(tmid)
    refElp.setSCH(llh[0], llh[1], hdg)

    metadata['earthRadius'] = refElp.pegRadCur
    metadata['altitude'] = llh[2]

    # make all value in string format
    for key, value in metadata.items():
        metadata[key] = str(value)

    metadata = readfile.standardize_metadata_isce(metadata)
    if rscFile:
        print('writing ', rscFile)
        writefile.write_roipac_rsc(metadata, rscFile)
    return metadata
Exemplo n.º 9
0
    def rdr2geoNew(self,
                   aztime,
                   rng,
                   height=0.,
                   doppler=None,
                   wvl=None,
                   planet=None,
                   side=-1):
        '''
        Returns point on ground at given height and doppler frequency.
        Never to be used for heavy duty computing.
        '''

        from isceobj.Planet.Planet import Planet

        ####Setup doppler for the equations
        dopfact = 0.

        sv = self.interpolateOrbit(aztime, method='hermite')
        pos = np.array(sv.getPosition())
        vel = np.array(sv.getVelocity())
        vmag = np.linalg.norm(vel)

        if doppler is not None:
            dopfact = doppler(DTU.seconds_since_midnight(aztime),
                              rng) * 0.5 * wvl * rng / vmag

        if planet is None:
            refElp = Planet(pname='Earth').ellipsoid
        else:
            refElp = planet.ellipsoid

        ###Convert position and velocity to local tangent plane
        major = refElp.a
        minor = major * np.sqrt(1 - refElp.e2)

        #####Setup ortho normal system right below satellite
        satDist = np.linalg.norm(pos)
        alpha = 1 / np.linalg.norm(pos / np.array([major, major, minor]))
        radius = alpha * satDist
        hgt = (1.0 - alpha) * satDist

        ###Setup TCN basis - Geocentric
        nhat = -pos / satDist
        temp = np.cross(nhat, vel)
        chat = temp / np.linalg.norm(temp)
        temp = np.cross(chat, nhat)
        that = temp / np.linalg.norm(temp)
        vhat = vel / vmag

        ####Solve the range doppler eqns iteratively
        ####Initial guess
        zsch = height

        for ii in range(10):

            ###Near nadir tests
            if (hgt - zsch) >= rng:
                return None

            a = satDist
            b = (radius + zsch)

            costheta = 0.5 * (a / rng + rng / a - (b / a) * (b / rng))
            sintheta = np.sqrt(1 - costheta * costheta)

            gamma = rng * costheta
            alpha = dopfact - gamma * np.dot(nhat, vhat) / np.dot(vhat, that)
            beta = -side * np.sqrt(rng * rng * sintheta * sintheta -
                                   alpha * alpha)

            delta = alpha * that + beta * chat + gamma * nhat

            targVec = pos + delta

            targLLH = refElp.xyz_to_llh(list(targVec))
            targXYZ = np.array(
                refElp.llh_to_xyz([targLLH[0], targLLH[1], height]))

            zsch = np.linalg.norm(targXYZ) - radius

            rdiff = rng - np.linalg.norm(pos - targXYZ)

        return targLLH
Exemplo n.º 10
0
def runUnwrap(inps,
              costMode=None,
              initMethod=None,
              defomax=None,
              initOnly=None):

    if costMode is None:
        costMode = 'DEFO'

    if initMethod is None:
        initMethod = 'MST'

    if defomax is None:
        defomax = 4.0

    if initOnly is None:
        initOnly = False

    #get earth radius and altitude using master's orbit
    with open(inps.mframe, 'rb') as f:
        mframe = pickle.load(f)

    azti = 1.0 / mframe.PRF
    tmid = mframe.getSensingStart() + datetime.timedelta(
        seconds=azti * (mframe.getNumberOfLines() / 2.0))
    orbit = mframe.getOrbit()
    peg = orbit.interpolateOrbit(tmid, method='hermite')

    refElp = Planet(pname='Earth').ellipsoid
    llh = refElp.xyz_to_llh(peg.getPosition())
    hdg = orbit.getHeading(tmid)
    #change to the following after updated to the newest version of isce
    #hdg = orbit.getENUHeading(tmid)
    refElp.setSCH(llh[0], llh[1], hdg)
    earthRadius = refElp.pegRadCur
    altitude = llh[2]

    wrapName = inps.inf
    unwrapName = inps.unw
    corrfile = inps.cor

    width = getWidth(wrapName + '.xml')
    wavelength = mframe.getInstrument().getRadarWavelength()
    rangeLooks = inps.rlks
    azimuthLooks = inps.alks

    #calculate azimuth resolution and pixel size
    azres = mframe.platform.antennaLength / 2.0
    vel = np.sqrt(peg.velocity[0] * peg.velocity[0] +
                  peg.velocity[1] * peg.velocity[1] +
                  peg.velocity[2] * peg.velocity[2])
    hgt = np.sqrt(peg.position[0] * peg.position[0] +
                  peg.position[1] * peg.position[1] +
                  peg.position[2] * peg.position[2])
    azimuthPixelSpacing = earthRadius / hgt * vel * azti
    azfact = azres / azimuthPixelSpacing

    #calculate range resolution and pixel size
    rBW = mframe.instrument.pulseLength * mframe.instrument.chirpSlope
    rgres = abs(SPEED_OF_LIGHT / (2.0 * rBW))
    slantRangePixelSpacing = 0.5 * SPEED_OF_LIGHT / mframe.rangeSamplingRate
    rngfact = rgres / slantRangePixelSpacing

    print('azfact: {}, rngfact: {}'.format(azfact, rngfact))
    corrLooks = azimuthLooks * rangeLooks / (azfact * rngfact)

    maxComponents = 20

    snp = Snaphu()
    snp.setInitOnly(initOnly)  # follow
    snp.setInput(wrapName)
    snp.setOutput(unwrapName)
    snp.setWidth(width)
    snp.setCostMode(costMode)  # follow
    snp.setEarthRadius(earthRadius)
    snp.setWavelength(wavelength)
    snp.setAltitude(altitude)
    snp.setCorrfile(corrfile)
    snp.setInitMethod(initMethod)  # follow
    snp.setCorrLooks(corrLooks)
    snp.setMaxComponents(maxComponents)
    snp.setDefoMaxCycles(defomax)  # follow
    snp.setRangeLooks(rangeLooks)
    snp.setAzimuthLooks(azimuthLooks)
    #snp.setCorFileFormat('FLOAT_DATA')
    snp.prepare()
    snp.unwrap()

    ######Render XML
    outImage = isceobj.Image.createUnwImage()
    outImage.setFilename(unwrapName)
    outImage.setWidth(width)
    outImage.setAccessMode('read')
    outImage.renderVRT()
    outImage.createImage()
    outImage.finalizeImage()
    outImage.renderHdr()

    #####Check if connected components was created
    if snp.dumpConnectedComponents:
        connImage = isceobj.Image.createImage()
        connImage.setFilename(unwrapName + '.conncomp')
        #At least one can query for the name used
        #self._insar.connectedComponentsFilename = unwrapName+'.conncomp'
        connImage.setWidth(width)
        connImage.setAccessMode('read')
        connImage.setDataType('BYTE')
        connImage.renderVRT()
        connImage.createImage()
        connImage.finalizeImage()
        connImage.renderHdr()

    return
Exemplo n.º 11
0
    def numberOfLooks(self, frame, posting, azlooks, rglooks):
        '''
        Compute relevant number of looks.
        '''
        from isceobj.Planet.Planet import Planet
        from isceobj.Constants import SPEED_OF_LIGHT
        import numpy as np

        azFinal = None
        rgFinal = None

        if azlooks is not None:
            azFinal = azlooks

        if rglooks is not None:
            rgFinal = rglooks

        if (azFinal is not None) and (rgFinal is not None):
            return (azFinal, rgFinal)

        if posting is None:
            raise Exception(
                'Input posting is none. Either specify (azlooks, rglooks) or posting in input file'
            )

        elp = Planet(pname='Earth').ellipsoid

        ####First determine azimuth looks
        tmid = frame.sensingMid
        sv = frame.orbit.interpolateOrbit(tmid,
                                          method='hermite')  #.getPosition()
        llh = elp.xyz_to_llh(sv.getPosition())

        if azFinal is None:
            hdg = frame.orbit.getENUHeading(tmid)
            elp.setSCH(llh[0], llh[1], hdg)
            sch, vsch = elp.xyzdot_to_schdot(sv.getPosition(),
                                             sv.getVelocity())
            azFinal = max(int(np.round(posting * frame.PRF / vsch[0])), 1)

        if rgFinal is None:
            pulseLength = frame.instrument.pulseLength
            chirpSlope = frame.instrument.chirpSlope

            #Range Bandwidth
            rBW = np.abs(chirpSlope) * pulseLength

            # Slant Range resolution
            rgres = abs(SPEED_OF_LIGHT / (2.0 * rBW))

            r0 = frame.startingRange
            rmax = frame.getFarRange()
            rng = (r0 + rmax) / 2

            Re = elp.pegRadCur
            H = sch[2]
            cos_beta_e = (Re**2 + (Re + H)**2 - rng**2) / (2 * Re * (Re + H))
            sin_bet_e = np.sqrt(1 - cos_beta_e**2)
            sin_theta_i = sin_bet_e * (Re + H) / rng
            print("incidence angle at the middle of the swath: ",
                  np.arcsin(sin_theta_i) * 180.0 / np.pi)
            groundRangeRes = rgres / sin_theta_i
            print("Ground range resolution at the middle of the swath: ",
                  groundRangeRes)
            rgFinal = max(int(np.round(posting / groundRangeRes)), 1)

        return azFinal, rgFinal