Package: gps-time
gps_timeTools for handling time related to GPSThis module is used to represent GPS time and provide tools for handling it. The tools developed here were originally made in pure python, but were later converted to jupyter notebooks usingnbdev. The goal is to provide an absolute time representation for python that is easer to use for scientific computing and with higher resolution than the built-indatetime.InstallInstallation can be achieved usingpip, specificallypipinstallgps-timeHow to useThis module is relatively straightfoward to use. TheGPSTimeobjects are generated (using arbitrary numbers) bygps_time1 = GPSTime(week_number=1872, time_of_week=3324.654324324234324)
gps_time2 = GPSTime(week_number=1875, time_of_week=9890874.32)Notice that the time of week forgps_time2is longer than a week. TheGPSTimeobject will automatically adjust the week number and time of week to reasonable values.gps_time2GPSTime(week_number=1891, time_of_week=214074.3200000003)ConversionTheGPSTimeobjects can also created fromdatetime.datetimeobjectsgps_time3 = GPSTime.from_datetime(datetime.datetime(2017, 9, 2, 13, 23, 12, 211423))
print(gps_time3)GPSTime(week_number=1964, time_of_week=566592.211423)GPSTimecan likewise be converted todatetime.datetimeobject. However, one must be careful becausedatetime.datetimeobjects only preserve microsecond resolution. Converting fromGPSTimetodatetime.datetimecan lose information. The opposite conversion does not lose information.print(f"GPS Time: {gps_time1}")
print(f"Datetime: {gps_time1.to_datetime()}")
print("")
print(f"Lost Precision: {gps_time1 - GPSTime.from_datetime(gps_time1.to_datetime())}")GPS Time: GPSTime(week_number=1872, time_of_week=3324.6543243242345)
Datetime: 2015-11-22 00:55:24.654324

Lost Precision: 3.2423440643469803e-07OperatorsGPSTimehas comparison operators defined (equality, less than, etc.). It also has addition and subtraction defined. In general, one can add/subtract eitherfloats or otherGPSTimes.For floats, it is interpreted as a time shift in seconds (forward for addition, backward for subtraction). This operation accounts for the time of week. In-place addition and subtraction, i.e. the+=and-=operators are supported for floats.time_shift_seconds = 23431123.3243

print(f"Addition (float):    {gps_time2 + time_shift_seconds}")
print(f"Subtraction (float): {gps_time2 - time_shift_seconds}")Addition (float):    GPSTime(week_number=1930, time_of_week=57997.64429999888)
Subtraction (float): GPSTime(week_number=1852, time_of_week=370150.9957000017)Alternatively, addition and subtraction can be done using twoGPSTimeobjects. Subtraction finds the time difference in seconds (as a float). Addition essentially sums the week numbers and times of week. Notice that in-place addition and subtraction are not supported for twoGPSTimeobjects.print(f"Addition (GPSTime):    {gps_time2 + gps_time1}")
print(f"Subtraction (GPSTime): {gps_time2 - gps_time1}")Addition (GPSTime):    GPSTime(week_number=3763, time_of_week=217398.97432432455)
Subtraction (GPSTime): 11701949.665675675LicenseCopyright (2020) The Aerospace Corporation. All Rights ReservedThegps_timemodule releasded under the Apache2 license.Open Source LicensesThis module is built on thenbdevtemplate, which is used under the Apache2 license.FormattingAs much as possible for jupyter notebooks, theblackformatting standard will be used. To apply black to jupyter notebooks, thejupyter-blackextension can be used.