Ejemplo n.º 1
0
 def normalize_comp_name(self, comp_name):
     """
     normalize_comp_name removes extra white spaces and
     capitalizes first letter of each word
     """
     from isceobj.Util.StringUtils import StringUtils
     return StringUtils.capitalize_single_spaced(comp_name)
Ejemplo n.º 2
0
 def normalize_prop_name(self, prop_name):
     """
     normalize_prop_name removes extra white spaces and
     converts words to lower case
     """
     from isceobj.Util.StringUtils import StringUtils
     return StringUtils.lower_single_spaced(prop_name)
Ejemplo n.º 3
0
 def renormalizeKey(s):
     """
     staticmethod renormalizeKey(s):
     Apply renormalization to a dictionary key,
     i.e., transform key to a standard format,
     by removing all white space and canverting
     to lower case.
     """
     from isceobj.Util.StringUtils import StringUtils
     return StringUtils.lower_no_spaces(s)
Ejemplo n.º 4
0
def runGeocode(self, prodlist, unwrapflag, bbox):
    '''Generalized geocoding of all the files listed above (in prodlist).'''
    if isinstance(prodlist, str):
        from isceobj.Util.StringUtils import StringUtils as SU
        tobeGeocoded = SU.listify(prodlist)
    else:
        tobeGeocoded = prodlist

    #####Remove the unwrapped interferogram if no unwrapping is done
    if not unwrapflag:
        try:
            tobeGeocoded.remove(self._isce.unwrappedIntFilename)
        except ValueError:
            pass

    print('Number of products to geocode: ', len(tobeGeocoded))

    stdWriter = create_writer("log", "", True, filename="geo.log")

    velocity, height = self._isce.vh()

    if bbox is not None:
        snwe = list(bbox)
        if len(snwe) != 4:
            raise valueError('Bounding box should be a list/tuple of length 4')
    else:
        snwe = self._isce.topo.snwe

    infos = {}
    for attribute in [
            'demCropFilename', 'numberRangeLooks', 'numberAzimuthLooks',
            'is_mocomp', 'demImage', 'peg', 'dopplerCentroid'
    ]:
        infos[attribute] = getattr(self._isce, attribute)

    for sceneid1, sceneid2 in self._isce.selectedPairs:
        pair = (sceneid1, sceneid2)
        for pol in self._isce.selectedPols:
            frame1 = self._isce.frames[sceneid1][pol]
            formSLC1 = self._isce.formSLCs[sceneid1][pol]
            sid = self._isce.formatname(pair, pol)
            infos['outputPath'] = os.path.join(
                self.getoutputdir(sceneid1, sceneid2), sid)
            catalog = isceobj.Catalog.createCatalog(self._isce.procDoc.name)
            run(tobeGeocoded,
                frame1,
                formSLC1,
                velocity,
                height,
                snwe,
                infos,
                catalog=catalog,
                sceneid=sid)
            self._isce.procDoc.addAllFromCatalog(catalog)
