PyDateTime#
- class cysgp4.PyDateTime(dt=None, init=True)#
Bases:
objectThin 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()andgmst()methods.- Parameters:
- dt
datetimeobject, orNone(default:None) Construct the
PyDateTimeinstance with a given Pythondatetimeobject, or - if None - use the current date and time (as given byutcnow())- init
Boolean(default:True) If set to true, the
datetimeobject will ignore thedtparameter and set the internal ticks variable to 0. This is only useful for computationally heavy tasks.
- dt
- Returns:
- pydt
PyDateTimeobject
- pydt
Examples
There are several possibilities to create a
PyDateTimeobject:>>> 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
setmethod.Attributes Summary
datetime (see Class documentation).
MJD (see Class documentation).
Ticks (see Class documentation).
Datetime in TLE epoch format.
Methods Summary
from_mjd(cls, double mjd)Creates a new
PyDateTimeinstance from MJD.from_ticks(cls, int64_t ticks)Creates a new
PyDateTimeinstance from "ticks".from_tle_epoch(cls, double tle_epoch)Creates a new
PyDateTimeinstance 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
PyDateTimeinstance 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
PyDateTimeinstance from MJD.Modified Julian Date (MJD), is a timescale, which is often used in astronomy.
- Parameters:
- mjd
double Modified Julian Date.
- mjd
- Returns:
- pydt
PyDateTimeobject
- pydt
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
PyDateTimeinstance 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:
- ticks
int64_t Number of micro-seconds since 1. January 0001, 00:00.
- ticks
- Returns:
- pydt
PyDateTimeobject
- pydt
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
PyDateTimeinstance 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_epoch
double Datetime in TLE epoch format.
- tle_epoch
- Returns:
- pydt
PyDateTimeobject
- pydt
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:
- gmst
float Greenwhich mean sidereal time (GMST) in (fractional) hours.
- gmst
- lmst(self, obslon_deg)#
Local mean sidereal time (LMST) of current date/time.
- set(self, int year, int month, int day, int hour, int minute, int second, int microsecond)#
Creates a new
PyDateTimeinstance from given date and time.