Time
Time conversion support, primarily provided by the Time
class.
- class kete.time.Time(jd, scaling='tdb')
A representation of time, always in JD with TDB scaling.
Note that TDB is not the same as UTC, there is often about 60 seconds or more offset between these time formats. This class enables fast conversion to and from UTC however, via the
from_mjd()
, andfrom_iso()
. UTC can be recovered from this object throughutc_mjd()
,utc_jd()
, oriso()
.UTC Leap seconds cannot be predicted, as a result of this, UTC becomes a bit fuzzy when attempting to record future times. All conversion of future times ignores the possibility of leap seconds.
This representation and conversion tools make some small tradeoff for performance vs accuracy. Conversion between time scales is only accurate on the millisecond scale, however internal representation accuracy is on the microsecond scale.
TDB is treated as equivalent to TT and TCB, because these times only differ by less than milliseconds per century.
- Parameters:
jd – Julian Date in days.
scaling – Accepts ‘tdb’, ‘tai’, ‘utc’, ‘tcb’, and ‘tt’, but they are converted to TDB immediately.
- static from_iso(s)
Time from an ISO formatted string.
ISO formatted strings are assumed to be in UTC time scaling.
- Parameters:
s – ISO Formatted String.
- static from_mjd(mjd, scaling='tdb')
Time from a modified julian date.
- Parameters:
mjd – Modified Julian Date in days.
scaling – Accepts ‘tdb’, ‘tai’, ‘utc’, and ‘tt’, but they are converted to TDB immediately.
- static from_ymd(year, month, day)
Create time object from the Year, Month, and Day.
These times are assumed to be in UTC amd conversion is performed automatically.
- Parameters:
year – The Year, for example 2020
month – The Month as an integer, 0 = January etc.
day – The day as an integer or float.
- iso
Time in the UTC ISO time format.
- static j2000()
J2000 epoch time.
- jd
Julian Date in TDB scaled time. The difference between TT and TDB is never more than a few milliseconds per century, so these are treated as equivalent.
- local_time(timezone=None)
String representation of the Time in a localized time zone format. This will automatically take into account daylight savings time if necessary.
- Parameters:
timezone –
Optional, a
datetime.timezone
object which defines a time zone, if you are using python 3.9 or greater, then thezoneinfo
package in base python maintains a list of pre-defined timezones:from zoneinfo import available_timezones, ZoneInfo available_timezones() # List all available timezones timezone = ZoneInfo(“US/Pacific”) kete.Time.j2000().local_time(timezone)
- Return type:
str
- mjd
Modified Julian Date in TDB scaled time. The difference between TT and TDB is never more than a few milliseconds per century, so these are treated as equivalent.
- static now()
Time in the current time.
- to_datetime()
Convert time to a Datetime object.
- Return type:
datetime
- utc_jd
Julian Date in UTC scaled time.
- utc_mjd
Modified Julian Date in UTC scaled time.
- property year_float: float
Time as the UTC year in float form.
Note that Time is TDB Scaled, causing UTC to be a few seconds different.
>>> kete.Time.from_ymd(2010, 1, 1).year_float 2010.0
>>> kete.Time(2457754.5, scaling='utc').year_float 2017.0
2016 was a leap year, so 366 days instead of 365.
>>> kete.Time(2457754.5 - 366, scaling='utc').year_float 2016.0
- ymd
Return (year, month, day), where day is a float.
>>> kete.Time.from_ymd(2010, 1, 1).ymd (2010, 1, 1.0)
- kete.time.d_h_m_s_to_float_days(days=0, hours=0, minutes=0, seconds=0)
Convert floats of days, hours, minutes, and seconds into a single float in units of days.
>>> kete.time.d_h_m_s_to_float_days(1, 11, 59, 60) 1.5
- Parameters:
days (float)
hours (float)
minutes (float)
seconds (float)
- Return type:
float
- kete.time.days_in_year(year)
Return the number of days in the specified year, specifically for leap years.
>>> kete.time.days_in_year(2016) 366
>>> kete.time.days_in_year(2017) 365
- Parameters:
year (int) – Year as an int.
- Return type:
int