Advertisement
goatbar

Cleanup of gps time conversion

Feb 7th, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. #!/usr/bin/python
  2. """Cleanup of http://csc.noaa.gov/digitalcoast/geozone/mapping-lidar."""
  3.  
  4. import datetime
  5. import fileinput
  6.  
  7. # Number of seconds between the start of unix time (Jan 1, 1970) and gps time (Jan 6, 1980).
  8. offset = 315964800
  9.  
  10.  
  11. def countleaps(gpsTime):
  12.   """Count number of leap seconds that have passed."""
  13.  
  14.   # a tuple of the gps times where leap seconds were added
  15.   leaps = (
  16.     46828800, 78364801, 109900802, 173059203, 252028804,
  17.     315187205, 346723206, 393984007, 425520008, 457056009,
  18.     504489610, 551750411, 599184012, 820108813, 914803214,
  19.     1025136015
  20.     )
  21.  
  22.   num_leaps = 0
  23.   for leap in leaps :  
  24.     if gpsTime >= leap:
  25.       leaps += 1
  26.  
  27.   return nleaps
  28.  
  29.  
  30. if __name__ == '__main__':
  31.   for line in fileinput.input():
  32.     # Please rename the first 2 variables.
  33.     what_is_this1, what_is_this2, values = line.split(' ')[:3]
  34.     gpstime = float(values[2])
  35.     gpstime += 1e9  # Unadjusted GPS time.
  36.     unixtime = gpstime + offset - countleaps(gpstime)
  37.     datetimestr = datetime.datetime.fromtimestamp(unixtime).strftime('%Y-%m-%d %H:%M:%S')
  38.    
  39.     print what_is_this1, what_is_this2, datetimestr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement