PyDateTime#

class cysgp4.PyDateTime(dt=None, init=True)#

Bases: object

Thin wrapper around sgp4 (C++) DateTime class.

Internally, DateTime objects store time on a linear scale, “ticks”, which is the number of micro-seconds since 1. January 0001, 00:00. For convenience, one can convert to and from Python datetime objects and Modified Julian Date (MJD), which is often used in astronomy.

For calculating the position of a satellite for a given observer (i.e., in the horizontal frame, Azimuth and Elevation), one needs the local mean sidereal time (derived from Greenwhich mean sidereal time), which can be queried using the lmst() and gmst() methods.

Parameters:
dtdatetime object, or None (default: None)

Construct the PyDateTime instance with a given Python datetime object, or - if None - use the current date and time (as given by utcnow())

initBoolean (default: True)

If set to true, the datetime object will ignore the dt parameter and set the internal ticks variable to 0. This is only useful for computationally heavy tasks.

Returns:
pydtPyDateTime object

Examples

There are several possibilities to create a PyDateTime object:

>>> from datetime import datetime
>>> from cysgp4 import PyDateTime

>>> # from Python's datetime
>>> dt = datetime(2019, 1, 1, 12, 13, 14)
>>> pydt = PyDateTime(dt)
>>> pydt
<PyDateTime: 2019-01-01 12:13:14.000000 UTC>

>>> # from Modified Julian Date
>>> mjd = 56458.123
>>> pydt = PyDateTime.from_mjd(mjd)
>>> pydt
<PyDateTime: 2013-06-15 02:57:07.199999 UTC>

>>> # from "Ticks"
>>> ticks = 58628880000000000  # aka MJD zero point
>>> pydt = PyDateTime.from_ticks(ticks)
>>> pydt
<PyDateTime: 1858-11-17 00:00:00.000000 UTC>

Accessing and Modifying the date and time is done via the following properties and methods:

>>> print(pydt.datetime)
1858-11-17 00:00:00
>>> pydt.datetime = datetime(2010, 5, 1, 0, 10, 20)

>>> print(pydt.mjd)
55317.00717592592
>>> pydt.mjd = 55489.01358

>>> print(pydt.ticks)
63423130773311999
>>> pydt.ticks = 63681941594000000

>>> observer_longitude = 6.67  # degrees
>>> print('GMST: {:9.6f} hours'.format(pydt.gmst()))
GMST:  4.959715 hours
>>> print('LMST: {:9.6f} hours'.format(pydt.lmst(observer_longitude)))
LMST:  5.076129 hours

One can also set the date and time manually with the set method.

Attributes Summary

datetime

datetime (see Class documentation).

mjd

MJD (see Class documentation).

ticks

Ticks (see Class documentation).

tle_epoch

Datetime in TLE epoch format.

Methods Summary

from_mjd(cls, double mjd)

Creates a new PyDateTime instance from MJD.

from_ticks(cls, int64_t ticks)

Creates a new PyDateTime instance from "ticks".

from_tle_epoch(cls, double tle_epoch)

Creates a new PyDateTime instance from TLE epoch format.

get_datetime_tuple(self)

gmst(self)

Greenwhich mean sidereal time (GMST) of current date/time.

lmst(self, obslon_deg)

Local mean sidereal time (LMST) of current date/time.

set(self, int year, int month, int day, ...)

Creates a new PyDateTime instance from given date and time.

Attributes Documentation

datetime#

datetime (see Class documentation).

mjd#

MJD (see Class documentation).

ticks#

Ticks (see Class documentation).

tle_epoch#

Datetime in TLE epoch format. See also from_tle_epoch.

Methods Documentation

classmethod from_mjd(cls, double mjd)#

Creates a new PyDateTime instance from MJD.

Modified Julian Date (MJD), is a timescale, which is often used in astronomy.

Parameters:
mjddouble

Modified Julian Date.

Returns:
pydtPyDateTime object

Examples

“from_mjd” is a classmethod:

>>> mjd = 56458.123
>>> pydt = PyDateTime.from_mjd(mjd)
>>> pydt
<PyDateTime: 2013-06-15 02:57:07.199999 UTC>
classmethod from_ticks(cls, int64_t ticks)#

Creates a new PyDateTime instance from “ticks”.

Internally, DateTime objects store time on a linear scale, “ticks”, which is the number of micro-seconds since 1. January 0001, 00:00.

Parameters:
ticksint64_t

Number of micro-seconds since 1. January 0001, 00:00.

Returns:
pydtPyDateTime object

Examples

“from_ticks” is a classmethod:

>>> ticks = 58628880000000000  # aka MJD zero point
>>> pydt = PyDateTime.from_ticks(ticks)
>>> pydt
<PyDateTime: 1858-11-17 00:00:00.000000 UTC>
classmethod from_tle_epoch(cls, double tle_epoch)#

Creates a new PyDateTime instance from TLE epoch format.

Note: TLE epochs have a very strange format: first two digits are the year, next three digits are the day from beginning of year, then the fraction of a day is given, e.g. 20180.25 would be 2020, day 180, 6 hours (probably UT as no timezone is mentioned). See also Wikipedia or Celestrak.

Corresponding year must be between 1957 and 2056.

Parameters:
tle_epochdouble

Datetime in TLE epoch format.

Returns:
pydtPyDateTime object

Examples

“from_tle_epoch” is a classmethod:

>>> tle_epoch = 19050.1
>>> pydt = PyDateTime.from_tle_epoch(tle_epoch)
>>> pydt
<PyDateTime: 2019-02-19 02:24:00.000000 UTC>
get_datetime_tuple(self)#
gmst(self)#

Greenwhich mean sidereal time (GMST) of current date/time.

Returns:
gmstfloat

Greenwhich mean sidereal time (GMST) in (fractional) hours.

lmst(self, obslon_deg)#

Local mean sidereal time (LMST) of current date/time.

Parameters:
obslon_degfloat

Geographic longitude of the observer.

Returns:
lmstfloat

Local mean sidereal time (LMST) in (fractional) hours.

set(self, int year, int month, int day, int hour, int minute, int second, int microsecond)#

Creates a new PyDateTime instance from given date and time.

Parameters:
yearint

Year of desired date.

monthint

Month of desired date.

dayint

Day of desired date.

hourint

Hours of desired time.

minuteint

Minutes of desired time.

secondint

Seconds of desired time.

microsecondint

Microseconds of desired time.