Ejemplo n.º 5
0
def runGeocode(self, prodlist, bbox, is_offset_mode=False):
    '''Generalized geocoding of all the files listed above.'''
    from isceobj.Catalog import recordInputsAndOutputs
    logger.info("Geocoding Image")
    insar = self._insar

    if (not self.doDenseOffsets) and (is_offset_mode):
        print('Skipping geocoding as Dense Offsets has not been requested ....')
        return


    if isinstance(prodlist,str):
        from isceobj.Util.StringUtils import StringUtils as SU
        tobeGeocoded = SU.listify(prodlist)
    else:
        tobeGeocoded = prodlist

    
    #remove files that have not been processed
    newlist=[]
    for toGeo in tobeGeocoded:
        if os.path.exists(toGeo):
            newlist.append(toGeo)

    
    tobeGeocoded = newlist
    print('Number of products to geocode: ', len(tobeGeocoded))

    if len(tobeGeocoded) == 0:
        print('No products found to geocode')
        return


    ###Read in the product
    burst = self._insar.loadProduct( self._insar.masterSlcCropProduct)

    ####Get required values from product
    t0 = burst.sensingStart
    prf = burst.PRF
    r0 = burst.startingRange
    dr = 0.5* SPEED_OF_LIGHT/ burst.rangeSamplingRate
    wvl = burst.radarWavelegth
    side= burst.getInstrument().getPlatform().pointingDirection
    orb = burst.orbit
    planet = Planet(pname='Earth')
     
    if (bbox is None):
        snwe = self._insar.estimatedBbox
    else:
        snwe = bbox
        if len(snwe) != 4 :
            raise Exception('Bbox must be 4 floats in SNWE order.')

    if is_offset_mode:  ### If using topsOffsetApp, image has been "pre-looked" by the
        numberRangeLooks = self.denseSkipWidth    ### skips in runDenseOffsets
        numberAzimuthLooks = self.denseSkipHeight
        rangeFirstSample = r0 + (self._insar.offset_left-1) * dr
        sensingStart =  t0 + datetime.timedelta(seconds=((self._insar.offset_top-1)/prf))
    else:
        ###Resolve number of looks
        azLooks, rgLooks = self.insar.numberOfLooks(burst, self.posting, self.numberAzimuthLooks, self.numberRangeLooks)

        numberRangeLooks = rgLooks
        numberAzimuthLooks = azLooks
        rangeFirstSample = r0 + ((numberRangeLooks-1)/2.0) * dr
        sensingStart = t0 + datetime.timedelta(seconds=(((numberAzimuthLooks-1)/2.0)/prf))


    ###Ughhh!! Doppler handling
    if self._insar.masterGeometrySystem.lower().startswith('native'):
        ###Need to fit polynomials
        ###Geozero fortran assumes that starting range for radar image and polynomial are same
        ###Also assumes that the polynomial spacing is original spacing at full looks
        ###This is not true for multilooked data. Need to fix this with good datastruct in ISCEv3
        ###Alternate method is to modify the mean and norm of a Poly1D structure such that the 
        ###translation is accounted for correctly.
        poly = burst._dopplerVsPixel

        if len(poly) != 1:
            slcPix = np.linspace(0., burst.numberOfSamples, len(poly)+1)
            dopplers = np.polyval(poly[::-1], slcPix)

            newPix = slcPix - (rangeFirstSample - r0)/dr
            nppoly = np.polyfit(newPix, dopplers, len(poly)-1)

            dopplercoeff = list(nppoly[::-1])
        else:
            dopplercoeff = poly

    else:
        dopplercoeff = [0.]

    ##Scale by PRF since the module needs it
    dopplercoeff = [x/prf for x in dopplercoeff]

    ###Setup DEM
    demfilename = self.verifyDEM()
    demImage = isceobj.createDemImage()
    demImage.load(demfilename + '.xml')

    ###Catalog for tracking
    catalog = isceobj.Catalog.createCatalog(insar.procDoc.name)
    catalog.addItem('Dem Used', demfilename, 'geocode')

    #####Geocode one by one
    first = False
    ge = Geocodable()
    for prod in tobeGeocoded:
        objGeo = createGeozero()
        objGeo.configure()

        ####IF statements to check for user configuration
        objGeo.snwe = snwe
        objGeo.demCropFilename = insar.demCropFilename


        objGeo.dopplerCentroidCoeffs = dopplercoeff
        objGeo.lookSide = side

        #create the instance of the input image and the appropriate
        #geocode method
        inImage,method = ge.create(prod)
        objGeo.method = method

        objGeo.slantRangePixelSpacing = dr
        objGeo.prf = prf
        objGeo.orbit = orb 
        objGeo.width = inImage.getWidth()
        objGeo.length = inImage.getLength()
        objGeo.dopplerCentroidCoeffs = dopplercoeff
        objGeo.radarWavelength = wvl
        objGeo.rangeFirstSample = rangeFirstSample
        objGeo.setSensingStart(sensingStart)
        objGeo.numberRangeLooks = numberRangeLooks
        objGeo.numberAzimuthLooks = numberAzimuthLooks


        objGeo.wireInputPort(name='dem', object=demImage)
        objGeo.wireInputPort(name='planet', object=planet)
        objGeo.wireInputPort(name='tobegeocoded', object=inImage)

        objGeo.geocode()
        # NEW COMMANDS added by YL --start
        catalog.addItem('Geocoding', inImage.filename, 'geocode')
        catalog.addItem('Output file', inImage.filename + '.geo', 'geocode')
        # NEW COMMANDS added by YL --end
        catalog.addItem('Width', inImage.width, 'geocode')
        catalog.addItem('Length', inImage.length, 'geocode')
        catalog.addItem('Range looks', objGeo.numberRangeLooks, 'geocode')
        catalog.addItem('Azimuth looks', objGeo.numberAzimuthLooks, 'geocode')
        catalog.addItem('South' , objGeo.minimumGeoLatitude, 'geocode')
        catalog.addItem('North', objGeo.maximumGeoLatitude, 'geocode')
        catalog.addItem('West', objGeo.minimumGeoLongitude, 'geocode')
        catalog.addItem('East', objGeo.maximumGeoLongitude, 'geocode')

    catalog.printToLog(logger, "runGeocode")
    self._insar.procDoc.addAllFromCatalog(catalog)
