Epoch class#
The representation of an epoch, that is of a specific point in time, be it in the future or in the past, can be rather confusing.
In pykep we opted to offer a dedicated class called epoch to offer a simple interface and, under the hoods, interfacing
seamlessly both to the c++ std::chrono
library and to the python datetime module.
Note
In pykep the default Julian Date is the Modified Julian Date, defined as a float representing the number of days since the start of 2000-1-1.
Note
The date in pykep does account for leap seconds. If the user wishes to use the exact ISO 8601 representation of some epoch, also including leap seconds, he will have to account for the offset himself. As of of 2023 this may account to maximum 28 seconds. More info on leap seconds.
- class pykep.epoch(when: float, julian_type=MJD2000)#
Represents a specific point in time.
Constructs an epoch from a Julian Date.
- Args:
when (
float): the Julian Date (days since reference)julian_type (
julian_type): one of MJD2000, JD or MJD- Examples:
>>> import pykep as pk >>> pk.epoch(12.3, pk.epoch.julian_type.MJD2000) 2000-01-13T07:12:00.000000
- Alternative Constructor:
__init__( when: str, string_format = pk.epoch.string_format.ISO )
Constructs an epoch from a string.
- Args:
when (
str): a datestring_format (:class`~pykep.epoch.string_format`): string format.
- Examples:
>>> import pykep as pk >>> pk.epoch("2000-01-14T00:00:00.000001") 2000-01-14T00:00:00.000001
- Alternative Constructor:
__init__( when: datetime.datetime )
Constructs an epoch from a datetime object.
- Args:
when (
datetime.datetime): a date- Examples:
>>> import pykep as pk >>> from datetime import datetime >>> pk.epoch(datetime(year=2000, month=1, day=13)) 2000-01-13T00:00:00.000000
- property jd#
The Julian Date
- class julian_type#
Members:
MJD2000 : Modified Julian Date 2000.
MJD : Modified Julian Date.
JD : Julian Date.
- property mjd#
The Modified Julian Date
- property mjd2000#
The Modified Julian Date 2000
- static now()#
Returns a pykep.epoch with the current UTC date.
- class string_format#
Members:
ISO : ISO 8601 format for dates.
- to_datetime()#
Convert this
epochto a timezone-aware Pythondatetimein UTC.This method is added to the class via monkey-patching:
It interprets
self.mjd2000as a day count relative to the MJD2000 reference epoch (2000-01-01 00:00:00) in UTC.It converts days to seconds by multiplying by 86400.
It returns an aware
datetime(tzinfo=timezone.utc) computed as:datetime(2000, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=self.mjd2000 * 86400)
- Notes:
This is a civil-time conversion that assumes the MJD2000 epoch and the stored day count are meant to be interpreted in UTC. If your underlying time scale is TT/TAI (or you require leap-second-aware conversions), use an astronomy time library (e.g., Astropy) instead of naive arithmetic.
- Returns:
datetime: A timezone-aware
datetimein UTC corresponding to this epoch.