def convert_gps_time(gpsweek, gpsweekseconds, format='unix'):
"""
convert_gps_time :: (String -> String) -> Float
Converts a GPS time format (weeks + seconds since 6 Jan 1980) to a UNIX timestamp
(seconds since 1 Jan 1970) without correcting for UTC leap seconds.
Static values gps_delta and gpsweek_cf are defined by the below functions (optimization)
gps_delta is the time difference (in seconds) between UNIX time and GPS time.
gps_delta = (dt.datetime(1980, 1, 6) - dt.datetime(1970, 1, 1)).total_seconds()
gpsweek_cf is the coefficient to convert weeks to seconds
gpsweek_cf = 7 * 24 * 60 * 60 # 604800
:param gpsweek: Number of weeks since beginning of GPS time (1980-01-06 00:00:00)
:param gpsweekseconds: Number of seconds since the GPS week parameter
:return: (float) unix timestamp (number of seconds since 1970-01-01 00:00:00)
"""
# GPS time begins 1980 Jan 6 00:00, UNIX time begins 1970 Jan 1 00:00
gps_delta = 315964800.0
gpsweek_cf = 604800
if isinstance(gpsweek, pd.Series) and isinstance(gpsweekseconds, pd.Series):
gps_ticks = (gpsweek.astype('float64') * gpsweek_cf) + gpsweekseconds.astype('float64')
else:
gps_ticks = (float(gpsweek) * gpsweek_cf) + float(gpsweekseconds)
timestamp = gps_delta + gps_ticks
if format == 'unix':
return timestamp
elif format == 'datetime':
return datetime.datetime(1970, 1, 1) + pd.to_timedelta(timestamp, unit='s')
评论列表
文章目录