コード例 #1
0
ファイル: Stack.py プロジェクト: wchch1010/isce2
def baselinePair(baselineDir, master, slave):

    try:
        mdb = shelve.open(os.path.join(master, 'raw'), flag='r')
        sdb = shelve.open(os.path.join(slave, 'raw'), flag='r')
    except:
        mdb = shelve.open(os.path.join(master, 'data'), flag='r')
        sdb = shelve.open(os.path.join(slave, 'data'), flag='r')

    mFrame = mdb['frame']
    sFrame = sdb['frame']

    bObj = Baseline()
    bObj.configure()
    bObj.wireInputPort(name='masterFrame', object=mFrame)
    bObj.wireInputPort(name='slaveFrame', object=sFrame)
    bObj.baseline()
    baselineOutName = os.path.basename(master) + "_" + os.path.basename(
        slave) + ".txt"
    f = open(os.path.join(baselineDir, baselineOutName), 'w')
    f.write("PERP_BASELINE_BOTTOM " + str(bObj.pBaselineBottom) + '\n')
    f.write("PERP_BASELINE_TOP " + str(bObj.pBaselineTop) + '\n')
    f.close()
    print('Baseline at top/bottom: %f %f' %
          (bObj.pBaselineTop, bObj.pBaselineBottom))
    return (bObj.pBaselineTop + bObj.pBaselineBottom) / 2.
コード例 #2
0
def getBaseline(frame1, frame2, catalog=None, sceneid='NO_ID'):
    optlist = ['all', 'top', 'middle', 'bottom']
    success = False
    baseLocation = None
    for option in optlist:
        baseObj = Baseline()
        baseObj.configure()
        baseObj.baselineLocation = option
        baseObj.wireInputPort(name='masterFrame',object=frame1)
        baseObj.wireInputPort(name='slaveFrame',object=frame2)
        try:
            baseObj.baseline()
            success = True
            baseLocation = option
        except:
            logger.debug(('runPreprocessor.getBaseline '+
                          'option "{0}" failed'.format(option)))
            pass
        if success:
            logger.debug(('runPreprocessor.getBaseline: '+
                          'option "{0}" success'.format(option)))
            break
    if not success:
        raise Exception('Baseline computation failed with all possible options. Images may not overlap.')

    if catalog is not None:
        catalog.addItem('horizontal_baseline_top', baseObj.hBaselineTop, sceneid)
        catalog.addItem('horizontal_baseline_rate', baseObj.hBaselineRate, sceneid)
        catalog.addItem('horizontal_baseline_acc', baseObj.hBaselineAcc, sceneid)
        catalog.addItem('vertical_baseline_top', baseObj.vBaselineTop, sceneid)
        catalog.addItem('vertical_baseline_rate', baseObj.vBaselineRate, sceneid)
        catalog.addItem('vertical_baseline_acc', baseObj.vBaselineAcc, sceneid)
        catalog.addItem('perp_baseline_top', baseObj.pBaselineTop, sceneid)
        catalog.addItem('perp_baseline_bottom', baseObj.pBaselineBottom, sceneid)
コード例 #3
0
def baselinePair(baselineDir, master, slave, doBaselines=True):

    if doBaselines:  # open files to calculate baselines
        try:
            mdb = shelve.open(os.path.join(master, 'raw'), flag='r')
            sdb = shelve.open(os.path.join(slave, 'raw'), flag='r')
        except:
            mdb = shelve.open(os.path.join(master, 'data'), flag='r')
            sdb = shelve.open(os.path.join(slave, 'data'), flag='r')

        mFrame = mdb['frame']
        sFrame = sdb['frame']

        bObj = Baseline()
        bObj.configure()
        bObj.wireInputPort(name='masterFrame', object=mFrame)
        bObj.wireInputPort(name='slaveFrame', object=sFrame)
        bObj.baseline()  # calculate baseline from orbits
        pBaselineBottom = bObj.pBaselineBottom
        pBaselineTop = bObj.pBaselineTop
    else:  # set baselines to zero if not calculated
        pBaselineBottom = 0.0
        pBaselineTop = 0.0

    baselineOutName = os.path.basename(master) + "_" + os.path.basename(
        slave) + ".txt"
    f = open(os.path.join(baselineDir, baselineOutName), 'w')
    f.write("PERP_BASELINE_BOTTOM " + str(pBaselineBottom) + '\n')
    f.write("PERP_BASELINE_TOP " + str(pBaselineTop) + '\n')
    f.close()
    print('Baseline at top/bottom: %f %f' % (pBaselineTop, pBaselineBottom))
    return (pBaselineTop + pBaselineBottom) / 2.
