Git Product home page Git Product logo

gps_time's Introduction

gps_time

Tools for handling time related to GPS

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.

Install

Installation can be achieved using pip, specifically

pip install gps-time

How to use

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
GPSTime(week_number=1891, time_of_week=214074.3200000003)

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)
GPSTime(week_number=1964, time_of_week=566592.211423)

GPSTime can likewise be converted to datetime.datetime object. However, one must be careful because datetime.datetime objects only preserve microsecond resolution. Converting from GPSTime to datetime.datetime can 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-07

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}")
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 two GPSTime objects. 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 two GPSTime objects.

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.665675675

License

Copyright (2020) The Aerospace Corporation. All Rights Reserved

The gps_time module releasded under the Apache2 license.

Open Source Licenses

This module is built on the nbdev template, which is used under the Apache2 license.

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.

gps_time's People

Contributors

dependabot[bot] avatar davidallen353 avatar sonya-rags avatar

Stargazers

Antonio Valentino avatar  avatar Zachary Hoppinen avatar  avatar  avatar  avatar Kévin EYERMANN avatar Adrien Wehrlé  avatar X. Li avatar Pablo Settecase avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

gps_time's Issues

Update to nbdev v2

This module is built on nbdev v1 and the update to v2 breaks the build process. Update to nbdev v2

Issue when converting UTC to gps_time

When converting from UTC to gps_time using this library, I tried to verify against the convertors on following two sites, your results are different. The differences always match the timezone offset (I am in Dallas area). Looked into your source code, I think the _gps_epoch_datetime definition in datetime.py, should specify the timezone of "1980-01-06" as GMT-0, because that's the GPS time starting point.
https://www.andrews.edu/~tzs/timeconv/timedisplay.php
https://gwosc.org/gps/

New format in version 2.8.1 does not support loading from YAML files formatted from versions <2.8

Prior to version 2.8, the GPSTime class had attributes week_number and time_of_week. If stored in a YAML file, this would be stored as:

!!python/object:gps_time.core.GPSTime
    time_of_week: 23234.2
    week_number: 213

In version 2.8.1, the GPSTime class was changes to have attributes of week_number, seconds, and femtoseconds with time_of_week becoming a property with a setter to ensure existing code still works. However, if a GPSTime object is created using a YAML file for an older version of this library, it will not be instantiated properly and will lack the seconds and femtoseconds attributes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.