예제 #1
0
 def test_utc_to_lst_gmst(self):
     self.assertEqual(clock.utc_to_lst(datetime.datetime(2010, 12, 25), 0),
                      clock.utc_to_gmst(datetime.datetime(2010, 12, 25)))
     # Perhaps not perfect test, a few seconds of uncertainty exist..
     self.assertAlmostEqual(
         clock.utc_to_lst(datetime.datetime(2010, 12, 25), 0),
         clock.time_to_decimal(datetime.time(6, 13, 35, 852535)))
예제 #2
0
 def test_utc_to_lst_at_longitudes(self):
     self.assertAlmostEqual(clock.utc_to_lst(datetime.datetime(2010, 12, 25), 90),
                            clock.time_to_decimal(datetime.time(12, 13, 35, 852535)))
     self.assertAlmostEqual(clock.utc_to_lst(datetime.datetime(2010, 12, 25), 180),
                            clock.time_to_decimal(datetime.time(18, 13, 35, 852535)))
     self.assertAlmostEqual(clock.utc_to_lst(datetime.datetime(2010, 12, 25), 5),
                            clock.time_to_decimal(datetime.time(6, 33, 35, 852535)))
예제 #3
0
 def test_utc_to_lst_gmst(self):
     self.assertEqual(
         clock.utc_to_lst(datetime.datetime(2010, 12, 25), 0), clock.utc_to_gmst(datetime.datetime(2010, 12, 25))
     )
     # Perhaps not perfect test, a few seconds of uncertainty exist..
     self.assertAlmostEqual(
         clock.utc_to_lst(datetime.datetime(2010, 12, 25), 0),
         clock.time_to_decimal(datetime.time(6, 13, 35, 852535)),
     )