Ejemplo n.º 6
0
def runGeocode(self, prodlist, unwrapflag, bbox, is_offset_mode=False):
    '''Generalized geocoding of all the files listed above.'''
    from isceobj.Catalog import recordInputsAndOutputs
    logger.info("Geocoding Image")
    insar = self._insar

    if (not self.doInSAR) and (not is_offset_mode):
        print(
            'Skipping geocoding as InSAR processing has not been requested ....'
        )
        return

    elif (not self.doDenseOffsets) and (is_offset_mode):
        print(
            'Skipping geocoding as Dense Offsets has not been requested ....')
        return

    if isinstance(prodlist, str):
        from isceobj.Util.StringUtils import StringUtils as SU
        tobeGeocoded = SU.listify(prodlist)
    else:
        tobeGeocoded = prodlist

    #remove files that have not been processed
    newlist = []
    for toGeo in tobeGeocoded:
        if os.path.exists(toGeo):
            newlist.append(toGeo)

    tobeGeocoded = newlist
    print('Number of products to geocode: ', len(tobeGeocoded))

    if len(tobeGeocoded) == 0:
        print('No products found to geocode')
        return

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

    frames = []
    for swath in swathList:
        referenceProduct = insar.loadProduct(
            os.path.join(insar.fineCoregDirname, 'IW{0}.xml'.format(swath)))
        frames.append(referenceProduct)

    orb = self._insar.getMergedOrbit(frames)

    if bbox is None:
        bboxes = []

        for frame in frames:
            bboxes.append(frame.getBbox())

        snwe = [
            min([x[0] for x in bboxes]),
            max([x[1] for x in bboxes]),
            min([x[2] for x in bboxes]),
            max([x[3] for x in bboxes])
        ]

    else:
        snwe = list(bbox)
        if len(snwe) != 4:
            raise ValueError('Bounding box should be a list/tuple of length 4')

    ###Identify the 4 corners and dimensions
    topSwath = min(frames, key=lambda x: x.sensingStart)
    leftSwath = min(frames, key=lambda x: x.startingRange)

    ####Get required values from product
    burst = frames[0].bursts[0]
    t0 = topSwath.sensingStart
    dtaz = burst.azimuthTimeInterval
    r0 = leftSwath.startingRange
    dr = burst.rangePixelSize
    wvl = burst.radarWavelength
    planet = Planet(pname='Earth')

    ###Setup DEM
    demfilename = self.verifyGeocodeDEM()
    demImage = isceobj.createDemImage()
    demImage.load(demfilename + '.xml')

    ###Catalog for tracking
    catalog = isceobj.Catalog.createCatalog(insar.procDoc.name)
    catalog.addItem('Dem Used', demfilename, 'geocode')

    #####Geocode one by one
    first = False
    ge = Geocodable()
    for prod in tobeGeocoded:
        objGeo = createGeozero()
        objGeo.configure()

        ####IF statements to check for user configuration
        objGeo.snwe = snwe
        objGeo.demCropFilename = os.path.join(insar.mergedDirname,
                                              insar.demCropFilename)
        if is_offset_mode:  ### If using topsOffsetApp, image has been "pre-looked" by the
            objGeo.numberRangeLooks = self.skipwidth  ### skips in runDenseOffsets
            objGeo.numberAzimuthLooks = self.skiphgt
        else:
            objGeo.numberRangeLooks = self.numberRangeLooks
            objGeo.numberAzimuthLooks = self.numberAzimuthLooks
        objGeo.lookSide = -1  #S1A is currently right looking only

        #create the instance of the input image and the appropriate
        #geocode method
        inImage, method = ge.create(prod)
        objGeo.method = method

        objGeo.slantRangePixelSpacing = dr
        objGeo.prf = 1.0 / dtaz
        objGeo.orbit = orb
        objGeo.width = inImage.getWidth()
        objGeo.length = inImage.getLength()
        objGeo.dopplerCentroidCoeffs = [0.]
        objGeo.radarWavelength = wvl

        if is_offset_mode:  ### If using topsOffsetApp, as above, the "pre-looking" adjusts the range/time start
            objGeo.rangeFirstSample = r0 + (self._insar.offset_left - 1) * dr
            objGeo.setSensingStart(t0 + datetime.timedelta(seconds=(
                (self._insar.offset_top - 1) * dtaz)))
        else:
            objGeo.rangeFirstSample = r0 + (
                (self.numberRangeLooks - 1) / 2.0) * dr
            objGeo.setSensingStart(t0 + datetime.timedelta(seconds=((
                (self.numberAzimuthLooks - 1) / 2.0) * dtaz)))
        objGeo.wireInputPort(name='dem', object=demImage)
        objGeo.wireInputPort(name='planet', object=planet)
        objGeo.wireInputPort(name='tobegeocoded', object=inImage)

        objGeo.geocode()

        catalog.addItem('Geocoding: ', inImage.filename, 'geocode')
        catalog.addItem('Output file: ', inImage.filename + '.geo', 'geocode')
        catalog.addItem('Width', inImage.width, 'geocode')
        catalog.addItem('Length', inImage.length, 'geocode')
        catalog.addItem('Range looks', self.numberRangeLooks, 'geocode')
        catalog.addItem('Azimuth looks', self.numberAzimuthLooks, 'geocode')
        catalog.addItem('South', objGeo.minimumGeoLatitude, 'geocode')
        catalog.addItem('North', objGeo.maximumGeoLatitude, 'geocode')
        catalog.addItem('West', objGeo.minimumGeoLongitude, 'geocode')
        catalog.addItem('East', objGeo.maximumGeoLongitude, 'geocode')

    catalog.printToLog(logger, "runGeocode")
    self._insar.procDoc.addAllFromCatalog(catalog)
