def test_properties(): t0 = time.Time(datetime(2000, 1, 1, 1, 1, 1), scale="utc", fmt="datetime") assert t0.year == 2000 assert t0.month == 1 assert t0.day == 1 assert t0.hour == 1 assert t0.minute == 1 assert t0.second == 1 assert t0.sec_of_day == 3661 assert t0.yydddsssss == "00:001:03661" assert t0.doy == 1 t1 = time.Time( [datetime(2000, 1, 1, 1, 1, 1), datetime(2001, 1, 1, 1, 1, 1)], scale="utc", fmt="datetime") assert (t1.year == np.array([2000, 2001])).all() assert (t1.month == np.array([1, 1])).all() assert (t1.day == np.array([1, 1])).all() assert (t1.hour == np.array([1, 1])).all() assert (t1.minute == np.array([1, 1])).all() assert (t1.second == np.array([1, 1])).all() assert (t1.sec_of_day == np.array([3661, 3661])).all() assert (t1.yydddsssss == np.array(["00:001:03661", "01:001:03661"])).all() assert (t1.doy == np.array([1, 1])).all()
def t_dt_utc_a2(): """Time, format datetime, scale utc, array entry""" return time.Time( [datetime(2015, 6, i + 1) for i in range(0, 2)], val2=[timedelta(hours=23, minutes=59, seconds=i) for i in range(0, 2)], scale="utc", fmt="datetime", )
def t_around_leapsecond(): """Epochs just before and after leap second on June 30th 2015""" return time.Time( [ datetime(2015, 6, 30) + timedelta(hours=23, minutes=59, seconds=i) for i in range(55, 65) ], scale="utc", fmt="datetime", )
def test_is_tests(): t = time.Time(datetime(2000, 1, 1, 1, 1, 1), scale="utc", fmt="datetime") dt = time.TimeDelta(30, scale="utc", fmt="seconds") assert time.Time.is_time(t) == True assert time.Time.is_time(dt) == False assert time.Time.is_time(8) == False assert time.Time.is_timedelta(t) == False assert time.Time.is_timedelta(dt) == True assert time.Time.is_timedelta(9) == False
def test_slice(t): scales = time.TimeArray._scales() formats = time.TimeArray._formats() for scale in scales.keys(): converted_t = getattr(t, scale) for fmt in formats: try: t_fmt = getattr(converted_t, fmt) print(f"Creating time time.Time({t_fmt}, {scale}, {fmt})") new_time_from_fmt = time.Time(t_fmt, scale=scale, fmt=fmt) except ValueError as err: # some formats are only available for certain scales assert converted_t.scale != "gps" and "gps" in fmt print( f"{fmt} is not a valid format for {converted_t.scale}. As expected." ) continue assert len(converted_t[0:2]) == 2 print(f"t.{scale}[0:2] == 2 OK") assert len(new_time_from_fmt[0:2]) == 2 print(f"t.{scale}.{fmt}[0:2] == 2 OK")
def apply_rates(coefficients, truncation_level, rundate): """Apply rates to coefficients for the gravitational field See IERS Conventions [4], equation (6.4). Args: coefficients: Dict containing tables of coefficients. truncation_level: Level of degree and order where coeffs are truncated. rundate: Start time of integration. Returns: None. Coefficients are changed in place. """ ref_date = time.Time(datetime(2000, 1, 1, 0, 0), fmt="datetime", scale="utc") years = (rundate.mjd - ref_date.mjd) / 365.25 if truncation_level >= 2: # Note that the C20- value is the tide free value on page 89 in [4], # not the zero tide value in Table 6.2. coefficients["C"][2, 0] = -0.484_165_31e-3 + 11.6e-12 * years if truncation_level >= 3: coefficients["C"][3, 0] += 4.9e-12 * years if truncation_level >= 4: coefficients["C"][4, 0] += 4.7e-12 * years
def t_jd_gps(): """Time, format julian date, scale gps""" return time.Time(2457448.5, scale="gps", fmt="jd")
def t_dt_utc_s2(): """Time, format datetime, scale utc, single entry""" return time.Time(datetime(2015, 6, 30), val2=timedelta(hours=23, minutes=59, seconds=20), scale="utc", fmt="datetime")
def t_dt_utc_sa(): """Time, format datetime, scale utc, array entry with single value""" return time.Time( [datetime(2015, 6, 30) + timedelta(hours=23, minutes=59, seconds=20)], scale="utc", fmt="datetime")
def test_empty_object(): time.Time([], scale="utc", fmt="datetime")
def get_gravity_coefficients(gravity_field, truncation_level, rundate): """Get coefficients for a gravity field The coefficient files come with normalized gravity coefficients. The coefficients are returned in a dict with keys `C` and `S`, each containing a table of coefficients `C[i, j]` and `S[i, j]`. Args: gravity_field: Name of gravity field. truncation_level: Level of degree and order where coeffs are truncated. rundate: Start time of integration. Returns: A dictionary containing C and S coefficients. """ log.info(f"Reading gravity field {gravity_field} up to degree and order {truncation_level}") try: gravity_parser = parsers.parse_key( "gravity_coefficients", file_vars=dict(gravity_field=gravity_field), num_degrees=truncation_level ) except FileNotFoundError: log.fatal(f"Unknown gravity field {gravity_field}, exiting!") gravity_coefficients = gravity_parser.as_dict() GM = gravity_parser.meta["earth_gravity_constant"] r = gravity_parser.meta["radius"] gr = dict() gr["C"] = np.zeros((truncation_level + 1, truncation_level + 1)) gr["S"] = np.zeros((truncation_level + 1, truncation_level + 1)) rundate = time.Time(rundate, fmt="datetime", scale="utc") if gravity_coefficients["gfc"].shape == (): gr["C"][gravity_coefficients["gfc"]["degree"], gravity_coefficients["gfc"]["order"]] = gravity_coefficients[ "gfc" ]["C"] gr["S"][gravity_coefficients["gfc"]["degree"], gravity_coefficients["gfc"]["order"]] = gravity_coefficients[ "gfc" ]["S"] else: for l in gravity_coefficients["gfc"]: gr["C"][l["degree"], l["order"]] = l["C"] gr["S"][l["degree"], l["order"]] = l["S"] if not "gfct" in gravity_coefficients: if gravity_field == "EGM2008": # Rates not contained in gravity file, apply rates from IERS apply_rates(gr, truncation_level, rundate) return gr, GM, r for l in gravity_coefficients["gfct"]: # TODO: Not sure what the xxxx in t0[yyyymmdd.xxxx] actually means (see e.g. EIGEN-6S4) # Maybe hours and minutes, but in that case the minutes should have been between 0..59. # They are not. # It doesn't seem to matter for the orbit determination process, # so I set hours = 0 for now t0 = time.Time( datetime(int(l["t0"][0:4]), int(l["t0"][4:6]), int(l["t0"][6:8]), int(l["t0"][9:11]), 0), scale="utc", fmt="datetime", ) t1 = time.Time( datetime(int(l["t1"][0:4]), int(l["t1"][4:6]), int(l["t1"][6:8]), int(l["t1"][9:11]), 0), scale="utc", fmt="datetime", ) if t0 <= rundate < t1: gr["C"][l["degree"], l["order"]] += l["C"] gr["S"][l["degree"], l["order"]] += l["S"] for l in gravity_coefficients["trnd"]: t0 = time.Time( datetime(int(l["t0"][0:4]), int(l["t0"][4:6]), int(l["t0"][6:8]), int(l["t0"][9:11]), 0), scale="utc", fmt="datetime", ) t1 = time.Time( datetime(int(l["t1"][0:4]), int(l["t1"][4:6]), int(l["t1"][6:8]), int(l["t1"][9:11]), 0), scale="utc", fmt="datetime", ) if t0 <= rundate < t1: years = (rundate.mjd - t0.mjd) / 365.25 gr["C"][l["degree"], l["order"]] += l["C"] * years gr["S"][l["degree"], l["order"]] += l["S"] * years for l in gravity_coefficients["asin"]: t0 = time.Time( datetime(int(l["t0"][0:4]), int(l["t0"][4:6]), int(l["t0"][6:8]), int(l["t0"][9:11]), 0), scale="utc", fmt="datetime", ) t1 = time.Time( datetime(int(l["t1"][0:4]), int(l["t1"][4:6]), int(l["t1"][6:8]), int(l["t1"][9:11]), 0), scale="utc", fmt="datetime", ) if t0 <= rundate < t1: years = (rundate.mjd - t0.mjd) / 365.25 gr["C"][l["degree"], l["order"]] += l["C"] * math.sin(2 * math.pi * years / l["period"]) gr["S"][l["degree"], l["order"]] += l["S"] * math.sin(2 * math.pi * years / l["period"]) for l in gravity_coefficients["acos"]: t0 = time.Time( datetime(int(l["t0"][0:4]), int(l["t0"][4:6]), int(l["t0"][6:8]), int(l["t0"][9:11]), 0), scale="utc", fmt="datetime", ) t1 = time.Time( datetime(int(l["t1"][0:4]), int(l["t1"][4:6]), int(l["t1"][6:8]), int(l["t1"][9:11]), 0), scale="utc", fmt="datetime", ) if t0 <= rundate < t1: years = (rundate.mjd - t0.mjd) / 365.25 gr["C"][l["degree"], l["order"]] += l["C"] * math.cos(2 * math.pi * years / l["period"]) gr["S"][l["degree"], l["order"]] += l["S"] * math.cos(2 * math.pi * years / l["period"]) return gr, GM, r