ait.core.dmc module

AIT DeLorean Motor Company (DMC)

The ait.dmc module provides utilities to represent, translate, and manipulate time, building upon Python’s datetime and timedelta data types.

Many functions assume the GPS (and ISS) epoch: January 6, 1980 at midnight.

class ait.core.dmc.UTCLeapSeconds

Bases: object

__init__()

Initialize self. See help(type(self)) for accurate signature.

get_current_gps_offset()
get_gps_offset_for_date(timestamp=None)
is_valid()
leapseconds
valid_date
ait.core.dmc.get_timestamp_utc()

Returns the current UTC time in seconds and microseconds.

ait.core.dmc.get_utc_datetime_doy(days=0, hours=0, minutes=0, seconds=0) → str

Convert current UTC, plus some optional offset, to ISO 8601 DOY format

Arguments:
days (int): Optional days offset from current UTC time hours (int): Optional hours offset from current UTC time minutes (int): Optional minutes offset from current UTC time seconds (int): Optional seconds offset from current UTC time
Returns:
String formatted datetime of the form “%Y-%jT%H:%M:%SZ”
ait.core.dmc.rfc3339_str_to_datetime(datestr: str) → datetime.datetime

Convert RFC3339 string to datetime.

Convert a RFC3339-formated date string into a datetime object whil attempting to preserve timezone information.

Arguments:
datestr: The RFC3339-formated date string to convert to a datetime.
Returns:
The datetime object with preserved timezone information for the RFC3339
formatted string or None if no datestr is None.
ait.core.dmc.tic()

Records the current time for benchmarking purposes. See also toc().

ait.core.dmc.to_gmst(dt=None) → float

Convert datetime / Julian date to GMST.

Converts the given Python datetime or Julian date (float) to Greenwich Mean Sidereal Time (GMST) (in radians) using the formula from D.A. Vallado (2004).

See:
D.A. Vallado, Fundamentals of Astrodynamics and Applications, p. 192 http://books.google.com/books?id=PJLlWzMBKjkC&lpg=PA956&vq=192&pg=PA192
Arguments:
dt (datetime.datetime or float): The datetime or Julian date (as a float) to convert to radians.
ait.core.dmc.to_gps_seconds(timestamp) → int

Convert datetime object into number of second since GPS epoch.

Arguments:
timestamp (datetime.datetime): The datetime object to convert.
Return:
Number of seconds since the GPS epoch which the timestamp represents.

Examples:

>>> import datetime
>>> to_gps_seconds(datetime.datetime(1980, 1, 6))
0
>>> to_gps_seconds(datetime.datetime(1980, 1, 7))
86400
ait.core.dmc.to_gps_week_and_secs(timestamp=None) → Tuple[int, int]

Convert a timestamp (default current UTC) to GPS weeks / seconds

Arguments:
timestamp (optional): An optional datetimme value to convert. Current
UTC time is used if nothing is provided.
Returns:
A tuple of the form (GPS weeks, GPS seconds within week) for the timestamp
ait.core.dmc.to_julian(dt=None)

Convert datetime to a Julian date.

Converts a Python datetime to a Julian date, using the formula from Meesus (1991). This formula is reproduced in D.A. Vallado (2004).

See:
D.A. Vallado, Fundamentals of Astrodynamics and Applications, p. 187 http://books.google.com/books?id=PJLlWzMBKjkC&lpg=PA956&vq=187&pg=PA187
Arguments:
dt (datetime.datetime): The datetime to convert.
Returns:
The converted Julian date.
ait.core.dmc.to_local_time(seconds: int, microseconds: int = 0) → datetime.datetime

Convert seconds / microseconds since GPS epoch to local time.

Converts the given number of seconds since the GPS Epoch (midnight on January 6th, 1980) to this computer’s local time.

Arguments:

seconds: The number of seconds since the GPS epoch.

microseconds (optional): The number of microseconds of the seconds
since the GPS epoch.
Returns:
The datetime object defined as the GPS epoch + the supplied seconds
and microseconds.

Examples:

>>> to_local_time(0)
datetime.datetime(1980, 1, 6, 0, 0)
>>> to_local_time(25 * 86400)
datetime.datetime(1980, 1, 31, 0, 0)
ait.core.dmc.toc() → float | None

Returns the total elapsed seconds since the most recent tic(), or None if tic() was not called.

Examples:

>>> import time
>>> tic()
>>> time.sleep(1.2)
>>> elapsed = toc()
>>> assert abs(elapsed - 1.2) <= 1e-2

Note

The tic() and toc() functions are simplistic and may introduce significant overhead, especially in tight loops. Their use should be limited to one-off experiments and rough numbers. The Python profile package (i.e. ‘import profile’) should be used for serious and detailed profiling.