Ejemplo n.º 7
0
def runGeocode(self, prodlist, unwrapflag, bbox):
    '''Generalized geocoding of all the files listed above.'''
    from isceobj.Catalog import recordInputsAndOutputs
    logger.info("Geocoding Image")
    insar = self.insar

    if isinstance(prodlist,str):
        from isceobj.Util.StringUtils import StringUtils as SU
        tobeGeocoded = SU.listify(prodlist)
    else:
        tobeGeocoded = prodlist

    #remove files that have not been processed
    for toGeo in tobeGeocoded:
        if not os.path.exists(toGeo):
            tobeGeocoded.remove(toGeo)
    print('Number of products to geocode: ', len(tobeGeocoded))

    stdWriter = create_writer("log", "", True, filename="geo.log")

    v,h = insar.vh()
    planet = insar.masterFrame._instrument._platform._planet


    if bbox is None:
        snwe = insar.topo.snwe
    else:
        snwe = list(bbox)
        if len(snwe) != 4:
            raise ValueError('Bounding box should be a list/tuple of length 4')

    #####Geocode one by one
    first = False
    ge = Geocodable()
    for prod in tobeGeocoded:
        objGeo = stdproc.createGeocode('insarapp_geocode_' + os.path.basename(prod).replace('.',''))
        objGeo.configure()

        ####IF statements to check for user configuration
        if objGeo.minimumLatitude is None:
            objGeo.minimumLatitude = snwe[0]

        if objGeo.maximumLatitude is None:
            objGeo.maximumLatitude = snwe[1]

        if objGeo.minimumLongitude is None:
            objGeo.minimumLongitude = snwe[2]

        if objGeo.maximumLongitude is None:
            objGeo.maximumLongitude = snwe[3]

        if objGeo.demCropFilename is None:
            objGeo.demCropFilename = insar.demCropFilename

        objGeo.referenceOrbit = insar.formSLC1.getMocompPosition(1)

        if objGeo.dopplerCentroidConstantTerm is None:
            objGeo.dopplerCentroidConstantTerm = insar.dopplerCentroid.getDopplerCoefficients(inHz=False)[0]

        if objGeo.bodyFixedVelocity is None:
            objGeo.bodyFixedVelocity = v

        if objGeo.spacecraftHeight is None:
            objGeo.spacecraftHeight = h

        if objGeo.numberRangeLooks is None:
            objGeo.numberRangeLooks = insar.numberRangeLooks

        if objGeo.numberAzimuthLooks is None:
            objGeo.numberAzimuthLooks = insar.numberAzimuthLooks

        if objGeo.isMocomp is None:
            objGeo.isMocomp = insar.is_mocomp

        objGeo.stdWriter = stdWriter

        #create the instance of the input image and the appropriate
        #geocode method
        inImage,method = ge.create(prod)
        if objGeo.method is None:
            objGeo.method = method

        if(inImage):
            #demImage = isceobj.createDemImage()
            #IU.copyAttributes(insar.demImage, demImage)
            demImage = insar.demImage.clone()
            objGeo(peg=insar.peg, frame=insar.masterFrame,
                           planet=planet, dem=demImage, tobegeocoded=inImage,
                           geoPosting=None, masterslc=insar.formSLC1)


            recordInputsAndOutputs(self._insar.procDoc, objGeo, "runGeocode",
                                       logger, "runGeocode")

    stdWriter.finalize()
