def test_array(self): # Do a simple test of transit_RA in an array. Use the fact that the RA # advances predictably to predict the answers from skyfield import earthlib epoch = datetime(2000, 1, 1, 11, 58, 56) # Create an observer at an arbitrary location obs = ctime.Observer(118.3, 36.1) # Calculate LST t = ctime.unix_to_skyfield_time(ctime.datetime_to_unix(epoch)) gst = earthlib.sidereal_time(t) lst = (360.0 * gst / 24.0 + obs.longitude) % 360.0 # Drift rate should be very close to 1 degree/4minutes. # Fetch times calculated by ephem delta_deg = np.arange(20) delta_deg.shape = (5, 4) lst = lst + delta_deg # Calculate RA using transit_RA unix_epoch = ctime.datetime_to_unix(epoch) unix_times = unix_epoch + (delta_deg * 60 * 4 * ctime.SIDEREAL_S) TRA = obs.transit_RA(unix_times) # Compare self.assertTrue(np.allclose(lst, TRA, atol=0.02, rtol=1e-10))
def test_lsa_tra(self): # Near the epoch transit RA and LRA should be extremely close dt = datetime(2001, 2, 3, 4, 5, 6) t1 = ctime.datetime_to_unix(dt) obs = ctime.Observer(118.0, 31.0) lsa = obs.unix_to_lsa(t1) tra = obs.transit_RA(t1) self.assertAlmostEqual(lsa, tra, 5)
def test_reverse_lsa(self): # Check that the lsa_to_unix routine correctly inverts a call to # unix_to_lsa dt1 = datetime(2018, 3, 12, 1, 2, 3) t1 = ctime.datetime_to_unix(dt1) dt0 = datetime(2018, 3, 12) t0 = ctime.datetime_to_unix(dt0) obs = ctime.Observer(42.8, 4.7) lsa = obs.unix_to_lsa(t1) t2 = obs.lsa_to_unix(lsa, t0) self.assertAlmostEqual(t1, t2, 2)
def test_lsa_skyfield(self): # Check an lsa calculated by caput.time against one calculated by PyEphem from skyfield import earthlib, api dt = datetime(2014, 10, 2, 13, 4, 5) dt_utc = dt.replace(tzinfo=api.utc) t1 = ctime.datetime_to_unix(dt) obs = ctime.Observer(42.8, 4.7) lsa1 = obs.unix_to_lsa(t1) t = ctime.skyfield_wrapper.timescale.utc(dt_utc) lsa2 = (earthlib.earth_rotation_angle(t.ut1) * 360.0 + obs.longitude) % 360.0 self.assertAlmostEqual(lsa1, lsa2, 4)
def test_delta(self): delta = np.arange(0, 200000, 1000) # Seconds. # time.time() when I wrote this. No leap seconds for the next few # days. obs = ctime.Observer(118.3, 36.1) start = 1383679008.816173 times = start + delta start_ra = obs.transit_RA(start) ra = obs.transit_RA(times) delta_ra = ra - start_ra expected = delta / 3600.0 * 15.0 / ctime.SIDEREAL_S error = ((expected - delta_ra + 180.0) % 360) - 180 # Tolerance limited by stellar aberation (40" peak to peak). self.assertTrue(np.allclose(error, 0, atol=0.02))
def test_array(self): dt = datetime(2025, 1, 1, 12, 0, 0) t1 = ctime.datetime_to_unix(dt) obs = ctime.Observer(0.0, 0.0) times = t1 + np.linspace(0, 48 * 3600.0, 25) lsds = obs.unix_to_lsd(times) # Check that the vectorization works correctly for t, lsd in zip(times, lsds): self.assertEqual(lsd, obs.unix_to_lsd(t)) # Check the inverse is correct. itimes = obs.lsd_to_unix(lsds) self.assertTrue(np.allclose(times, itimes, rtol=1.0e-5, atol=1.0e-5))
def test_lrd(self): """Test Local Earth Rotation Day (LSD) definition.""" obs = ctime.Observer(113.2, 62.4) obs.lsd_start_day = ctime.datetime_to_unix(datetime(2014, 1, 2)) # Check the zero point is correct self.assertEqual(obs.lsd_zero(), obs.lsa_to_unix(0.0, obs.lsd_start_day)) dt = datetime(2017, 3, 4, 5, 6, 7) ut = ctime.datetime_to_unix(dt) # Check that the fractional part if equal to the transit RA self.assertAlmostEqual(360.0 * (obs.unix_to_lsd(ut) % 1.0), obs.unix_to_lsa(ut), places=4)
def test_epoch(self): from skyfield import earthlib # At the J2000 epoch, sidereal time and transit RA should be the same. epoch = datetime(2000, 1, 1, 11, 58, 56) # Create an observer at an arbitrary location obs = ctime.Observer(118.3, 36.1) # Calculate the transit_RA unix_epoch = ctime.datetime_to_unix(epoch) TRA = obs.transit_RA(unix_epoch) # Calculate LST t = ctime.unix_to_skyfield_time(unix_epoch) gst = earthlib.sidereal_time(t) lst = (360.0 * gst / 24.0 + obs.longitude) % 360.0 # Tolerance limited by stellar aberation self.assertTrue(np.allclose(lst, TRA, atol=0.01, rtol=1e-10))
def test_array(self): dt = datetime(2000, 1, 1, 12, 0, 0) t1 = ctime.datetime_to_unix(dt) obs = ctime.Observer(0.0, 0.0) times = t1 + np.linspace(0, 24 * 3600.0, 25) lsas = obs.unix_to_lsa(times) # Check that the vectorization works correctly for t, lsa in zip(times, lsas): self.assertEqual(lsa, obs.unix_to_lsa(t)) # Check the inverse is correct. The first 24 entries should be correct, # but the last one should be one sidereal day behind (because times[0] # was not in the correct sidereal day) itimes = obs.lsa_to_unix(lsas, times[0]) self.assertTrue( np.allclose(times[:-1], itimes[:-1], rtol=1.0e-5, atol=1.0e-5)) self.assertAlmostEqual(times[-1] - itimes[-1], 24 * 3600.0 * ctime.SIDEREAL_S, 1)