def all_kinds_of_time_array(ts): yield ts.utc(2020, 10, [8, 9]) yield ts.tai(2020, 10, [8, 9]) yield ts.tt(2020, 10, [8, 9]) yield ts.tdb(2020, 10, [8, 9]) yield ts.ut1(2020, 10, [8, 9]) jd = a(2459130.5, 2459131.5) yield ts.tai_jd(jd) yield ts.tt_jd(jd) yield ts.tdb_jd(jd) yield ts.ut1_jd(jd) yield Time(ts, jd) for jd, fraction in [ (a(2459130.5, 2459131.5), 0.25), (2459130.5, a(0.0, 0.25)), (a(2459130.5, 2459131.5), a(0.0, 0.25)), ]: yield ts.tai_jd(jd, fraction) yield ts.tt_jd(jd, fraction) yield ts.tdb_jd(jd, fraction) # yield ts.ut1_jd(jd, fraction) # not yet supported # We only support direct Time instantiation for the final case, # where jd and fraction are arrays that already agree in their # dimensions. yield Time(ts, jd, fraction)
def moon_phase_at(time: Time): time._nutation_angles = get_iau2000b(time) current_earth = earth.at(time) _, mlon, _ = current_earth.observe(moon).apparent().ecliptic_latlon( 'date') _, slon, _ = current_earth.observe(sun).apparent().ecliptic_latlon( 'date') return (((mlon.radians - slon.radians) // (tau / 8)) % 8).astype(int)
def build_legacy_delta_t(delta_t_recent): bundled = _cat( load_bundled_npy('morrison_stephenson_deltat.npy')[:, :22], load_bundled_npy('historic_deltat.npy'), ) recent_start_time = delta_t_recent[0, 0] i = np.searchsorted(bundled[0], recent_start_time) century = 36524.0 start_tt = bundled[0, 0] - century start_J = Time(None, start_tt).J end_tt = delta_t_recent[0, -1] + century end_J = Time(None, end_tt).J parabola = timelib.delta_t_parabola_morrison_stephenson_2004 delta_t_table = _cat( [[start_tt], [parabola(start_J)]], bundled[:, :i], delta_t_recent, [[end_tt], [parabola(end_J)]], ) return timelib.DeltaT(delta_t_table[0], delta_t_table[1], parabola)
def _get_month_start_end(self, start: Time, stop: Time = None) -> Tuple[Time, Month]: # input parameters validation if stop is None: stop = Time(self.time_scale, start.tt + 366.) else: if stop.tt < start.tt: raise ValueError("Stop time should be greater than start time") # first pass compute sun_pos every 6 hours for 1 year tframe = Time( self.time_scale, np.linspace(start.tt, stop.tt, int((stop.tt - start.tt) * 24 / 6))) sun_pos = self._compute_sun_pos(tframe) # convert degrees in increasing order mesha_crossing_idxs = [ x for x in np.argwhere(np.diff(sun_pos.degrees) < 0.).flatten() ] degrees = sun_pos.degrees for n, _ in enumerate(mesha_crossing_idxs): if n + 1 < len(mesha_crossing_idxs): degrees[mesha_crossing_idxs[n] + 1:mesha_crossing_idxs[n + 1]] += 360. * (n + 1) else: degrees[mesha_crossing_idxs[n] + 1:] += 360. * (n + 1) # model as spline interpolation problem y = tframe.tt x = degrees # get time for these crossings x_new = np.arange(np.ceil(x.min() / 30), np.ceil(x.max() / 30) + 1) * 30 interp_model = interpolate.splrep(x, y, s=0) y_new = interpolate.splev(x_new, interp_model, der=0) months = Month(Angle(degrees=x_new % 360)) times = Time(self.time_scale, y_new) return times, months
def _get_sun_rise_on_day(self, time: Time) -> Time: vfunc = np.vectorize(lambda x: x.date(), otypes=[date]) if len(time.shape) > 0: dates = vfunc(time.utc_datetime()) else: dates = vfunc([time.utc_datetime()]) output = [] for curr_date in dates: if curr_date not in self.sun_rise_cache.keys(): self._compute_sun_rise_sun_set( self.time_scale.utc(curr_date.year, curr_date.month, curr_date.day), self.time_scale.utc(curr_date.year, curr_date.month, curr_date.day + 1)) output.append(self.sun_rise_cache[curr_date].tt) return Time(self.time_scale, output)
def test_constellations(): lookup = load_constellation_map() assert lookup(position_of_radec(0, 0)) == 'Psc' assert lookup(position_of_radec(360, 90)) == 'UMi' # (4.65, 0) used to be in Orion, but, precession assert lookup(position_of_radec(4.65, 0)) == 'Eri' assert lookup(position_of_radec(4.75, 0.3)) == 'Ori' # exploit extend() bug, issue 547 B1875 = Time(None, julian_date_of_besselian_epoch(1875)) assert lookup(position_of_radec(18.1747, 39., epoch=B1875)) == 'Her' assert lookup(position_of_radec(18.1753, 39., epoch=B1875)) == 'Lyr' # Test vectorization. assert list( lookup(position_of_radec([4.65, 4.75], [0, 0.3])) ) == ['Eri', 'Ori']
run_benchmark(times, coordinate.radec) def bm_coordinate_to_apparent(times, t): coordinate = star.observe_from(earth(t)) run_benchmark(times, coordinate.apparent) def bm_coordinate_horizontal(times, t): ggr = earth.topos('75 W', '45 N', elevation_m=0.0) run_benchmark(times, ggr(t).observe(jupiter).apparent().horizontal) BENCHMARKS = ( BM(times=100, bm_fn=bm_earth_rotation_angle, t=array([T0, TA, TB])), BM(times=100, bm_fn=bm_star_observe_from, t=Time(tt=T0)), BM(times=100, bm_fn=bm_star_observe_from, t=Time(tt=TA)), BM(times=100, bm_fn=bm_star_observe_from, t=Time(tt=TB)), BM(times=100, bm_fn=bm_planet_observe_from, t=Time(tt=T0)), BM(times=100, bm_fn=bm_planet_observe_from, t=Time(tt=TA)), BM(times=100, bm_fn=bm_planet_observe_from, t=Time(tt=TB)), BM(times=100, bm_fn=bm_topo_planet_observe, t=Time(tt=T0)), BM(times=100, bm_fn=bm_topo_planet_observe, t=Time(tt=TA)), BM(times=100, bm_fn=bm_topo_planet_observe, t=Time(tt=TB)), BM(times=100, bm_fn=bm_earth_tilt, t=Time(tt=T0)), BM(times=100, bm_fn=bm_earth_tilt, t=Time(tt=TA)), BM(times=100, bm_fn=bm_earth_tilt, t=Time(tt=TB)), BM(times=100, bm_fn=bm_equation_of_the_equinoxes, t=array([T0, TA, TB])), BM(times=100, bm_fn=bm_fundamental_arguments, t=array([T0, TA, TB])), BM(times=100, bm_fn=bm_coordinate_to_astrometric, t=Time(tt=T0)), BM(times=100, bm_fn=bm_coordinate_to_astrometric, t=Time(tt=TA)),