# -*- coding: utf-8 -*- import datetime as dt_module import re import sys from collections import namedtuple from datetime import date, datetime, timedelta from numpy import ( array, concatenate, cos, float64, int64, isnan, isinf, linspace, nan, ndarray, nonzero, pi, rollaxis, searchsorted, sin, where, zeros_like, ) from time import strftime, struct_time from ._compatibility import interp from .constants import ASEC2RAD, B1950, DAY_S, T0, tau from .curvelib import Splines, build_spline_given_ends from .descriptorlib import reify from .earthlib import sidereal_time, earth_rotation_angle from .framelib import ICRS_to_J2000 as B from .functions import (A, mxm, mxmxm, load_bundled_npy, rot_x, rot_y, rot_z, _to_array, _reconcile) from .nutationlib import ( build_nutation_matrix, equation_of_the_equinoxes_complimentary_terms, iau2000a_radians, mean_obliquity, ) from .precessionlib import compute_precession _EMPTY_TUPLE = () # since we use the value as a sentinel DAY_US = 86400000000.0 GREGORIAN_START = 2299161 GREGORIAN_START_ENGLAND = 2361222 _OLD_PYTHON = sys.version_info < (2, 7) def _cat(*args): return concatenate(args, axis=1) CalendarTuple = namedtuple('CalendarTuple', 'year month day hour minute second') class CalendarArray(ndarray): @property def year(self): return self[0] @property def month(self): return self[1] @property def day(self): return self[2] @property def hour(self): return self[3] @property def minute(self): return self[4] @property def second(self): return self[5] if hasattr(dt_module, 'timezone'): utc = dt_module.timezone.utc @staticmethod def _utcnow(): return datetime.now(utc) # datetime.UTC was not added until 3.11 else: class UTC(dt_module.tzinfo): 'UTC' zero = timedelta(0) def utcoffset(self, dt): return self.zero def tzname(self, dt): return 'UTC' def dst(self, dt): return self.zero utc = UTC() _utcnow = datetime.utcnow # Much of the following code is adapted from the USNO's "novas.c". _time_zero = dt_module.time(tzinfo=utc) MONTH_NAMES = A['0', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] tt_minus_tai = array(32.184 / DAY_S) class Timescale(object): """The data necessary to express dates in different timescales. A `Timescale` provides time objects with the data tables they need to translate between different time scales: the schedule of UTC leap seconds, and the value of ∆T over time. Most programs create a single `Timescale` which they use to build their `Time` objects: >>> from skyfield.api import load >>> ts = load.timescale() >>> t = ts.utc(1980, 3, 1, 9, 30) >>> t