コード例 #4
0
    def computeBaseline(self, refDir, secDir):
        import isce
        import isceobj
        from mroipac.baseline.Baseline import Baseline
        import shelve

        #try:
        #    mdb = shelve.open( os.path.join(refDir, 'data'), flag='r')
        #except:
        with shelve.open(os.path.join(refDir, 'raw'), flag='r') as mdb:
            rFrame = mdb['frame']

        #try:
        #    sdb = shelve.open( os.path.join(secDir, 'data'), flag='r')
        #except:
        with shelve.open(os.path.join(secDir, 'raw'), flag='r') as sdb:
            sFrame = sdb['frame']

        bObj = Baseline()
        bObj.configure()
        bObj.wireInputPort(name='masterFrame', object=rFrame)
        bObj.wireInputPort(name='slaveFrame', object=sFrame)

        bObj.baseline()

        print('Baseline at top/bottom: %f %f' %
              (bObj.pBaselineTop, bObj.pBaselineBottom))

        avgBaseline = (bObj.pBaselineTop + bObj.pBaselineBottom) / 2.0

        return avgBaseline
コード例 #5
0
if not os.path.isdir(args.slcname_slave):
    os.mkdir(args.slcname_slave)
date = os.path.basename(args.slcname_slave)
obj = createSensor('TanDEMX')
obj.xml = args.fname_slave
obj.output = os.path.join(args.slcname_slave, date + '.slc')
if not os.path.exists(obj.output):
    obj.extractImage()
    obj.frame.getImage().renderHdr()
    obj.extractDoppler()
pickName_slave = os.path.join(args.slcname_slave, 'data')
if os.path.exists(pickName_slave):
    with shelve.open(pickName_slave, flag='r') as sdb:
        sFrame = sdb['frame']
else:
    with shelve.open(pickName_slave) as sdb:
        sdb['frame'] = obj.frame
        sFrame = sdb['frame']

### Baseline generation
bObj = Baseline()
bObj.configure()
bObj.wireInputPort(name='masterFrame', object=mFrame)
bObj.wireInputPort(name='slaveFrame', object=sFrame)
bObj.baseline()
print('Baseline at top/bottom: %f %f' %
      (bObj.pBaselineTop, bObj.pBaselineBottom))