def oldvsnew_diagram():
    """
    Visual accuracy comparisons of old and new transformations.
    Compares the correlations between the transformations:
    equatorial_to_horizontal and equatorial_to_zenith_azimuth_astropy
    horizontal_to_equatorial and horizontal_to_zenith_azimuth_astropy
    Makes a histogram of the error differences
    between these two functions as well.
    The errors seem to be in the order of 1000 arcsec
    :return: None

    Ethan van Woerkom is responsible for the benchmarking functions;
    refer to him for when something is unclear
    """
    # make random frames, in correct angle range and from utc time 2000-2020
    frames = []
    # boxes for the four different transformation results
    etoha = []
    etoh = []
    htoe = []
    htoea = []
    straight = lambda x : x # straight trendline function

    # Create the data sets for eq to az
    for i in range(100):
        frames.append((r.uniform(-90, 90),
                       r.uniform(-180,180),
                       r.randint(946684800,1577836800),
                       r.uniform(0, 2 * np.pi),
                       r.uniform(-0.5 * np.pi, 0.5 * np.pi)))
    for i in frames:
        etoha.append(celestial.equatorial_to_zenithazimuth_astropy(i[0], i[1], i[2], [(i[3], i[4])])[0])
        etoh.append(celestial.equatorial_to_zenithazimuth(i[0], i[1], clock.utc_to_gps(i[2]), i[3], i[4]))
    # Data sets for hor to eq
    for i in frames:
        htoe.append(celestial.horizontal_to_equatorial(i[0],
        clock.utc_to_lst(datetime.datetime.utcfromtimestamp(i[2]), i[1]), i[4], i[3]))
        htoea.extend(celestial.horizontal_to_equatorial_astropy(i[0], i[1], i[2], [(i[3], i[4])]))

    # Make figs eq -> zenaz
    plt.figure(1)
    plt.suptitle('Zen/Az correlation in rads (equatorial_to_zenithazimuth)')

    zenrange = [0, np.pi]
    plt.subplot(211)
    plt.title('Zenith')
    plt.axis(zenrange*2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')

    # Make figure and add 1:1 trendline

    plt.plot([co[0] for co in etoha], [co[0] for co in etoh], 'r.', zenrange, straight(zenrange), '-')

    plt.subplot(212)
    plt.title('Azimuth')
    azrange = [-np.pi, np.pi]
    plt.axis(azrange*2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in etoha], [co[1] for co in etoh], 'b.', azrange, straight(azrange), '-')
    plt.tight_layout() # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(2)
    # Take diff. and convert to arcsec
    nieuw = (np.array(etoh) - np.array(etoha))
    nieuw *= 360 * 3600 / (2 * np.pi)

    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Zenith Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(3)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Azimuth Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(7)
    nieuw = np.array([angle_between(etoh[i][0], etoh[i][1], etoha[i][0], etoha[i][1])
                      for i in range(len(etoh))])
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist(nieuw, bins=20)
    plt.title('ZEN+AZ Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make figs hor - > eq

    plt.figure(4)
    plt.suptitle('RA/DEC  correlation in rads (horizontal_to_equatorial)')
    altrange = [-0.5 * np.pi, 0.5 * np.pi]
    plt.subplot(211)
    plt.title('Declination')
    plt.axis(altrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in htoea], [co[1] for co in htoe], 'r.', altrange, straight(altrange), '-')

    plt.subplot(212)
    plt.title('Right Ascension')
    azrange = [0, 2 * np.pi]
    plt.axis(azrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[0] for co in htoea], [co[0] for co in htoe], 'b.', azrange, straight(azrange), '-')
    plt.tight_layout()  # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(5)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Declination Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(6)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Right Ascension Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(8)
    nieuw = np.array([angle_between_horizontal(htoe[i][0], htoe[i][1], htoea[i][0], htoea[i][1])
                      for i in range(len(htoe))])
    # Take diff. and convert to arcsec
    nieuw /= 2 / np.pi * 360 * 3600
    plt.hist(nieuw, bins=20)
    plt.title('RA+DEC Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.show()
    return
def oldvsnew_diagram():
    """
    Visual accuracy comparisons of old and new transformations.
    Compares the correlations between the transformations:
    equatorial_to_horizontal and equatorial_to_zenith_azimuth_astropy
    horizontal_to_equatorial and horizontal_to_zenith_azimuth_astropy
    Makes a histogram of the error differences
    between these two functions as well.
    The errors seem to be in the order of 1000 arcsec
    :return: None

    Ethan van Woerkom is responsible for the benchmarking functions;
    refer to him for when something is unclear
    """
    # make random frames, in correct angle range and from utc time 2000-2020
    frames = []
    # boxes for the four different transformation results
    etoha = []
    etoh = []
    htoe = []
    htoea = []
    straight = lambda x: x  # straight trendline function

    # Create the data sets for eq to az
    for i in range(100):
        frames.append(
            (r.uniform(-90,
                       90), r.uniform(-180,
                                      180), r.randint(946684800, 1577836800),
             r.uniform(0, 2 * np.pi), r.uniform(-0.5 * np.pi, 0.5 * np.pi)))
    for i in frames:
        etoha.append(
            celestial.equatorial_to_zenithazimuth_astropy(
                i[0], i[1], i[2], [(i[3], i[4])])[0])
        etoh.append(
            celestial.equatorial_to_zenithazimuth(i[0], i[1],
                                                  clock.utc_to_gps(i[2]), i[3],
                                                  i[4]))
    # Data sets for hor to eq
    for i in frames:
        htoe.append(
            celestial.horizontal_to_equatorial(
                i[0],
                clock.utc_to_lst(datetime.datetime.utcfromtimestamp(i[2]),
                                 i[1]), i[4], i[3]))
        htoea.extend(
            celestial.horizontal_to_equatorial_astropy(i[0], i[1], i[2],
                                                       [(i[3], i[4])]))

    # Make figs eq -> zenaz
    plt.figure(1)
    plt.suptitle('Zen/Az correlation in rads (equatorial_to_zenithazimuth)')

    zenrange = [0, np.pi]
    plt.subplot(211)
    plt.title('Zenith')
    plt.axis(zenrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')

    # Make figure and add 1:1 trendline

    plt.plot([co[0] for co in etoha], [co[0] for co in etoh], 'r.', zenrange,
             straight(zenrange), '-')

    plt.subplot(212)
    plt.title('Azimuth')
    azrange = [-np.pi, np.pi]
    plt.axis(azrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in etoha], [co[1] for co in etoh], 'b.', azrange,
             straight(azrange), '-')
    plt.tight_layout()  # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(2)
    # Take diff. and convert to arcsec
    nieuw = (np.array(etoh) - np.array(etoha))
    nieuw *= 360 * 3600 / (2 * np.pi)

    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Zenith Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(3)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Azimuth Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(7)
    nieuw = np.array([
        angle_between(etoh[i][0], etoh[i][1], etoha[i][0], etoha[i][1])
        for i in range(len(etoh))
    ])
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist(nieuw, bins=20)
    plt.title('ZEN+AZ Old-New Error (equatorial_to_zenithazimuth)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make figs hor - > eq

    plt.figure(4)
    plt.suptitle('RA/DEC  correlation in rads (horizontal_to_equatorial)')
    altrange = [-0.5 * np.pi, 0.5 * np.pi]
    plt.subplot(211)
    plt.title('Declination')
    plt.axis(altrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[1] for co in htoea], [co[1] for co in htoe], 'r.', altrange,
             straight(altrange), '-')

    plt.subplot(212)
    plt.title('Right Ascension')
    azrange = [0, 2 * np.pi]
    plt.axis(azrange * 2)
    plt.xlabel('New (Astropy)')
    plt.ylabel('Old')
    # Make figure and add 1:1 trendline
    plt.plot([co[0] for co in htoea], [co[0] for co in htoe], 'b.', azrange,
             straight(azrange), '-')
    plt.tight_layout()  # Prevent titles merging
    plt.subplots_adjust(top=0.85)

    # Make histogram of differences
    plt.figure(5)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[1] for i in nieuw], bins=20)
    plt.title('Declination Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.figure(6)
    # Take diff. and convert to arcsec
    nieuw = (np.array(htoe) - np.array(htoea))
    nieuw *= 360 * 3600 / (2 * np.pi)
    plt.hist([i[0] for i in nieuw], bins=20)
    plt.title('Right Ascension Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    # Make histogram of differences using the absolute distance in arcsec
    # this graph has no wrapping issues
    plt.figure(8)
    nieuw = np.array([
        angle_between_horizontal(htoe[i][0], htoe[i][1], htoea[i][0],
                                 htoea[i][1]) for i in range(len(htoe))
    ])
    # Take diff. and convert to arcsec
    nieuw = nieuw / 2 / np.pi * 360 * 3600
    plt.hist(nieuw, bins=20)
    plt.title('RA+DEC Old-New Error (horizontal_to_equatorial)')
    plt.xlabel('Error (arcsec)')
    plt.ylabel('Counts')

    plt.show()
    return