# -*- coding: utf-8 -*- import datetime as dt import re from collections import namedtuple from datetime import date, datetime from numpy import (array, concatenate, cos, float_, interp, isnan, nan, ndarray, pi, rollaxis, searchsorted, sin, where, zeros_like) from time import strftime from .constants import ASEC2RAD, B1950, DAY_S, T0, tau from .descriptorlib import reify from .earthlib import sidereal_time, earth_rotation_angle from .framelib import ICRS_to_J2000 as B from .functions import mxm, mxmxm, _to_array, load_bundled_npy, rot_z from .nutationlib import ( build_nutation_matrix, equation_of_the_equinoxes_complimentary_terms, iau2000a_radians, mean_obliquity, ) from .precessionlib import compute_precession 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, 'timezone'): utc = dt.timezone.utc else: try: from pytz import utc except ImportError: # Lacking a full suite of timezones from pytz, we at least need a # time zone object for UTC. class UTC(dt.tzinfo): 'UTC' zero = dt.timedelta(0) def utcoffset(self, dt): return self.zero def tzname(self, dt): return 'UTC' def dst(self, dt): return self.zero utc = UTC() # Much of the following code is adapted from the USNO's "novas.c". _time_zero = dt.time() _half_minute = 30.0 / DAY_S _half_second = 0.5 / DAY_S _half_microsecond = 0.5e-6 / DAY_S _months = array(['Month zero', '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. Whenever you want to express a date in Skyfield, you need a `Timescale` that can translate between several different systems for expressing time. You will usually create a single `Timescale` at the beginning of your program, and use it every time you want to generate a specific `Time`: >>> from skyfield.api import load >>> ts = load.timescale(builtin=True) >>> t = ts.utc(1980, 3, 1, 9, 30) >>> t