mdb.close()
sdb.close()
コード例 #6
0
def runPreprocessor(self):
    master = make_raw(self.master, self.masterdop)
    self.insar.rawMasterIQImage = master.iqImage
    slave = make_raw(self.slave, self.slavedop)
    self.insar.rawSlaveIQImage = slave.iqImage
    self._insar.numberRangeBins = master.frame.numberRangeBins
    #add raw images to main object
    masterRaw = initRawImage(master)
    self._insar.setMasterRawImage(masterRaw)
    slaveRaw = initRawImage(slave)
    self._insar.setSlaveRawImage(slaveRaw)

    #add frames to main  object
    self._insar.setMasterFrame(master.frame)
    self._insar.setSlaveFrame(slave.frame)

    #add doppler to main object
    self._insar.setMasterDoppler(master.getDopplerValues())
    self._insar.setSlaveDoppler(slave.getDopplerValues())

    #add squints to main object
    self._insar.setMasterSquint(master.getSquint())
    self._insar.setSlaveSquint(slave.getSquint())

    #add look direction
    self._insar.setLookSide(
        master.frame.getInstrument().getPlatform().pointingDirection)

    catalog = isceobj.Catalog.createCatalog(self._insar.procDoc.name)

    frame = self._insar.getMasterFrame()
    instrument = frame.getInstrument()
    platform = instrument.getPlatform()

    planet = platform.getPlanet()
    catalog.addInputsFrom(planet, 'planet')
    catalog.addInputsFrom(planet.get_elp(), 'planet.ellipsoid')

    catalog.addInputsFrom(master.sensor, 'master.sensor')
    catalog.addItem('width', masterRaw.getWidth(), 'master')
    catalog.addItem('xmin', masterRaw.getXmin(), 'master')
    catalog.addItem('iBias', instrument.getInPhaseValue(), 'master')
    catalog.addItem('qBias', instrument.getQuadratureValue(), 'master')
    catalog.addItem('range_sampling_rate', instrument.getRangeSamplingRate(),
                    'master')
    catalog.addItem('prf', instrument.getPulseRepetitionFrequency(), 'master')
    catalog.addItem('pri', 1.0 / instrument.getPulseRepetitionFrequency(),
                    'master')
    catalog.addItem('pulse_length', instrument.getPulseLength(), 'master')
    catalog.addItem('chirp_slope', instrument.getChirpSlope(), 'master')
    catalog.addItem('wavelength', instrument.getRadarWavelength(), 'master')
    catalog.addItem('lookSide', platform.pointingDirection, 'master')
    catalog.addInputsFrom(frame, 'master.frame')
    catalog.addInputsFrom(instrument, 'master.instrument')
    catalog.addInputsFrom(platform, 'master.platform')
    catalog.addInputsFrom(frame.orbit, 'master.orbit')

    frame = self._insar.getSlaveFrame()
    instrument = frame.getInstrument()
    platform = instrument.getPlatform()

    catalog.addInputsFrom(slave.sensor, 'slave.sensor')
    catalog.addItem('width', slaveRaw.getWidth(), 'slave')
    catalog.addItem('xmin', slaveRaw.getXmin(), 'slave')
    catalog.addItem('iBias', instrument.getInPhaseValue(), 'slave')
    catalog.addItem('qBias', instrument.getQuadratureValue(), 'slave')
    catalog.addItem('range_sampling_rate', instrument.getRangeSamplingRate(),
                    'slave')
    catalog.addItem('prf', instrument.getPulseRepetitionFrequency(), 'slave')
    catalog.addItem('pri', 1.0 / instrument.getPulseRepetitionFrequency(),
                    'slave')
    catalog.addItem('pulse_length', instrument.getPulseLength(), 'slave')
    catalog.addItem('chirp_slope', instrument.getChirpSlope(), 'slave')
    catalog.addItem('wavelength', instrument.getRadarWavelength(), 'slave')
    catalog.addItem('lookSide', platform.pointingDirection, 'slave')
    catalog.addInputsFrom(frame, 'slave.frame')
    catalog.addInputsFrom(instrument, 'slave.instrument')
    catalog.addInputsFrom(platform, 'slave.platform')
    catalog.addInputsFrom(frame.orbit, 'slave.orbit')

    optlist = ['all', 'top', 'middle', 'bottom']
    success = False
    baseLocation = None

    for option in optlist:
        baseObj = Baseline()
        baseObj.configure()
        baseObj.baselineLocation = option
        baseObj.wireInputPort(name='masterFrame',
                              object=self._insar.getMasterFrame())
        baseObj.wireInputPort(name='slaveFrame',
                              object=self._insar.getSlaveFrame())
        try:
            baseObj.baseline()
            success = True
            baseLocation = option
        except:
            print('Baseline computation with option {0} Failed'.format(option))
            pass

        if success:
            break

    if not success:
        raise Exception(
            'Baseline computation failed with all possible options. Images may not overlap.'
        )

    catalog.addItem('horizontal_baseline_top', baseObj.hBaselineTop,
                    'baseline')
    catalog.addItem('horizontal_baseline_rate', baseObj.hBaselineRate,
                    'baseline')
    catalog.addItem('horizontal_baseline_acc', baseObj.hBaselineAcc,
                    'baseline')
    catalog.addItem('vertical_baseline_top', baseObj.vBaselineTop, 'baseline')
    catalog.addItem('vertical_baseline_rate', baseObj.vBaselineRate,
                    'baseline')
    catalog.addItem('vertical_baseline_acc', baseObj.vBaselineAcc, 'baseline')
    catalog.addItem('perp_baseline_top', baseObj.pBaselineTop, 'baseline')
    catalog.addItem('perp_baseline_bottom', baseObj.pBaselineBottom,
                    'baseline')
    catalog.addItem('baseline_location', baseLocation, 'baseline')

    catalog.printToLog(logger, "runPreprocessor")
    self._insar.procDoc.addAllFromCatalog(catalog)
