def main(): parser = argparse.ArgumentParser() parser.add_argument('rinex3obs_filename') args = parser.parse_args() user_input = raw_input( 'Name your PRN of interest, by number: 1 through 32: ') int_prn = int(user_input) try: print('Reading {}'.format(args.rinex3obs_filename)) header, data = gpstk.readRinex3Obs( args.rinex3obs_filename) # read in everything print(header) # Now we loop through all the epochs and process the data for each one for d in data: # Let's use the CivilTime class to print an easy to understand time: civtime = gpstk.CivilTime(d.time) print(civtime, ) # Make a GPSTk SatID for the user's PRN so we can search for it prn = gpstk.RinexSatID(int_prn, gpstk.SatID.systemGPS) # Check if the PRN is in view (by searching for it) if d.obs.find(prn) == d.obs.end(): print('PRN {} not in view'.format(int_prn)) else: P1 = d.getObs(prn, "P1", header).data P2 = d.getObs(prn, "P2", header).data L1 = d.getObs(prn, "L1", header).data mu = P1 - L1 * (C_MPS / L1_FREQ_GPS) - 2 * (P1 - P2) / (1 - GAMMA_GPS) print('PRN {} biased multipath {}'.format(int_prn, mu)) # We can catch any custom gpstk exception like this: except gpstk.Exception as e: print(e)
def process(input_file, output_file): try: print 'Reading {}.'.format(input_file) header, data = gpstk.readRinex3Obs(input_file) # read in everything #print header new_header = gpstk.Rinex3ObsHeader() # Initially, valid = 0L, but other values get masked into it. new_header.version = header.version new_header.fileType = header.fileType new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validVersion new_header.fileProgram = header.fileProgram new_header.date = header.date new_header.fileAgency = header.fileAgency new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validRunBy new_header.markerName = header.markerName new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validMarkerName new_header.observer = header.observer new_header.agency = header.agency new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validObserver new_header.recNo = header.recNo new_header.recType = header.recType new_header.recVers = header.recVers new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validReceiver new_header.antNo = header.antNo new_header.antType = header.antType new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validAntennaType newAntPosition = gpstk.Triple(header.antennaPosition[0], header.antennaPosition[1], header.antennaPosition[2]) new_header.antennaPosition = newAntPosition new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validAntennaPosition newAntDelta = gpstk.Triple(header.antennaDeltaHEN[0], header.antennaDeltaHEN[1], header.antennaDeltaHEN[2]) new_header.antennaDeltaHEN = newAntDelta new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validAntennaDeltaHEN # This is kind of odd. The Rinex3ObsHeader can handle both V3 and V2 # formatted files. The two versions handle observation types differently. # - The first structure "mapObsTypes" holds the V3 definitions in a # "dictionary of lists" (or "map of vectors" in c++) # - The second structure "R2ObsTypes" holds the V2 definitions and is # stored as list of strings (or Vector of Strings in c++) # It's not clear whether either or both are necessary to write a file. # It DOES seem to be clear that both will be available after reading a file. for rinObsType in header.mapObsTypes: #print "Found obs-type:{}".format(rinObsType) newObsIds = [] for rinObsId in header.mapObsTypes[rinObsType]: #print "Found obs-id:{}".format(str(rinObsId)) #print " --type={} code={} band={}".format(rinObsId.type, rinObsId.code, rinObsId.band) newObsId = gpstk.RinexObsID(str(rinObsId)) newObsIds.append(newObsId) new_header.mapObsTypes[rinObsType] = tuple(newObsIds) new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validNumObs for rin_obs_id in header.R2ObsTypes: #print "Found obs-id:{}".format(rin_obs_id) new_header.R2ObsTypes.append(rin_obs_id) new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validNumObs # This creates a new CivilTime object that we can populate new_header.firstObs = gpstk.CivilTime() new_header.firstObs.year = header.firstObs.year new_header.firstObs.month = header.firstObs.month new_header.firstObs.day = header.firstObs.day new_header.firstObs.hour = header.firstObs.hour new_header.firstObs.minute = header.firstObs.minute new_header.firstObs.second = header.firstObs.second new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validFirstTime new_header.markerNumber = header.markerNumber new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validMarkerNumber new_header.interval = header.interval new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validInterval ##### # Unfortunately, sigStrengthUnit is tied to the wavelengthFactor property, # We cannot set the latter due to a missing SWIG Python adapter, and # because the same "validity flag" governs both, we can't output # sigStrengthUnit without inadvertently outputting a bogus wavelengthFactor. ##### #new_header.wavelengthFactor = header.wavelengthFactor #new_header.sigStrengthUnit = header.sigStrengthUnit #new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validSigStrengthUnit for comment in header.commentList: new_header.commentList.append(comment) new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validComment new_header.validEoH = True # This method is a huge hack to get around a problem in the Rinex3ObsData # writer. See the method for details. new_header = tweakInternalHeaderState(new_header) #print new_header processed_data = [] # Now we loop through all the epochs and process the data for each one for d in data: # This creates a new CommonTime object with the system set to GPS. timec = gpstk.CommonTime(gpstk.TimeSystem(gpstk.TimeSystem.GPS)) # This creates a new CommonTime object with the system set to GPS. mjd = int(d.time.getDays()) sod = float(d.time.getSecondOfDay()) timec.set(mjd, sod, gpstk.TimeSystem(gpstk.TimeSystem.GPS)) # Assign values to a new Rinex Obs Data object nd = gpstk.Rinex3ObsData() nd.time = timec nd.auxHeader = d.auxHeader nd.clockOffset = d.clockOffset nd.epochFlag = d.epochFlag nd.numSVs = d.numSVs for satkey in d.obs.keys(): newSatKey = gpstk.RinexSatID(satkey.toString()) satObss = d.obs[newSatKey] # satObss is a tuple of RinexDatum newSatObss = [] for satObs in satObss: #print "{} {} {} {}".format(satkey.toString(), satObs.data, satObs.lli, satObs.ssi) newSatObs = gpstk.RinexDatum() newSatObs.data = satObs.data newSatObs.lli = satObs.lli newSatObs.ssi = satObs.ssi newSatObss.append(newSatObs) nd.obs[newSatKey] = tuple(newSatObss) #print "O{}".format(d) #print "S{}".format(nd) processed_data.append(nd) gpstk.writeRinex3Obs(output_file, new_header, processed_data) print "Wrote output file: {}".format(output_file) # We can catch any custom gpstk exception like this: except gpstk.Exception as e: print e
timec = gpstk.CommonTime(gpstk.TimeSystem(gpstk.TimeSystem.GPS)) # This creates a new CommonTime object with the system set to GPS. mjd = int(d.time.getDays()) sod = float(d.time.getSecondOfDay()) timec.set(mjd, sod, gpstk.TimeSystem(gpstk.TimeSystem.GPS)) # Assign values to a new Rinex Obs Data object nd = gpstk.Rinex3ObsData() nd.time = timec nd.auxHeader = d.auxHeader nd.clockOffset = d.clockOffset nd.epochFlag= d.epochFlag nd.numSVs = d.numSVs for satkey in d.obs.keys(): newSatKey = gpstk.RinexSatID(satkey.toString()) satObss = d.obs[newSatKey] # satObss is a tuple of RinexDatum newSatObss = [] for satObs in satObss: #print "{} {} {} {}".format(satkey.toString(), satObs.data, satObs.lli, satObs.ssi) newSatObs = gpstk.RinexDatum() newSatObs.data = satObs.data newSatObs.lli = satObs.lli newSatObs.ssi = satObs.ssi newSatObss.append(newSatObs) nd.obs[newSatKey] = tuple(newSatObss) #print "O{}".format(d) #print "S{}".format(nd)
#!/usr/bin/env python """ 1. Extract pseudorange obs 2. compute biased multipath observation. """ from gpstk import C_MPS, GAMMA_GPS, L1_FREQ_GPS import gpstk rfn = gpstk.getPathData() + "/test_input_rinex2_obs_RinexObsFile.06o" # Make a GPSTk SatID used to find a specific satellite in the data svid = gpstk.RinexSatID(5, gpstk.SatID.systemGPS) try: header, data = gpstk.readRinex3Obs(rfn, strict=True) print(header) # Loop through all the epochs and process the data for each one for d in data: # Note that d is now a Rinex3ObsData # Check if the PRN is in view (by searching for it) if d.obs.find(svid) == d.obs.end(): print(gpstk.CivilTime(d.time), "svid", svid, "not in view") else: P1 = d.getObs(svid, "C1W", header).data P2 = d.getObs(svid, "C2W", header).data L1 = d.getObs(svid, "L1C", header).data mu = P1 - L1 * (C_MPS / L1_FREQ_GPS) - 2 * (P1 - P2) / (1 - GAMMA_GPS) print(gpstk.CivilTime(d.time), svid, "biased multipath", mu)