def extractOrbit(self): ''' Extract orbit information from xml node. ''' node = self._xml_root.find('generalAnnotation/orbitList') print('Extracting orbit from annotation XML file') frameOrbit = Orbit() frameOrbit.configure() for child in node.getchildren(): timestamp = self.convertToDateTime(child.find('time').text) pos = [] vel = [] posnode = child.find('position') velnode = child.find('velocity') for tag in ['x', 'y', 'z']: pos.append(float(posnode.find(tag).text)) for tag in ['x', 'y', 'z']: vel.append(float(velnode.find(tag).text)) vec = StateVector() vec.setTime(timestamp) vec.setPosition(pos) vec.setVelocity(vel) frameOrbit.addStateVector(vec) orbExt = OrbitExtender(planet=Planet(pname='Earth')) orbExt.configure() newOrb = orbExt.extendOrbit(frameOrbit) return newOrb
def extractOrbitFromAnnotation(self): ''' Extract orbit information from xml node. ''' node = self._xml_root.find('generalAnnotation/orbitList') frameOrbit = Orbit() frameOrbit.setOrbitSource('Header') for child in node: timestamp = self.convertToDateTime(child.find('time').text) pos = [] vel = [] posnode = child.find('position') velnode = child.find('velocity') for tag in ['x', 'y', 'z']: pos.append(float(posnode.find(tag).text)) for tag in ['x', 'y', 'z']: vel.append(float(velnode.find(tag).text)) vec = StateVector() vec.setTime(timestamp) vec.setPosition(pos) vec.setVelocity(vel) frameOrbit.addStateVector(vec) planet = self.frame.instrument.platform.planet orbExt = OrbitExtender(planet=planet) orbExt.configure() newOrb = orbExt.extendOrbit(frameOrbit) return newOrb
def getOrbitFromXML(self): ''' Populate orbit. ''' orb = Orbit() orb.configure() for node in self._xml_root.find('platform/orbit'): if node.tag == 'stateVec': sv = StateVector() sv.configure() for z in node: if z.tag == 'timeUTC': timeStamp = self.convertToDateTime2(z.text) elif z.tag == 'posX': xPosition = float(z.text) elif z.tag == 'posY': yPosition = float(z.text) elif z.tag == 'posZ': zPosition = float(z.text) elif z.tag == 'velX': xVelocity = float(z.text) elif z.tag == 'velY': yVelocity = float(z.text) elif z.tag == 'velZ': zVelocity = float(z.text) sv.setTime(timeStamp) sv.setPosition([xPosition, yPosition, zPosition]) sv.setVelocity([xVelocity, yVelocity, zVelocity]) orb.addStateVector(sv) print('sv=',sv) orbExt = OrbitExtender(planet=Planet(pname='Earth')) orbExt.configure() newOrb = orbExt.extendOrbit(orb) return newOrb self.product.orbit.setOrbitSource('Header') for sv in newOrb: self.product.orbit.addStateVector(sv)
def getOrbitFromXML(self): ''' Populate orbit. ''' orb = Orbit() orb.configure() for node in self._xml_root.find( 'sourceAttributes/orbitAndAttitude/orbitInformation'): if node.tag == 'stateVector': sv = StateVector() sv.configure() for z in node.getchildren(): if z.tag == 'timeStamp': timeStamp = self.convertToDateTime(z.text) elif z.tag == 'xPosition': xPosition = float(z.text) elif z.tag == 'yPosition': yPosition = float(z.text) elif z.tag == 'zPosition': zPosition = float(z.text) elif z.tag == 'xVelocity': xVelocity = float(z.text) elif z.tag == 'yVelocity': yVelocity = float(z.text) elif z.tag == 'zVelocity': zVelocity = float(z.text) sv.setTime(timeStamp) sv.setPosition([xPosition, yPosition, zPosition]) sv.setVelocity([xVelocity, yVelocity, zVelocity]) orb.addStateVector(sv) orbExt = OrbitExtender(planet=Planet(pname='Earth')) orbExt.configure() newOrb = orbExt.extendOrbit(orb) return newOrb self.product.orbit.setOrbitSource('Header') for sv in newOrb: self.product.orbit.addStateVector(sv)
def populateMetadata(self): """ Create the appropriate metadata objects from our CEOSFormat metadata """ frame = self._decodeSceneReferenceNumber( self.leaderFile.sceneHeaderRecord. metadata['Scene reference number']) try: rangePixelSize = Const.c / (2 * self.leaderFile.sceneHeaderRecord. metadata['Range sampling rate']) except ZeroDivisionError: rangePixelSize = 0 print( 'Average terrain height: ', 1000 * self.leaderFile. sceneHeaderRecord.metadata['Average terrain height in km']) ins = self.frame.getInstrument() platform = ins.getPlatform() platform.setMission(self.leaderFile.sceneHeaderRecord. metadata['Sensor platform mission identifier']) platform.setAntennaLength(self.constants['antennaLength']) platform.setPlanet(Planet(pname='Earth')) ins.setRadarWavelength( self.leaderFile.sceneHeaderRecord.metadata['Radar wavelength']) ins.setIncidenceAngle(self.leaderFile.sceneHeaderRecord. metadata['Incidence angle at scene centre']) self.frame.getInstrument().setPulseRepetitionFrequency( self.leaderFile.sceneHeaderRecord. metadata['Pulse Repetition Frequency']) ins.setRangePixelSize(rangePixelSize) ins.setRangeSamplingRate( self.leaderFile.sceneHeaderRecord.metadata['Range sampling rate']) ins.setPulseLength( self.leaderFile.sceneHeaderRecord.metadata['Range pulse length']) chirpPulseBandwidth = self.leaderFile.processingRecord.metadata[ 'Pulse bandwidth code'] * 1e4 ins.setChirpSlope( chirpPulseBandwidth / self.leaderFile.sceneHeaderRecord.metadata['Range pulse length']) ins.setInPhaseValue(0.0) ins.setQuadratureValue(0.0) self.lineDirection = self.leaderFile.sceneHeaderRecord.metadata[ 'Time direction indicator along line direction'].strip() self.pixelDirection = self.leaderFile.sceneHeaderRecord.metadata[ 'Time direction indicator along pixel direction'].strip() ######RISAT-1 sensor orientation convention is opposite to ours lookSide = self.leaderFile.processingRecord.metadata[ 'Sensor orientation'] if lookSide == 'RIGHT': platform.setPointingDirection(1) elif lookSide == 'LEFT': platform.setPointingDirection(-1) else: raise Exception('Unknown look side') print('Leader file look side: ', lookSide) self.frame.setFrameNumber(frame) self.frame.setOrbitNumber( self.leaderFile.sceneHeaderRecord.metadata['Orbit number']) self.frame.setProcessingFacility( self.leaderFile.sceneHeaderRecord. metadata['Processing facility identifier']) self.frame.setProcessingSystem( self.leaderFile.sceneHeaderRecord. metadata['Processing system identifier']) self.frame.setProcessingSoftwareVersion( self.leaderFile.sceneHeaderRecord. metadata['Processing version identifier']) self.frame.setNumberOfLines( self.imageFile.imageFDR.metadata['Number of lines per data set']) self.frame.setNumberOfSamples( self.imageFile.imageFDR. metadata['Number of pixels per line per SAR channel']) ###### self.frame.getOrbit().setOrbitSource('Header') self.frame.getOrbit().setOrbitQuality( self.leaderFile.platformPositionRecord. metadata['Orbital elements designator']) t0 = datetime.datetime(year=2000 + self.leaderFile.platformPositionRecord. metadata['Year of data point'], month=self.leaderFile.platformPositionRecord. metadata['Month of data point'], day=self.leaderFile.platformPositionRecord. metadata['Day of data point']) t0 = t0 + datetime.timedelta( seconds=self.leaderFile.platformPositionRecord. metadata['Seconds of day']) #####Read in orbit in inertial coordinates orb = Orbit() deltaT = self.leaderFile.platformPositionRecord.metadata[ 'Time interval between DATA points'] numPts = self.leaderFile.platformPositionRecord.metadata[ 'Number of data points'] for i in range(numPts): vec = StateVector() t = t0 + datetime.timedelta(seconds=i * deltaT) vec.setTime(t) dataPoints = self.leaderFile.platformPositionRecord.metadata[ 'Positional Data Points'][i] pos = [ dataPoints['Position vector X'], dataPoints['Position vector Y'], dataPoints['Position vector Z'] ] vel = [ dataPoints['Velocity vector X'], dataPoints['Velocity vector Y'], dataPoints['Velocity vector Z'] ] vec.setPosition(pos) vec.setVelocity(vel) orb.addStateVector(vec) #####Convert orbits from ECI to ECR frame t0 = orb._stateVectors[0]._time ang = self.leaderFile.platformPositionRecord.metadata[ 'Greenwich mean hour angle'] cOrb = ECI2ECR(orb, GAST=ang, epoch=t0) iOrb = cOrb.convert() #####Extend the orbits by a few points #####Expect large azimuth shifts - absolutely needed #####Since CEOS contains state vectors that barely covers scene extent planet = self.frame.instrument.platform.planet orbExt = OrbitExtender() orbExt.configure() orbExt._newPoints = 4 newOrb = orbExt.extendOrbit(iOrb) orb = self.frame.getOrbit() for sv in newOrb: orb.addStateVector(sv) self.doppler_coeff = [ self.leaderFile.sceneHeaderRecord. metadata['Cross track Doppler frequency centroid constant term'], self.leaderFile.sceneHeaderRecord. metadata['Cross track Doppler frequency centroid linear term'], self.leaderFile.sceneHeaderRecord. metadata['Cross track Doppler frequency centroid quadratic term'] ] self.azfmrate_coeff = [ self.leaderFile.sceneHeaderRecord. metadata['Cross track Doppler frequency rate constant term'], self.leaderFile.sceneHeaderRecord. metadata['Cross track Doppler frequency rate linear term'], self.leaderFile.sceneHeaderRecord. metadata['Cross track Doppler frequency rate quadratic term'] ]
def populateMetadata(self): """ Create metadata objects from the metadata files """ mission = self.product.sourceAttributes.satellite swath = self.product.sourceAttributes.radarParameters.beams frequency = self.product.sourceAttributes.radarParameters.radarCenterFrequency orig_prf = self.product.sourceAttributes.radarParameters.prf # original PRF not necessarily effective PRF rangePixelSize = self.product.imageAttributes.rasterAttributes.sampledPixelSpacing rangeSamplingRate = Const.c / (2 * rangePixelSize) pulseLength = self.product.sourceAttributes.radarParameters.pulseLengths[ 0] pulseBandwidth = self.product.sourceAttributes.radarParameters.pulseBandwidths[ 0] polarization = self.product.sourceAttributes.radarParameters.polarizations lookSide = lookMap[self.product.sourceAttributes.radarParameters. antennaPointing.upper()] facility = self.product.imageGenerationParameters.generalProcessingInformation._processingFacility version = self.product.imageGenerationParameters.generalProcessingInformation.softwareVersion lines = self.product.imageAttributes.rasterAttributes.numberOfLines samples = self.product.imageAttributes.rasterAttributes.numberOfSamplesPerLine startingRange = self.product.imageGenerationParameters.slantRangeToGroundRange.slantRangeTimeToFirstRangeSample * ( Const.c / 2) incidenceAngle = (self.product.imageGenerationParameters. sarProcessingInformation.incidenceAngleNearRange + self.product.imageGenerationParameters. sarProcessingInformation.incidenceAngleFarRange) / 2 # some RS2 scenes have oversampled SLC images because processed azimuth bandwidth larger than PRF EJF 2015/08/15 azimuthPixelSize = self.product.imageAttributes.rasterAttributes.sampledLineSpacing # ground spacing in meters totalProcessedAzimuthBandwidth = self.product.imageGenerationParameters.sarProcessingInformation.totalProcessedAzimuthBandwidth prf = orig_prf * np.ceil( totalProcessedAzimuthBandwidth / orig_prf ) # effective PRF can be double original, suggested by Piyush print("effective PRF %f, original PRF %f" % (prf, orig_prf)) lineFlip = (self.product.imageAttributes.rasterAttributes. lineTimeOrdering.upper() == 'DECREASING') if lineFlip: dataStopTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeFirstLine dataStartTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeLastLine else: dataStartTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeFirstLine dataStopTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeLastLine passDirection = self.product.sourceAttributes.orbitAndAttitude.orbitInformation.passDirection height = self.product.imageGenerationParameters.sarProcessingInformation._satelliteHeight ####Populate platform platform = self.frame.getInstrument().getPlatform() platform.setPlanet(Planet(pname="Earth")) platform.setMission(mission) platform.setPointingDirection(lookSide) platform.setAntennaLength(15.0) ####Populate instrument instrument = self.frame.getInstrument() instrument.setRadarFrequency(frequency) instrument.setPulseRepetitionFrequency(prf) instrument.setPulseLength(pulseLength) instrument.setChirpSlope(pulseBandwidth / pulseLength) instrument.setIncidenceAngle(incidenceAngle) #self.frame.getInstrument().setRangeBias(0) instrument.setRangePixelSize(rangePixelSize) instrument.setRangeSamplingRate(rangeSamplingRate) instrument.setBeamNumber(swath) instrument.setPulseLength(pulseLength) #Populate Frame #self.frame.setSatelliteHeight(height) self.frame.setSensingStart(dataStartTime) self.frame.setSensingStop(dataStopTime) diffTime = DTUtil.timeDeltaToSeconds(dataStopTime - dataStartTime) / 2.0 sensingMid = dataStartTime + datetime.timedelta( microseconds=int(diffTime * 1e6)) self.frame.setSensingMid(sensingMid) self.frame.setPassDirection(passDirection) self.frame.setPolarization(polarization) self.frame.setStartingRange(startingRange) self.frame.setFarRange(startingRange + (samples - 1) * rangePixelSize) self.frame.setNumberOfLines(lines) self.frame.setNumberOfSamples(samples) self.frame.setProcessingFacility(facility) self.frame.setProcessingSoftwareVersion(version) # Initialize orbit objects # Read into temp orbit first. # Radarsat 2 needs orbit extensions. tempOrbit = Orbit() self.frame.getOrbit().setOrbitSource( 'Header: ' + self.product.sourceAttributes.orbitAndAttitude. orbitInformation.orbitDataFile) self.frame.setPassDirection(passDirection) stateVectors = self.product.sourceAttributes.orbitAndAttitude.orbitInformation.stateVectors for i in range(len(stateVectors)): position = [ stateVectors[i].xPosition, stateVectors[i].yPosition, stateVectors[i].zPosition ] velocity = [ stateVectors[i].xVelocity, stateVectors[i].yVelocity, stateVectors[i].zVelocity ] vec = StateVector() vec.setTime(stateVectors[i].timeStamp) vec.setPosition(position) vec.setVelocity(velocity) tempOrbit.addStateVector(vec) planet = self.frame.instrument.platform.planet orbExt = OrbitExtender(planet=planet) orbExt.configure() newOrb = orbExt.extendOrbit(tempOrbit) for sv in newOrb: self.frame.getOrbit().addStateVector(sv) # save the Doppler centroid coefficients, converting units from product.xml 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 # added EJF 2015/08/17 dc = self.product.imageGenerationParameters.dopplerCentroid poly = dc.dopplerCentroidCoefficients # 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) # Guessing that ISCE expects Hz, Hz/(range sample), Hz((range sample)^2 # note that RS2 Doppler values are estimated at time dc.dopplerRateReferenceTime, # so the values might need to be adjusted for ISCE usage # added EJF 2015/08/17 dr = self.product.imageGenerationParameters.dopplerRateValues fmpoly = dr.dopplerRateValuesCoefficients # need to convert units fmpoly[1] = fmpoly[1] / rangeSamplingRate fmpoly[2] = fmpoly[2] / rangeSamplingRate**2 self.azfmrate_coeff = fmpoly
def populateMetadata(self): """ Create metadata objects from the metadata files """ mission = self.product.sourceAttributes.satellite swath = self.product.sourceAttributes.radarParameters.beams frequency = self.product.sourceAttributes.radarParameters.radarCenterFrequency prf = self.product.sourceAttributes.radarParameters.prf rangePixelSize = self.product.imageAttributes.rasterAttributes.sampledPixelSpacing rangeSamplingRate = Const.c/(2*rangePixelSize) pulseLength = self.product.sourceAttributes.radarParameters.pulseLengths[0] pulseBandwidth = self.product.sourceAttributes.radarParameters.pulseBandwidths[0] polarization = self.product.sourceAttributes.radarParameters.polarizations lookSide = lookMap[self.product.sourceAttributes.radarParameters.antennaPointing.upper()] facility = self.product.imageGenerationParameters.generalProcessingInformation._processingFacility version = self.product.imageGenerationParameters.generalProcessingInformation.softwareVersion lines = self.product.imageAttributes.rasterAttributes.numberOfLines samples = self.product.imageAttributes.rasterAttributes.numberOfSamplesPerLine startingRange = self.product.imageGenerationParameters.slantRangeToGroundRange.slantRangeTimeToFirstRangeSample * (Const.c/2) incidenceAngle = (self.product.imageGenerationParameters.sarProcessingInformation.incidenceAngleNearRange + self.product.imageGenerationParameters.sarProcessingInformation.incidenceAngleFarRange)/2 lineFlip = (self.product.imageAttributes.rasterAttributes.lineTimeOrdering.upper() == 'DECREASING') if lineFlip: dataStopTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeFirstLine dataStartTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeLastLine else: dataStartTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeFirstLine dataStopTime = self.product.imageGenerationParameters.sarProcessingInformation.zeroDopplerTimeLastLine passDirection = self.product.sourceAttributes.orbitAndAttitude.orbitInformation.passDirection height = self.product.imageGenerationParameters.sarProcessingInformation._satelliteHeight ####Populate platform platform = self.frame.getInstrument().getPlatform() platform.setPlanet(Planet("Earth")) platform.setMission(mission) platform.setPointingDirection(lookSide) platform.setAntennaLength(15.0) ####Populate instrument instrument = self.frame.getInstrument() instrument.setRadarFrequency(frequency) instrument.setPulseRepetitionFrequency(prf) instrument.setPulseLength(pulseLength) instrument.setChirpSlope(pulseBandwidth/pulseLength) instrument.setIncidenceAngle(incidenceAngle) #self.frame.getInstrument().setRangeBias(0) instrument.setRangePixelSize(rangePixelSize) instrument.setRangeSamplingRate(rangeSamplingRate) instrument.setBeamNumber(swath) instrument.setPulseLength(pulseLength) #Populate Frame #self.frame.setSatelliteHeight(height) self.frame.setSensingStart(dataStartTime) self.frame.setSensingStop(dataStopTime) diffTime = DTUtil.timeDeltaToSeconds(dataStopTime - dataStartTime)/2.0 sensingMid = dataStartTime + datetime.timedelta(microseconds=int(diffTime*1e6)) self.frame.setSensingMid(sensingMid) self.frame.setPassDirection(passDirection) self.frame.setPolarization(polarization) self.frame.setStartingRange(startingRange) self.frame.setFarRange(startingRange + (samples-1)*rangePixelSize) self.frame.setNumberOfLines(lines) self.frame.setNumberOfSamples(samples) self.frame.setProcessingFacility(facility) self.frame.setProcessingSoftwareVersion(version) # Initialize orbit objects # Read into temp orbit first. # Radarsat 2 needs orbit extensions. tempOrbit = Orbit() self.frame.getOrbit().setOrbitSource('Header: ' + self.product.sourceAttributes.orbitAndAttitude.orbitInformation.orbitDataFile) self.frame.setPassDirection(passDirection) stateVectors = self.product.sourceAttributes.orbitAndAttitude.orbitInformation.stateVectors for i in range(len(stateVectors)): position = [stateVectors[i].xPosition, stateVectors[i].yPosition, stateVectors[i].zPosition] velocity = [stateVectors[i].xVelocity, stateVectors[i].yVelocity, stateVectors[i].zVelocity] vec = StateVector() vec.setTime(stateVectors[i].timeStamp) vec.setPosition(position) vec.setVelocity(velocity) tempOrbit.addStateVector(vec) planet = self.frame.instrument.platform.planet orbExt = OrbitExtender(planet=planet) orbExt.configure() newOrb = orbExt.extendOrbit(tempOrbit) for sv in newOrb: self.frame.getOrbit().addStateVector(sv)