コード例 #7
0
ファイル: runPreprocessor.py プロジェクト: solkan1201/FSH
def runPreprocessor(self):

    from .Factories import isRawSensor, isZeroDopplerSLC, getDopplerMethod

    ###Unpack master
    sensor = copy.deepcopy(self.master)

    dirname = sensor.output

    if self.masterSensorName is None:
        self.masterSensorName = self.sensorName

    israwdata = isRawSensor(self.masterSensorName)

    if self.masterDopplerMethod is None:
        mdop = getDopplerMethod(self.masterSensorName)
    else:
        mdop = self.masterDopplerMethod

    masterdop = isceobj.Doppler.createDoppler(mdop)

    if israwdata:
        print('Master data is in RAW format. Adding _raw to output name.')
        sensor.output = os.path.join(dirname + '_raw',
                                     os.path.basename(dirname) + '.raw')
        if not os.path.isdir(os.path.dirname(sensor.output)):
            os.makedirs(os.path.dirname(sensor.output))
        #sensor._resampleFlag = 'single2dual'
        master = make_raw(sensor, masterdop)

        ###Weird handling here because of way make_raw is structured
        ###DOPIQ uses weird dict to store coeffs
        if mdop == 'useDOPIQ':
            #master._dopplerVsPixel = [masterdop.quadratic[x]*master.PRF for x in ['a','b','c']]
            master.frame._dopplerVsPixel = [
                masterdop.quadratic[x] * master.PRF for x in ['a', 'b', 'c']
            ]

        if self._insar.masterRawProduct is None:
            self._insar.masterRawProduct = dirname + '_raw.xml'

        self._insar.saveProduct(master.frame, self._insar.masterRawProduct)

    else:
        print('Master data is in SLC format. Adding _slc to output name.')
        iszerodop = isZeroDopplerSLC(self.masterSensorName)
        sensor.output = os.path.join(dirname + '_slc',
                                     os.path.basename(dirname) + '.slc')

        if not os.path.isdir(os.path.dirname(sensor.output)):
            os.makedirs(os.path.dirname(sensor.output))

        master = make_raw(sensor, masterdop)

        if self._insar.masterSlcProduct is None:
            self._insar.masterSlcProduct = dirname + '_slc.xml'

        if iszerodop:
            self._insar.masterGeometrySystem = 'Zero Doppler'
        else:
            self._insar.masterGeometrySystem = 'Native Doppler'

        self._insar.saveProduct(master.frame, self._insar.masterSlcProduct)

    ###Unpack slave
    sensor = copy.deepcopy(self.slave)
    dirname = sensor.output

    if self.slaveSensorName is None:
        self.slaveSensorName = self.sensorName

    israwdata = isRawSensor(self.slaveSensorName)

    if self.slaveDopplerMethod is None:
        sdop = getDopplerMethod(self.slaveSensorName)
    else:
        sdop = self.slaveDopplerMethod

    slavedop = isceobj.Doppler.createDoppler(sdop)

    if israwdata:
        print('Slave data is in RAW format. Adding _raw to output name.')
        sensor.output = os.path.join(dirname + '_raw',
                                     os.path.basename(dirname) + '.raw')

        if not os.path.isdir(os.path.dirname(sensor.output)):
            os.makedirs(os.path.dirname(sensor.output))

        slave = make_raw(sensor, slavedop)

        ###Weird handling here because of make_raw structure
        ###DOPIQ uses weird dict to store coefficients
        if sdop == 'useDOPIQ':
            #slave._dopplerVsPixel = [slavedop.quadratic[x]*slave.PRF for x in ['a','b','c']]
            slave.frame._dopplerVsPixel = [
                slavedop.quadratic[x] * slave.PRF for x in ['a', 'b', 'c']
            ]

        if self._insar.slaveRawProduct is None:
            self._insar.slaveRawProduct = dirname + '_raw.xml'

        self._insar.saveProduct(slave.frame, self._insar.slaveRawProduct)

    else:
        print('Master data is in SLC format. Adding _slc to output name.')
        iszerodop = isZeroDopplerSLC(self.slaveSensorName)
        sensor.output = os.path.join(dirname + '_slc',
                                     os.path.basename(dirname) + '.slc')

        if not os.path.isdir(os.path.dirname(sensor.output)):
            os.makedirs(os.path.dirname(sensor.output))

        slave = make_raw(sensor, slavedop)

        if self._insar.slaveSlcProduct is None:
            self._insar.slaveSlcProduct = dirname + '_slc.xml'

        if iszerodop:
            self._insar.slaveGeometrySystem = 'Zero Doppler'
        else:
            self._insar.slaveGeometrySystem = 'Native Doppler'

        self._insar.saveProduct(slave.frame, self._insar.slaveSlcProduct)

    catalog = isceobj.Catalog.createCatalog(self._insar.procDoc.name)
    frame = master.frame
    instrument = frame.getInstrument()
    platform = instrument.getPlatform()

    catalog.addInputsFrom(master.sensor, 'master.sensor')
    catalog.addItem('width', frame.numberOfSamples, 'master')
    catalog.addItem('iBias', instrument.getInPhaseValue(), 'master')
    catalog.addItem('qBias', instrument.getQuadratureValue(), 'master')
    catalog.addItem('range_sampling_rate', instrument.getRangeSamplingRate(),
                    'master')
    catalog.addItem('prf', instrument.getPulseRepetitionFrequency(), 'master')
    catalog.addItem('pri', 1.0 / instrument.getPulseRepetitionFrequency(),
                    'master')
    catalog.addItem('pulse_length', instrument.getPulseLength(), 'master')
    catalog.addItem('chirp_slope', instrument.getChirpSlope(), 'master')
    catalog.addItem('wavelength', instrument.getRadarWavelength(), 'master')
    catalog.addItem('lookSide', platform.pointingDirection, 'master')
    catalog.addInputsFrom(frame, 'master.frame')
    catalog.addInputsFrom(instrument, 'master.instrument')
    catalog.addInputsFrom(platform, 'master.platform')
    catalog.addInputsFrom(frame.orbit, 'master.orbit')

    frame = slave.frame
    instrument = frame.getInstrument()
    platform = instrument.getPlatform()

    catalog.addInputsFrom(slave.sensor, 'slave.sensor')
    catalog.addItem('width', frame.numberOfSamples, 'slave')
    catalog.addItem('iBias', instrument.getInPhaseValue(), 'slave')
    catalog.addItem('qBias', instrument.getQuadratureValue(), 'slave')
    catalog.addItem('range_sampling_rate', instrument.getRangeSamplingRate(),
                    'slave')
    catalog.addItem('prf', instrument.getPulseRepetitionFrequency(), 'slave')
    catalog.addItem('pri', 1.0 / instrument.getPulseRepetitionFrequency(),
                    'slave')
    catalog.addItem('pulse_length', instrument.getPulseLength(), 'slave')
    catalog.addItem('chirp_slope', instrument.getChirpSlope(), 'slave')
    catalog.addItem('wavelength', instrument.getRadarWavelength(), 'slave')
    catalog.addItem('lookSide', platform.pointingDirection, 'slave')
    catalog.addInputsFrom(frame, 'slave.frame')
    catalog.addInputsFrom(instrument, 'slave.instrument')
    catalog.addInputsFrom(platform, 'slave.platform')
    catalog.addInputsFrom(frame.orbit, 'slave.orbit')

    # NEW COMMANDS added by YL --start
    optlist = ['all', 'top', 'middle', 'bottom']
    success = False
    baseLocation = None

    for option in optlist:
        baseObj = Baseline()
        baseObj.configure()
        baseObj.baselineLocation = option
        baseObj.wireInputPort(name='masterFrame', object=master.frame)
        baseObj.wireInputPort(name='slaveFrame', object=slave.frame)
        try:
            baseObj.baseline()
            success = True
            baseLocation = option
        except:
            print('Baseline computation with option {0} Failed'.format(option))
            pass

        if success:
            break

    if not success:
        raise Exception(
            'Baseline computation failed with all possible options. Images may not overlap.'
        )

    catalog.addItem('horizontal_baseline_top', baseObj.hBaselineTop,
                    'baseline')
    catalog.addItem('horizontal_baseline_rate', baseObj.hBaselineRate,
                    'baseline')
    catalog.addItem('horizontal_baseline_acc', baseObj.hBaselineAcc,
                    'baseline')
    catalog.addItem('vertical_baseline_top', baseObj.vBaselineTop, 'baseline')
    catalog.addItem('vertical_baseline_rate', baseObj.vBaselineRate,
                    'baseline')
    catalog.addItem('vertical_baseline_acc', baseObj.vBaselineAcc, 'baseline')
    catalog.addItem('perp_baseline_top', baseObj.pBaselineTop, 'baseline')
    catalog.addItem('perp_baseline_bottom', baseObj.pBaselineBottom,
                    'baseline')
    catalog.addItem('baseline_location', baseLocation, 'baseline')
    # NEW COMMANDS added by YL --end

    catalog.printToLog(logger, "runPreprocessor")
    self._insar.procDoc.addAllFromCatalog(catalog)
