This 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 using nbdev. 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-in datetime.
This module is relatively straightfoward to use. The GPSTime objects are generated (using arbitrary numbers) by
gps_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 for gps_time2 is longer than a week. The GPSTime object will automatically adjust the week number and time of week to reasonable values.
gps_time2
Conversion
The GPSTime objects can also created from datetime.datetime objects
gps_time3 = GPSTime.from_datetime(datetime.datetime(2017, 9, 2, 13, 23, 12, 211423))
print(gps_time3)
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())}")
Operators
GPSTime has comparison operators defined (equality, less than, etc.). It also has addition and subtraction defined. In general, one can add/subtract either floats or other GPSTimes.
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}")
print(f"Addition (GPSTime): {gps_time2 + gps_time1}")
print(f"Subtraction (GPSTime): {gps_time2 - gps_time1}")
Formatting
As much as possible for jupyter notebooks, the black formatting standard will be used. To apply black to jupyter notebooks, the jupyter-black extension can be used.