Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    def test_ensure_unix(self):
        # Check that ensure_unix is doing its job for both scalar and array
        # inputs

        dt = datetime(2016, 4, 3, 2, 1, 0)
        dt_list = [
            datetime(2016, 4, 3, 2, 1, 0),
            datetime(2016, 4, 3, 2, 1, 0)
        ]

        ut = ctime.datetime_to_unix(dt)
        ut_array = ctime.datetime_to_unix(dt_list)

        sf = ctime.unix_to_skyfield_time(ut)
        sf_array = ctime.unix_to_skyfield_time(ut_array)

        self.assertEqual(ctime.ensure_unix(dt), ut)
        self.assertEqual(ctime.ensure_unix(ut), ut)
        self.assertAlmostEqual(ctime.ensure_unix(sf), ut, 3)

        self.assertTrue((ctime.ensure_unix(dt_list) == ut_array).all())
        self.assertTrue((ctime.ensure_unix(ut_array) == ut_array).all())
        self.assertTrue(
            np.allclose(ctime.ensure_unix(sf_array),
                        ut_array,
                        rtol=1e-10,
                        atol=1e-4))
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def test_leap_seconds(self):
        # 'test_' removed from name to deactivate the test untill this can be
        # implemented.
        l_second_date = datetime(2009, 1, 1, 0, 0, 0)
        l_second_date = ctime.datetime_to_unix(l_second_date)
        before = l_second_date - 10000
        after = l_second_date + 10000
        after_after = l_second_date + 200
        self.assertEqual(ctime.leap_seconds_between(before, after), 1)
        self.assertEqual(ctime.leap_seconds_between(after, after_after), 0)

        # Check that a period including an extra leap seconds has two increments
        l_second2_date = ctime.datetime_to_unix(datetime(2012, 7, 1, 0, 0, 0))
        after2 = l_second2_date + 10000

        self.assertEqual(ctime.leap_seconds_between(before, after2), 2)
Ejemplo n.º 7
0
    def test_leap_seconds(self):
        # 'test_' removed from name to deactivate the test untill this can be
        # implemented.
        l_second_date = datetime(2009, 1, 1, 0, 0, 0)
        l_second_date = ctime.datetime_to_unix(l_second_date)
        before = l_second_date - 10000
        after = l_second_date + 10000
        after_after = l_second_date + 200
        self.assertEqual(ctime.leap_seconds_between(before, after), 1)
        self.assertEqual(ctime.leap_seconds_between(after, after_after), 0)

        # Check that a period including an extra leap seconds has two increments
        l_second2_date = ctime.datetime_to_unix(datetime(2012, 7, 1, 0, 0, 0))
        after2 = l_second2_date + 10000

        self.assertEqual(ctime.leap_seconds_between(before, after2), 2)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    def test_era_inverse(self):

        # Check a full forward/inverse cycle
        dt = datetime(2016, 4, 3, 2, 1, 0)
        t1 = ctime.datetime_to_unix(dt)
        era = ctime.unix_to_era(t1)
        t2 = ctime.era_to_unix(era, t1 - 3600.0)

        # Should be accurate at the 1 ms level
        self.assertAlmostEqual(t1, t2, 3)

        # Check a full forward/inverse cycle over a leap second boundary
        dt = datetime(2009, 1, 1, 3, 0, 0)
        t1 = ctime.datetime_to_unix(dt)
        era = ctime.unix_to_era(t1)
        t2 = ctime.era_to_unix(era, t1 - 6 * 3600.0)

        # Should be accurate at the 10 ms level
        self.assertAlmostEqual(t1, t2, 2)