コード例 #8
0
def calBaseline(masterFrame, slaveFrame, baselineName):

    #setting up catalog name
    masterYear = str(masterFrame.sensingStart.year)
    masterMonth = '%02d' % masterFrame.sensingStart.month
    masterDay = '%02d' % masterFrame.sensingStart.day

    slaveYear = str(slaveFrame.sensingStart.year)
    slaveMonth = '%02d' % slaveFrame.sensingStart.month
    slaveDay = '%02d' % slaveFrame.sensingStart.day

    catalogName = masterYear + masterMonth + masterDay + '-' + slaveYear + slaveMonth + slaveDay + '_baseline'
    if baselineName != None:
        if baselineName.endswith('.xml'):
            catalogName = os.path.splitext(baselineName)[0]
        else:
            catalogName = baselineName

    catalog = isceobj.Catalog.createCatalog(catalogName)

    #calculate baseline
    optlist = ['all', 'top', 'middle', 'bottom']
    success = False
    baseLocation = None

    for option in optlist:
        baseObj = Baseline()
        baseObj.configure()
        baseObj.baselineLocation = option
        baseObj.wireInputPort(name='masterFrame', object=masterFrame)
        baseObj.wireInputPort(name='slaveFrame', object=slaveFrame)
        try:
            baseObj.baseline()
            success = True
            baseLocation = option
        except:
            print('Baseline computation with option {0} Failed'.format(option))
            pass

        if success:
            break

    if not success:
        raise Exception(
            'Baseline computation failed with all possible options. Images may not overlap.'
        )

    print('horizontal_baseline_top: {}'.format(baseObj.hBaselineTop))
    print('horizontal_baseline_rate: {}'.format(baseObj.hBaselineRate))
    print('horizontal_baseline_acc: {}'.format(baseObj.hBaselineAcc))
    print('vertical_baseline_top: {}'.format(baseObj.vBaselineTop))
    print('vertical_baseline_rate: {}'.format(baseObj.vBaselineRate))
    print('vertical_baseline_acc: {}'.format(baseObj.vBaselineAcc))
    print('perp_baseline_top: {}'.format(baseObj.pBaselineTop))
    print('perp_baseline_bottom: {}'.format(baseObj.pBaselineBottom))
    print('baseline_location: {}'.format(baseLocation))

    catalog.addItem('horizontal_baseline_top', baseObj.hBaselineTop,
                    'baseline')
    catalog.addItem('horizontal_baseline_rate', baseObj.hBaselineRate,
                    'baseline')
    catalog.addItem('horizontal_baseline_acc', baseObj.hBaselineAcc,
                    'baseline')
    catalog.addItem('vertical_baseline_top', baseObj.vBaselineTop, 'baseline')
    catalog.addItem('vertical_baseline_rate', baseObj.vBaselineRate,
                    'baseline')
    catalog.addItem('vertical_baseline_acc', baseObj.vBaselineAcc, 'baseline')
    catalog.addItem('perp_baseline_top', baseObj.pBaselineTop, 'baseline')
    catalog.addItem('perp_baseline_bottom', baseObj.pBaselineBottom,
                    'baseline')
    catalog.addItem('baseline_location', baseLocation, 'baseline')

    catalog.renderXml()