Ejemplo n.º 8
0
def runGeocode(self, prodlist, unwrapflag, bbox):
    '''Generalized geocoding of all the files listed above.'''
    from isceobj.Catalog import recordInputsAndOutputs
    logger.info("Geocoding Image")
    insar = self.insar

    if isinstance(prodlist, str):
        from isceobj.Util.StringUtils import StringUtils as SU
        tobeGeocoded = SU.listify(prodlist)
    else:
        tobeGeocoded = prodlist

    #####Remove the unwrapped interferogram if no unwrapping is done
    if not unwrapflag:
        try:
            tobeGeocoded.remove(insar.unwrappedIntFilename)
        except ValueError:
            pass

    print('Number of products to geocode: ', len(tobeGeocoded))

    frame = insar.masterFrame
    slc = insar.formSLC1
    planet = frame._instrument._platform._planet
    prf = frame._instrument.getPulseRepetitionFrequency()
    wvl = frame._instrument.getRadarWavelength()
    lookSide = frame._instrument._platform.pointingDirection
    sensingStart = insar.formSLC1.slcSensingStart
    delr = 0.5 * SPEED_OF_LIGHT / frame.rangeSamplingRate
    startingRange = slc.startingRange

    if bbox is None:
        snwe = insar.topo.snwe
    else:
        snwe = list(bbox)
        if len(snwe) != 4:
            raise ValueError('Bounding box should be a list/tuple of length 4')

    #####Geocode one by one
    first = False
    ge = Geocodable()
    for prod in tobeGeocoded:
        objGeo = createGeozero()
        objGeo.configure()

        ####IF statements to check for user configuration
        if objGeo.minimumLatitude is None:
            objGeo.minimumLatitude = snwe[0]

        if objGeo.maximumLatitude is None:
            objGeo.maximumLatitude = snwe[1]

        if objGeo.minimumLongitude is None:
            objGeo.minimumLongitude = snwe[2]

        if objGeo.maximumLongitude is None:
            objGeo.maximumLongitude = snwe[3]

        if objGeo.demCropFilename is None:
            objGeo.demCropFilename = insar.demCropFilename

        objGeo.orbit = frame.orbit

        if objGeo.numberRangeLooks is None:
            objGeo.numberRangeLooks = insar.numberRangeLooks

        if objGeo.numberAzimuthLooks is None:
            objGeo.numberAzimuthLooks = insar.numberAzimuthLooks

        #create the instance of the input image and the appropriate
        #geocode method
        inImage, method = ge.create(prod)
        if objGeo.method is None:
            objGeo.method = method

        if (inImage):
            #demImage = isceobj.createDemImage()
            #IU.copyAttributes(insar.demImage, demImage)
            demImage = insar.demImage.clone()

            objGeo.slantRangePixelSpacing = delr
            objGeo.radarWavelength = wvl
            objGeo.width = inImage.getWidth()
            objGeo.length = inImage.getLength()
            objGeo.lookSide = lookSide
            objGeo.prf = prf

            objGeo.setSensingStart(sensingStart + datetime.timedelta(
                seconds=(objGeo.numberAzimuthLooks - 1) / (2 * objGeo.prf)))
            objGeo.rangeFirstSample = startingRange + delr * (
                objGeo.numberRangeLooks - 1) / 2

            #print('method ', objGeo.method)
            #print('prf ', objGeo.prf)
            #print('delr ', objGeo.slantRangePixelSpacing)
            #print('azlooks ', objGeo.numberAzimuthLooks)
            #print('rglooks ', objGeo.numberRangeLooks)
            #print('tstart ', objGeo.sensingStart)
            #print('rstart ', objGeo.rangeFirstSample)

            objGeo.demInterpolationMethod = 'BIQUINTIC'
            objGeo.geoFilename = inImage.filename + '.geo'

            objGeo.wireInputPort(name='dem', object=demImage)
            objGeo.wireInputPort(name='planet', object=planet)
            objGeo.wireInputPort(name='tobegeocoded', object=inImage)

            ####Doppler coefficients
            dop = frame._dopplerVsPixel[::-1]
            xx = np.linspace(0, (slc.slcImage.width - 1), num=len(dop) + 1)
            x = (slc.startingRange -
                 frame.startingRange) / objGeo.slantRangePixelSpacing + xx
            v = np.polyval(dop, x)
            p = np.polyfit(xx, v, len(dop) - 1)[::-1]

            pp = [x / prf for x in p]
            objGeo.dopplerCentroidCoeffs = pp

            objGeo.geocode()