Ejemplo n.º 11
0
    def test_era_inverse(self):

        # Check a full forward/inverse cycle
        dt = datetime(2016, 4, 3, 2, 1, 0)
        t1 = ctime.datetime_to_unix(dt)
        era = ctime.unix_to_era(t1)
        t2 = ctime.era_to_unix(era, t1 - 3600.0)

        # Should be accurate at the 1 ms level
        self.assertAlmostEqual(t1, t2, 3)

        # Check a full forward/inverse cycle over a leap second boundary
        dt = datetime(2009, 1, 1, 3, 0, 0)
        t1 = ctime.datetime_to_unix(dt)
        era = ctime.unix_to_era(t1)
        t2 = ctime.era_to_unix(era, t1 - 6 * 3600.0)

        # Should be accurate at the 10 ms level
        self.assertAlmostEqual(t1, t2, 2)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    def test_ensure_unix(self):
        # Check that ensure_unix is doing its job for both scalar and array
        # inputs

        dt = datetime(2016, 4, 3, 2, 1, 0)
        dt_list = [datetime(2016, 4, 3, 2, 1, 0), datetime(2016, 4, 3, 2, 1, 0)]

        ut = ctime.datetime_to_unix(dt)
        ut_array = ctime.datetime_to_unix(dt_list)

        sf = ctime.unix_to_skyfield_time(ut)
        sf_array = ctime.unix_to_skyfield_time(ut_array)

        self.assertEqual(ctime.ensure_unix(dt), ut)
        self.assertEqual(ctime.ensure_unix(ut), ut)
        self.assertAlmostEqual(ctime.ensure_unix(sf), ut, 3)

        self.assertTrue((ctime.ensure_unix(dt_list) == ut_array).all())
        self.assertTrue((ctime.ensure_unix(ut_array) == ut_array).all())
        self.assertTrue(np.allclose(ctime.ensure_unix(sf_array), ut_array, rtol=1e-10, atol=1e-4))
Ejemplo n.º 15
0
    def test_era_known(self):
        # Check an ERA calculated by caput.time against one calculated by
        # http://dc.zah.uni-heidelberg.de/apfs/times/q/form (note the latter
        # uses UT1, so we have maximum precision of 1s)

        dt = datetime(2016, 4, 3, 2, 1, 0)

        t1 = ctime.datetime_to_unix(dt)
        era1 = ctime.unix_to_era(t1)
        era2 = 221.0 + (52.0 + 50.828 / 60.0) / 60.0

        self.assertAlmostEqual(era1, era2, 3)

        # Test another one
        dt = datetime(2001, 2, 3, 4, 5, 6)

        t1 = ctime.datetime_to_unix(dt)
        era1 = ctime.unix_to_era(t1)
        era2 = 194.0 + (40.0 + 11.549 / 60.0) / 60.0

        self.assertAlmostEqual(era1, era2, 3)
Ejemplo n.º 16
0
    def test_era_known(self):
        # Check an ERA calculated by caput.time against one calculated by
        # http://dc.zah.uni-heidelberg.de/apfs/times/q/form (note the latter
        # uses UT1, so we have maximum precision of 1s)

        dt = datetime(2016, 4, 3, 2, 1, 0)

        t1 = ctime.datetime_to_unix(dt)
        era1 = ctime.unix_to_era(t1)
        era2 = 221.0 + (52.0 + 50.828 / 60.0) / 60.0

        self.assertAlmostEqual(era1, era2, 3)

        # Test another one
        dt = datetime(2001, 2, 3, 4, 5, 6)

        t1 = ctime.datetime_to_unix(dt)
        era1 = ctime.unix_to_era(t1)
        era2 = 194.0 + (40.0 + 11.549 / 60.0) / 60.0

        self.assertAlmostEqual(era1, era2, 3)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    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))
Ejemplo n.º 19
0
    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.e-5, atol=1.e-5))
Ejemplo n.º 20
0
    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)
Ejemplo n.º 21
0
def utc_lst_to_mjd(datestring, lst, obs=chime):
    """Convert datetime string and LST to corresponding modified Julian Day

    Parameters
    ----------
    datestring : string
        Date as YYYYMMDD-AAA, where AAA is one of [UTC, PST, PDT]
    lst : float
        Local sidereal time at DRAO (CHIME) in decimal hours
    obs : caput.Observer object

    Returns
    -------
    mjd : float
        Modified Julian Date corresponding to the given time.
    """
    return (unix_to_skyfield_time(
        obs.lsa_to_unix(lst * 360 / 24, datetime_to_unix(
            parse_date(datestring)))).tt - 2400000.5)
Ejemplo n.º 22
0
    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.e-5, atol=1.e-5))
        self.assertAlmostEqual(times[-1] - itimes[-1], 24 * 3600.0 * ctime.SIDEREAL_S, 1)
Ejemplo n.º 23
0
    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))
Ejemplo n.º 24
0
    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))
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    def test_datetime_to_unix(self):

        unix_time = time.time()
        dt = datetime.utcfromtimestamp(unix_time)
        new_unix_time = ctime.datetime_to_unix(dt)
        self.assertAlmostEqual(new_unix_time, unix_time, 5)
Ejemplo n.º 27
0
    def test_datetime_to_unix(self):

        unix_time = time.time()
        dt = datetime.utcfromtimestamp(unix_time)
        new_unix_time = ctime.datetime_to_unix(dt)
        self.assertAlmostEqual(new_unix_time, unix_time, 5)