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__()

x.__init__(…) initializes x; see help(type(x)) for signature

get_GPS_offset_for_date(timestamp=None)
get_current_GPS_offset()
is_valid()
leapseconds
valid_date
ait.core.dmc.getTimestampUTC() -> (ts_sec, ts_usec)

Returns the current UTC time in seconds and microseconds.

ait.core.dmc.getUTCDatetimeDOY(days=0, hours=0, minutes=0, seconds=0)

getUTCDatetimeDOY -> datetime

Returns the UTC current datetime with the input timedelta arguments (days, hours, minutes, seconds) added to current date. Returns ISO-8601 datetime format for day of year:

YYYY-DDDTHH:mm:ssZ
ait.core.dmc.tic()

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

ait.core.dmc.toGMST(dt=None)

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
ait.core.dmc.toGPSSeconds(timestamp) → integer

Converts the given Python datetime object to the number of seconds since the GPS Epoch (midnight on January 6th, 1980).

Examples:

>>> import datetime
>>> toGPSSeconds( datetime.datetime(1980, 1, 6) )
0
>>> toGPSSeconds( datetime.datetime(1980, 1, 7) )
86400
ait.core.dmc.toGPSWeekAndSecs(timestamp=None)

Converts the given UTC timestamp (defaults to the current time) to a two-tuple, (GPS week number, GPS seconds within the week).

ait.core.dmc.toJulian(dt=None)

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
ait.core.dmc.toLocalTime(seconds, microseconds=0) → datetime

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

Examples:

>>> toLocalTime(0)
datetime.datetime(1980, 1, 6, 0, 0)
>>> toLocalTime(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.

ait.core.dmc.totalSeconds(td) → float

Return the total number of seconds contained in the given Python datetime.timedelta object. Python 2.6 and earlier do not have timedelta.total_seconds().

Examples:

>>> totalSeconds( toLocalTime(86400.123) - toLocalTime(0.003) )
86400.12