def test_pole_tides(self): t = gpstk.CivilTime(2000).toCommonTime() p = gpstk.Position(1000.0, 2000.0, 3000.0) x = 5.0 y = 10.0 trip = gpstk.poleTides(t, p, x, y) self.assertAlmostEqual(-0.03128457731297798, trip[0])
def test_moon(self): t = gpstk.CivilTime(2000).toCommonTime() # object way: pos = gpstk.MoonPosition().getPosition(t) self.assertAlmostEqual(-89651219.03579193, pos[0]) # functional way: pos = gpstk.moonPosition(t) self.assertAlmostEqual(-89651219.03579193, pos[0])
def test_sun(self): t = gpstk.CivilTime(2000).toCommonTime() # object way: pos = gpstk.SunPosition().getPosition(t) self.assertAlmostEqual(-136909966557.8461 , pos[0], places=3) # functional way: pos = gpstk.sunPosition(t) self.assertAlmostEqual(-136909966557.8461 , pos[0], places=3)
def main(): # Read in the rinex data header, data = gpstk.readRinex3Obs('rinex3obs_data.txt', strict=True) # Let's pretend we want to change something in the header # (otherwise this would be a two-line example!) header.receiverOffset = 47 # Now let's find the earliest and latest observations # function for how to compare Rinex3ObsData objects for min/max functions: timeFunction = lambda self: self.time earliest = min(data, key=timeFunction) latest = max(data, key=timeFunction) print 'Earliest time found:', gpstk.CivilTime(earliest.time) print 'Latest time found: ', gpstk.CivilTime(latest.time) # Now let's write it all back to a different file gpstk.writeRinex3Obs('rinex3obs_data.txt.new', header, data)
def test_readRinex3Obs(self): """Test reading entire rinex obs file and spot check the data""" header, data = gpstk.readRinex3Obs(args.input_dir + "/arlm200a.15o", strict=True) # Find the earliest and latest observations # function for how to compare Rinex3ObsData objects for min/max functions: timeFunction = lambda self: self.time earliest = min(data, key=timeFunction) latest = max(data, key=timeFunction) self.assertEqual( gpstk.CivilTime(2015, 7, 19, 0, 0, 0, gpstk.TimeSystem(gpstk.TimeSystem.GPS)), gpstk.CivilTime(earliest.time)) self.assertEqual( gpstk.CivilTime(2015, 7, 19, 0, 59, 30, gpstk.TimeSystem(gpstk.TimeSystem.GPS)), gpstk.CivilTime(latest.time))
def test_ephemeris(self): isblock9 = (lambda x: x.blockNum == 9) header, data = gpstk.readFIC('fic_data.txt', filterfunction=isblock9, strict=True) g = gpstk.GPSEphemerisStore() for d in data: ephem = gpstk.Rinex3NavData(d.toEngEphemeris()) g.addEphemeris(ephem) sat = gpstk.SatID(4, gpstk.SatID.systemGPS) sys = gpstk.TimeSystem(gpstk.TimeSystem.GPS) t = gpstk.CivilTime(2012, 11, 10, 2, 0, 0, sys) t = t.toCommonTime() xvt= g.getXvt(sat, t) self.assertAlmostEqual(6887268.768807452, xvt.x[0]) self.assertAlmostEqual(1036.3167828001287, xvt.v[1])
def test(self): a = gpstk.ANSITime() a.scanf("1234567789", "%K") a.setTimeSystem(gpstk.TimeSystem('GLO')) b = a.toCommonTime() c = gpstk.MJD(b) d = gpstk.GPSWeekSecond(b) e = gpstk.CivilTime(b) f = gpstk.QZSWeekSecond(b) self.assertEqual('1234567789 GLO', str(a)) self.assertEqual('2454876 84589000 0.000000000000000 GLO', str(b)) self.assertEqual('54875.979039352 GLO', str(c)) self.assertEqual('1518 516589.000000 GLO', str(d)) self.assertEqual('02/13/2009 23:29:49 GLO', str(e)) self.assertEqual('1518 516589.000000 GLO', str(f))
def test_almanac(self): isblock62 = (lambda x: x.blockNum == 62) header, data = gpstk.readFIC('fic_data.txt', filterfunction=isblock62, strict=True) self.assertEqual(96, len(data)) g = gpstk.GPSAlmanacStore() for d in data: orbit = d.toAlmOrbit() g.addAlmanac(orbit) sat = gpstk.SatID(4, gpstk.SatID.systemGPS) sys = gpstk.TimeSystem(gpstk.TimeSystem.GPS) t = gpstk.CivilTime(2012, 11, 10, 2, 0, 0, sys) t = t.toCommonTime() xvt= g.getXvt(sat, t) self.assertAlmostEqual(6888490.4337890595, xvt.x[0]) self.assertAlmostEqual(1036.1894772036476, xvt.v[1])
def test_standard_times(self): timeSystem = gpstk.TimeSystem('GPS') t1 = gpstk.UnixTime(1370983244, 659200) # in 2013 t1 = t1.toCommonTime() t1.setTimeSystem(timeSystem) t2 = gpstk.CivilTime(2012, 11, 6, 20, 40, 400) # in 2012 t2 = t2.toCommonTime() t2.setTimeSystem(timeSystem) self.assertEqual(False, t1 < t2) self.assertEqual(False, t1 <= t2) self.assertEqual(True, t1 > t2) self.assertEqual(True, t1 >= t2) self.assertEqual(False, t1 == t2) self.assertEqual(True, t1 != t2)
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 main(): # In the GPSTk there are multiple classes to manage time, depending # on the specific operation that we want to carry out. This modular # approach eases handling the many different time systems used in the # modern Global Navigation Satellite Systems. # Note, however, that in the GPSTk the unifying class to do time # Computations is the 'CommonTime' class. # Read current time from system clock systime = gpstk.SystemTime() # Convert to 'CommonTime', the standard way to handle time at GPSTk comtime = systime.toCommonTime() # This is the typical way to handle civil time civtime = gpstk.CivilTime(comtime) # The YDSTime class is very useful for common GNSS tasks ydstime = gpstk.YDSTime(comtime) # This is a typical class to handle time in GPS system gpstime = gpstk.GPSWeekSecond(comtime) # Class to handle Modified Julian Date mjd = gpstk.MJD(comtime) print "Hello world!" print " The current civil time is", civtime print " The current year is", ydstime.year print " The current day of year is", ydstime.doy print " The current second of day is", ydstime.sod print " The current full GPS week is", gpstime.week print " The current short GPS week is", gpstime.getModWeek() print " The current day of GPS week is", gpstime.getDayOfWeek() print " The current second of GPS week is", gpstime.sow print " The current Modified Julian Date is", mjd
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
python example2.py """ from __future__ import print_function import gpstk # Read in the rinex data # rfn = 'data/rinex3obs_data.txt' rfn = gpstk.getPathData() + '/test_input_rinex2_obs_RinexObsFile.06o' header, data = gpstk.readRinex3Obs(rfn, strict=True) # Let's pretend we want to change something in the header # (otherwise this would be a two-line example!) header.receiverOffset = 47 # Now let's find the earliest and latest observations # function for how to compare Rinex3ObsData objects for min/max functions: def timeFunction(self): return self.time earliest = min(data, key=timeFunction) latest = max(data, key=timeFunction) print('Earliest time found:', gpstk.CivilTime(earliest.time)) print('Latest time found:', gpstk.CivilTime(latest.time)) # Now let's write it all back to a different file gpstk.writeRinex3Obs(rfn + '.new', header, data)
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) except gpstk.InvalidRequest as e: print("InvalidRequest:", e) except gpstk.Exception as e: print(e)
""" An example of how to walk a RINEX data set and use SatID and ObsID, building an obsEpochMap of the data along the way. """ import gpstk fn = gpstk.getPathData() + '/arlm200z.15o' # read in header and get a generator for the data header, data = gpstk.readRinex3Obs(fn) print header oem = gpstk.ObsEpochMap() for d in data: print gpstk.CivilTime(d.time) oe = gpstk.ObsEpoch() oe.time = d.time for sv in d.obs.keys(): # sv is an SatID object print sv, epoch = d.obs[sv] soe = gpstk.SvObsEpoch() soe.svid = sv for i in range(len(epoch)): rinex2_obs_type = header.R2ObsTypes[i] oid = header.mapObsTypes['G'][i] print "{}({})={}".format(str(oid), rinex2_obs_type, epoch[i].data), soe[oid] = epoch[i].data oe[sv] = soe print
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
def daytostring(x): t = gpstk.CommonTime() t.set(x) return gpstk.CivilTime(t).printf(args.format)
def main(args=sys.argv[1:]): program_description = ('Converts from a given input time specification to ' 'other time formats. Include the quotation marks. ' 'All year values are four digit years.') parser = argparse.ArgumentParser(description=program_description) group = parser.add_mutually_exclusive_group() group.add_argument('-A', '--ansi', help='\"ANSI-Second\"') group.add_argument('-c', '--civil', help='\"Month(numeric) DayOfMonth Year Hour:Minute:Second\"') group.add_argument('-R', '--rinex', help='\"Year(2-digit) Month(numeric) DayOfMonth Hour Minute Second\"') group.add_argument('-o', '--ews', help='\"GPSEpoch 10bitGPSweek SecondOfWeek\"') group.add_argument('-f', '--ws', help='\"FullGPSWeek SecondOfWeek\"') group.add_argument('-w', '--wz', help='\"FullGPSWeek Zcount\"') group.add_argument('--z29', help='\"29bitZcount\"') group.add_argument('-Z', '--z32', help='\"32bitZcount\"') group.add_argument('-j', '--julian', help='\"JulianDate\"') group.add_argument('-m', '--mjd', help='\"ModifiedJulianDate\"') group.add_argument('-u', '--unixtime', help='\"UnixSeconds UnixMicroseconds\"') group.add_argument('-y', '--doy', help='\"Year DayOfYear SecondsOfDay\"') parser.add_argument('-F', '--output_format', help='Time format to use on output') parser.add_argument('-a', '--add_offset', type=int, nargs='+', help='add NUM seconds to specified time') parser.add_argument('-s', '--sub_offset', type=int, nargs='+', help='subtract NUM seconds to specified time') args = parser.parse_args(args) # these format keys must match the long arg names formats = { 'ansi': '%K', 'civil': '%m %d %Y %H:%M:%f', 'rinex': '%y %m %d %H %M %S', 'ews': '%E %G %g', 'ws': '%F %g', 'wz': '%F %Z', 'z29': '%E %c', 'z32': '%C', 'julian': '%J', 'mjd': '%Q', 'unixtime': '%U', 'doy': '%Y %j %s' } time_found = False for key in formats: input_time = getattr(args, key) # args.ansi, args.civil, etc. if input_time is not None: try: ct = gpstk.scanTime(input_time, formats[key]) time_found = True except gpstk.exceptions.InvalidRequest: raise gpstk.exceptions.InvalidRequest('Input could not be parsed.' '\nCheck formatt, ensure that the input is both valid and in quotes.' '\nCheck if time is too early/late for these formats.') if not time_found: ct = gpstk.SystemTime().toCommonTime() ct.setTimeSystem(gpstk.TimeSystem('GPS')) if args.add_offset is not None: for t in args.add_offset: ct.addSeconds(float(t)) if args.sub_offset is not None: for t in args.sub_offset: ct.addSeconds(-float(t)) if args.output_format is not None: print((gpstk.printTime(ct, args.output_format))) else: def left_align(str): spacing = ' ' * 8 return spacing + str.ljust(31) print('') # newline print(left_align('Month/Day/Year H:M:S'), end=' ') print(gpstk.CivilTime(ct)) print(left_align('Modified Julian Date'), end=' ') print(gpstk.MJD(ct)) print(left_align('GPSweek DayOfWeek SecOfWeek'), end=' ') print(gpstk.GPSWeekSecond(ct).printf('%G %w % 13.6g')) print(left_align('FullGPSweek Zcount'), end=' ') print(gpstk.GPSWeekZcount(ct).printf('%F % 6z')) print(left_align('Year DayOfYear SecondOfDay'), end=' ') print(gpstk.YDSTime(ct).printf('%Y %03j % 12.6s')) print(left_align('Unix: Second Microsecond'), end=' ') print(gpstk.UnixTime(ct).printf('%U % 6u')) print(left_align('Zcount: 29-bit (32-bit)'), end=' ') print(gpstk.GPSWeekZcount(ct).printf('%c (%C)')) print('') # newline
def main(args=sys.argv[1:]): program_description = ('This program takes 2 nav files and ' 'provides a plot of the magnitude of ' 'the difference of a given PRN ID.' 'Valid file types are ' + str(valid_types) + '.') parser = argparse.ArgumentParser(description=program_description) parser.add_argument('prn_id', type=int, help='The integer PRN ID you are interested in.') parser.add_argument('filetype1', help='Type for the first file.') parser.add_argument('filename1', help='File name for the first file.') parser.add_argument('filetype2', help='Type for the second file.') parser.add_argument('filename2', help='File name for the second file.') parser.add_argument('-v', '--verbose', action="store_true", help='Print output locations and error.') parser.add_argument('-n', '--noplot', action="store_true", help='Don\'t plot the file.') parser.add_argument('-d', '--drawdots', action="store_true", help='Matplotlib will not connect calculated data ' 'points in the plot') parser.add_argument('-t', '--timestep', type=int, default=300, help='Timestep, in seconds, between plot points.') parser.add_argument('-s', '--save', help='Save the image to <file>.') parser.add_argument('-f', '--format', default='%02H:%02M', help='Format for x time ticks.') args = parser.parse_args(args) def timestr(t): return str(gpstk.CivilTime(t)) def check(filetype, filename): if not filetype in valid_types: print 'Invalid filetype:', filetype print 'Valid choices are:' + str(valid_types) print 'Use the -h or --help flags for more information.\n' sys.exit() try: with open('filename'): pass except IOError as e: print e sys.exit(filename, 'cannot be read.\n') check(args.filetype1, args.filename1) check(args.filetype2, args.filename2) pos1 = read_data(args.filetype1, args.filename1, args.prn_id) pos2 = read_data(args.filetype2, args.filename2, args.prn_id) X = [] # list of x plot values Y = [] # list of y plot values starttime = max(pos1.first_time(), pos2.first_time()) endtime = min(pos1.last_time(), pos2.last_time()) if args.verbose: print (args.filename1 + ' ranges from ' + timestr(pos1.first_time()) + ' to ' + timestr(pos1.last_time())) print (args.filename2 + ' ranges from ' + timestr(pos2.first_time()) + ' to ' + timestr(pos2.last_time())) print 'Earliest time computable:', timestr(starttime) print 'Latest time computable:', timestr(endtime), '\n' sumErr = 0.0 sumErrSq = 0.0 n = 0 maxErr = 0.0 for t in gpstk.times(starttime, endtime, seconds=args.timestep): try: p1 = pos1.position(t) p2 = pos2.position(t) error = gpstk.range(p1, p2) maxErr = max(maxErr, error) X.append(t.getDays()) Y.append(error) if args.verbose: sumErr += error sumErrSq += error*error n += 1 print 'Time:', timestr(t) print '\tPosition 1:', p1 print '\tPosition 2:', p2 print '\tError:', error except gpstk.exceptions.InvalidRequest: if args.verbose: print 'Can\'t use data at:', timestr(t) if args.verbose and n > 0: print 'Arithmetic mean of error values: ', sumErr / n, 'm' print 'Root mean square of error values:', np.sqrt(sumErrSq / n), 'm' fig = plt.figure() title = ('Error for PRN ' + str(args.prn_id) + ' starting ' + gpstk.CivilTime(starttime).printf('%02m/%02d/%04Y %02H:%02M:%02S')) fig.suptitle(title, fontsize=14, fontweight='bold') ax = fig.add_subplot(111) ax.text(0.90, 0.90, args.filetype1 + ': ' + args.filename1 + '\n' + args.filetype2 + ': ' + args.filename2, verticalalignment='bottom', horizontalalignment='right', transform=ax.transAxes) ax.set_xlabel('Time') ax.set_ylabel('Error (meters)') if args.drawdots: plt.plot(X, Y, 'ro') else: plt.plot(X, Y, 'r') # sets the y scale plt.ylim([0, 2.0 * maxErr]) # converts common time day (float) -> string def daytostring(x): t = gpstk.CommonTime() t.set(x) return gpstk.CivilTime(t).printf(args.format) # sets the text shown per-pixel when viewed interactively def format_coord(x, y): return 'x=' + daytostring(x) + ', y=%1.4f'%(y) ax.format_coord = format_coord # sets x ticks to use the daytostring text locs, labels = plt.xticks() for i in range(len(locs)): labels[i] = daytostring(locs[i]) ax.set_xticklabels(labels) if not args.noplot: plt.show() if args.save is not None: fig.savefig(args.save)
def timestr(t): return str(gpstk.CivilTime(t))
python example2.py """ from __future__ import print_function import gpstk # Read in the rinex data # rfn = 'data/rinex3obs_data.txt' rfn = gpstk.getPathData() + "/test_input_rinex2_obs_RinexObsFile.06o" header, data = gpstk.readRinex3Obs(rfn, strict=True) # Let's pretend we want to change something in the header # (otherwise this would be a two-line example!) header.receiverOffset = 47 # Now let's find the earliest and latest observations # function for how to compare Rinex3ObsData objects for min/max functions: def timeFunction(self): return self.time earliest = min(data, key=timeFunction) latest = max(data, key=timeFunction) print("Earliest time found:", gpstk.CivilTime(earliest.time)) print("Latest time found:", gpstk.CivilTime(latest.time)) # Now let's write it all back to a different file gpstk.writeRinex3Obs(rfn + ".new", header, data)
""" An example of how to walk a RINEX data set and use SatID and ObsID, building an obsEpochMap of the data along the way. """ from __future__ import print_function import gpstk fn = gpstk.getPathData() + '/arlm200z.15o' # read in header and get a generator for the data header, data = gpstk.readRinex3Obs(fn) print(header) oem = gpstk.ObsEpochMap() for d in data: print(gpstk.CivilTime(d.time)) oe = gpstk.ObsEpoch() oe.time = d.time for sv in list(d.obs.keys()): # sv is an SatID object print(sv, end=' ') epoch = d.obs[sv] soe = gpstk.SvObsEpoch() soe.svid = sv for i in range(len(epoch)): rinex2_obs_type = header.R2ObsTypes[i] oid = header.mapObsTypes['G'][i] print("{}({})={}".format(oid, rinex2_obs_type, epoch[i].data), end=' ') soe[oid] = epoch[i].data oe[sv] = soe
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) except gpstk.InvalidRequest as e: print("InvalidRequest:", e) except gpstk.Exception as e: print(e)
def test_solid_tides(self): t = gpstk.CivilTime(2000).toCommonTime() p = gpstk.Position(1000.0, 2000.0, 3000.0) trip = gpstk.solidTides(t, p) self.assertAlmostEqual(-2.2479508782610997e-15, trip[0])
import argparse import gpstk parser = argparse.ArgumentParser() parser.add_argument('rinex2obs_filename') args = parser.parse_args() try: print 'Reading ' + args.rinex2obs_filename + '.' # read in header and get a generator for the data header, data = gpstk.readRinex3Obs(args.rinex2obs_filename) print header for d in data: civtime = gpstk.CivilTime(d.time) print civtime oe = gpstk.ObsEpoch() oe.time = d.time for sv in d.obs.keys(): print sv, epoch = d.obs[sv] soe = gpstk.SvObsEpoch() soe.svid = sv for i in range(len(epoch)): rinex2_obs_type = header.R2ObsTypes[i] oid = header.mapObsTypes['G'][i] print "{}({})={}".format(str(oid), rinex2_obs_type, epoch[i].data), soe[oid] = epoch[i].data oe[sv] = soe
def main(args=sys.argv[1:]): program_description = ("Converts from a given input time specification to " "other time formats. Include the quotation marks. " "All year values are four digit years.") parser = argparse.ArgumentParser(description=program_description) group = parser.add_mutually_exclusive_group() group.add_argument("-A", "--ansi", help='"ANSI-Second"') group.add_argument( "-c", "--civil", help='"Month(numeric) DayOfMonth Year Hour:Minute:Second"') group.add_argument( "-R", "--rinex", help='"Year(2-digit) Month(numeric) DayOfMonth Hour Minute Second"') group.add_argument("-o", "--ews", help='"GPSEpoch 10bitGPSweek SecondOfWeek"') group.add_argument("-f", "--ws", help='"FullGPSWeek SecondOfWeek"') group.add_argument("-w", "--wz", help='"FullGPSWeek Zcount"') group.add_argument("--z29", help='"29bitZcount"') group.add_argument("-Z", "--z32", help='"32bitZcount"') group.add_argument("-j", "--julian", help='"JulianDate"') group.add_argument("-m", "--mjd", help='"ModifiedJulianDate"') group.add_argument("-u", "--unixtime", help='"UnixSeconds UnixMicroseconds"') group.add_argument("-y", "--doy", help='"Year DayOfYear SecondsOfDay"') parser.add_argument("-F", "--output_format", help="Time format to use on output") parser.add_argument("-a", "--add_offset", type=int, nargs="+", help="add NUM seconds to specified time") parser.add_argument("-s", "--sub_offset", type=int, nargs="+", help="subtract NUM seconds to specified time") args = parser.parse_args(args) # these format keys must match the long arg names formats = { "ansi": "%K", "civil": "%m %d %Y %H:%M:%f", "rinex": "%y %m %d %H %M %S", "ews": "%E %G %g", "ws": "%F %g", "wz": "%F %Z", "z29": "%E %c", "z32": "%C", "julian": "%J", "mjd": "%Q", "unixtime": "%U", "doy": "%Y %j %s", } time_found = False for key in formats: input_time = getattr(args, key) # args.ansi, args.civil, etc. if input_time is not None: try: ct = gpstk.scanTime(input_time, formats[key]) time_found = True except gpstk.exceptions.InvalidRequest: raise gpstk.exceptions.InvalidRequest( "Input could not be parsed." "\nCheck formatt, ensure that the input is both valid and in quotes." "\nCheck if time is too early/late for these formats.") if not time_found: ct = gpstk.SystemTime().toCommonTime() ct.setTimeSystem(gpstk.TimeSystem("GPS")) if args.add_offset is not None: for t in args.add_offset: ct.addSeconds(float(t)) if args.sub_offset is not None: for t in args.sub_offset: ct.addSeconds(-float(t)) if args.output_format is not None: print((gpstk.printTime(ct, args.output_format))) else: def left_align(txt: str): spacing = " " * 8 return spacing + txt.ljust(31) print("") # newline print(left_align("Month/Day/Year H:M:S"), end=" ") print(gpstk.CivilTime(ct)) print(left_align("Modified Julian Date"), end=" ") print(gpstk.MJD(ct)) print(left_align("GPSweek DayOfWeek SecOfWeek"), end=" ") print(gpstk.GPSWeekSecond(ct).printf("%G %w % 13.6g")) print(left_align("FullGPSweek Zcount"), end=" ") print(gpstk.GPSWeekZcount(ct).printf("%F % 6z")) print(left_align("Year DayOfYear SecondOfDay"), end=" ") print(gpstk.YDSTime(ct).printf("%Y %03j % 12.6s")) print(left_align("Unix: Second Microsecond"), end=" ") print(gpstk.UnixTime(ct).printf("%U % 6u")) print(left_align("Zcount: 29-bit (32-bit)"), end=" ") print(gpstk.GPSWeekZcount(ct).printf("%c (%C)")) print("") # newline
# In the GPSTk there are multiple classes to manage time, depending # on the specific operation that we want to carry out. This modular # approach eases handling the many different time systems used in the # modern Global Navigation Satellite Systems. # Note, however, that in the GPSTk the unifying class to do time # Computations is the 'CommonTime' class. # Read current time from system clock systime = gpstk.SystemTime() # Convert to 'CommonTime', the standard way to handle time at GPSTk comtime = systime.toCommonTime() # This is the typical way to handle civil time civtime = gpstk.CivilTime(comtime) # The YDSTime class is very useful for common GNSS tasks ydstime = gpstk.YDSTime(comtime) # This is a typical class to handle time in GPS system gpstime = gpstk.GPSWeekSecond(comtime) # Class to handle Modified Julian Date mjd = gpstk.MJD(comtime) print("current civil time is", civtime) print("current year is", ydstime.year) print("current day of year is", ydstime.doy) print("current second of day is", ydstime.sod) print("current full GPS week is", gpstime.week)