Exemple #1
0
def test_against_jpl_horizons():
    """Check that Astropy gives consistent results with the JPL Horizons example.

    The input parameters and reference results are taken from this page:
    (from the first row of the Results table at the bottom of that page)
    http://ssd.jpl.nasa.gov/?horizons_tutorial
    """
    print('NASA JPL')
    obstime = Time('1998-07-28 03:00')
    location = EarthLocation(lon=Angle('248.405300d'),
                             lat=Angle('31.9585d'),
                             height=2.06 * u.km)
    # No atmosphere
    altaz_frame = AltAz(obstime=obstime, location=location)

    altaz = SkyCoord('143.2970d 2.6223d', frame=altaz_frame)
    radec_actual = altaz.transform_to('icrs')
    print('Astropy: ', radec_actual)
    radec_expected = SkyCoord('19h24m55.01s -40d56m28.9s', frame='icrs')
    print('Source:  ', radec_expected)
    distance = radec_actual.separation(radec_expected).to('arcsec')
    #assert distance < 1 * u.arcsec

    # SAPPHiRE
    longitude = 248.405300
    latitude = 31.9585
    utc = datetime.datetime(1998, 7, 28, 3, 0)
    elevation = np.radians(2.6223)
    azi = np.radians(143.2970)
    gps = clock.utc_to_gps(calendar.timegm(utc.utctimetuple()))
    zenith, azimuth = celestial.horizontal_to_zenithazimuth(elevation, azi)
    ra, dec = celestial.zenithazimuth_to_equatorial(longitude, latitude, gps,
                                                    zenith, azimuth)

    print('SAPPHiRE: ra=%f, dec=%f' % (np.degrees(ra), np.degrees(dec)))
Exemple #2
0
    def test_against_jpl_horizons(self):
        """Check for consistent results with the JPL Horizons example.

        The input parameters and reference results are taken from this page:
        (from the first row of the Results table at the bottom of that page)
        http://ssd.jpl.nasa.gov/?horizons_tutorial

        """
        # NASA JPL
        ra_expected = np.radians(291.229208333)
        dec_expected = np.radians(-40.9413611111)

        # Astropy 1.0rc1
        ra_astropy = np.radians(291.229161499)
        dec_astropy = np.radians(-40.9413052259)

        # Data
        # Kitt Peak
        longitude = 248.405300
        latitude = 31.9585
        utc = datetime.datetime(1998, 7, 28, 3, 0)
        altitude = np.radians(2.6223)
        azi = np.radians(143.2970)

        # SAPPHiRE
        gps = clock.utc_to_gps(calendar.timegm(utc.utctimetuple()))
        zenith, azimuth = celestial.horizontal_to_zenithazimuth(altitude, azi)
        ra, dec = celestial.zenithazimuth_to_equatorial(
            longitude, latitude, gps, zenith, azimuth)

        self.assertAlmostEqual(ra, ra_expected, 3)
        self.assertAlmostEqual(ra, ra_astropy, 3)
        self.assertAlmostEqual(dec, dec_expected, 2)
        self.assertAlmostEqual(dec, dec_astropy, 2)
Exemple #3
0
    def test_against_pyephem(self):
        """Check for consistent results with one PyEphem example.

        PyEphem: http://rhodesmill.org/pyephem/

        See example input and output here:
        https://gist.github.com/zonca/1672906
        https://github.com/phn/pytpm/issues/2#issuecomment-3698679

        """
        # PyEphem
        ra_expected = np.radians(196.497518)
        dec_expected = np.radians(-4.569323)

        # Astropy 1.0rc1
        ra_astropy = np.radians(196.49537283)
        dec_astropy = np.radians(-4.5606942763)

        # Data
        longitude = base.sexagesimal_to_decimal(-109, -24, -53.1)
        latitude = base.sexagesimal_to_decimal(33, 41, 46.0)
        utc = datetime.datetime(2011, 9, 18, 8, 50)
        altitude = np.radians(-60.7665)
        azi = np.radians(6.8927)

        # SAPPHiRE
        gps = clock.utc_to_gps(calendar.timegm(utc.utctimetuple()))
        zenith, azimuth = celestial.horizontal_to_zenithazimuth(altitude, azi)
        ra, dec = celestial.zenithazimuth_to_equatorial(
            longitude, latitude, gps, zenith, azimuth)

        self.assertAlmostEqual(ra, ra_expected, 2)
        self.assertAlmostEqual(ra, ra_astropy, 2)
        self.assertAlmostEqual(dec, dec_expected, 2)
        self.assertAlmostEqual(dec, dec_astropy, 2)
    def test_against_pyephem(self):
        """Check for consistent results with one PyEphem example.

        PyEphem: http://rhodesmill.org/pyephem/

        See example input and output here:
        https://gist.github.com/zonca/1672906
        https://github.com/phn/pytpm/issues/2#issuecomment-3698679

        """
        # PyEphem
        ra_expected = np.radians(196.497518)
        dec_expected = np.radians(-4.569323)

        # Astropy 1.0rc1
        ra_astropy = np.radians(196.49537283)
        dec_astropy = np.radians(-4.5606942763)

        # Data
        longitude = base.sexagesimal_to_decimal(-109, -24, -53.1)
        latitude = base.sexagesimal_to_decimal(33, 41, 46.0)
        utc = datetime.datetime(2011, 9, 18, 8, 50)
        altitude = np.radians(-60.7665)
        azi = np.radians(6.8927)

        # SAPPHiRE
        gps = clock.utc_to_gps(calendar.timegm(utc.utctimetuple()))
        zenith, azimuth = celestial.horizontal_to_zenithazimuth(altitude, azi)
        ra, dec = celestial.zenithazimuth_to_equatorial(latitude, longitude,
                                                        gps, zenith, azimuth)

        self.assertAlmostEqual(ra, ra_expected, 2)
        self.assertAlmostEqual(ra, ra_astropy, 2)
        self.assertAlmostEqual(dec, dec_expected, 2)
        self.assertAlmostEqual(dec, dec_astropy, 2)
    def test_against_jpl_horizons(self):
        """Check for consistent results with the JPL Horizons example.

        The input parameters and reference results are taken from this page:
        (from the first row of the Results table at the bottom of that page)
        http://ssd.jpl.nasa.gov/?horizons_tutorial

        """
        # NASA JPL
        ra_expected = np.radians(291.229208333)
        dec_expected = np.radians(-40.9413611111)

        # Astropy 1.0rc1
        ra_astropy = np.radians(291.229161499)
        dec_astropy = np.radians(-40.9413052259)

        # Data
        # Kitt Peak
        longitude = 248.405300
        latitude = 31.9585
        utc = datetime.datetime(1998, 7, 28, 3, 0)
        altitude = np.radians(2.6223)
        azi = np.radians(143.2970)

        # SAPPHiRE
        gps = clock.utc_to_gps(calendar.timegm(utc.utctimetuple()))
        zenith, azimuth = celestial.horizontal_to_zenithazimuth(altitude, azi)
        ra, dec = celestial.zenithazimuth_to_equatorial(latitude, longitude,
                                                        gps, zenith, azimuth)

        self.assertAlmostEqual(ra, ra_expected, 3)
        self.assertAlmostEqual(ra, ra_astropy, 3)
        self.assertAlmostEqual(dec, dec_expected, 2)
        self.assertAlmostEqual(dec, dec_astropy, 2)
Exemple #6
0
def test_against_hor2eq():
    """Check that Astropy gives consistent results with an IDL hor2eq example.

    See EXAMPLE input and output here:
    http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hor2eq.pro
    """
    print('IDL hor2eq')
    # Observatory position for `kpno` from here:
    # http://idlastro.gsfc.nasa.gov/ftp/pro/astro/observatory.pro
    location = EarthLocation(lon=Angle('-111d36.0m'),
                             lat=Angle('31d57.8m'),
                             height=2120. * u.m)

    # obstime = Time('2041-12-26 05:00:00')
    obstime = Time(2466879.7083333, format='jd')
    # obstime += TimeDelta(-2, format='sec')

    altaz_frame = AltAz(obstime=obstime, location=location)
    altaz = SkyCoord('264d55m06s 37d54m41s', frame=altaz_frame)

    radec_frame = 'icrs'

    # The following transformation throws a warning about precision problems
    # because the observation date is in the future
    with catch_warnings() as _:
        radec_actual = altaz.transform_to(radec_frame)
    print('Astropy: ', radec_actual)

    radec_expected = SkyCoord('00h13m14.1s  +15d11m0.3s', frame=radec_frame)
    print('Source:  ', radec_expected)
    distance = radec_actual.separation(radec_expected).to('arcsec')
    # print(distance)

    # TODO: why is there a difference of 2.6 arcsec currently?
    # radec_expected = ra=3.30875 deg, dec=15.183416666666666 deg
    # radec_actual = ra=3.3094193224314625 deg, dec=15.183757021354532 deg
    # distance = 2.6285 arcsec
    #     assert distance < 5 * u.arcsec

    # SAPPHiRE
    longitude = -111.6
    latitude = 31.9633
    jd = 2466879.7083333
    elevation = (37, 54, 41)
    azi = (264, 55, 6)
    # lst = clock.gmst_to_lst(clock.juliandate_to_gmst(jd), longitude)
    # Matches  LAST = +03 53 53.6  in the hor2eq.pro
    gps = clock.utc_to_gps(
        calendar.timegm(clock.juliandate_to_utc(jd).utctimetuple()))
    zenith, azimuth = celestial.horizontal_to_zenithazimuth(
        np.radians(base.sexagesimal_to_decimal(*elevation)),
        np.radians(base.sexagesimal_to_decimal(*azi)))
    ra, dec = celestial.zenithazimuth_to_equatorial(longitude, latitude, gps,
                                                    zenith, azimuth)

    print('SAPPHiRE: ra=%f, dec=%f' % (np.degrees(ra), np.degrees(dec)))
Exemple #7
0
    def test_against_hor2eq(self):
        """Check for consistent results with an IDL hor2eq example.

        See EXAMPLE input and output here:
        http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hor2eq.pro

        Observatory position for ``kpno`` from here:
        http://idlastro.gsfc.nasa.gov/ftp/pro/astro/observatory.pro

        """
        # IDL hor2eq
        ra_expected = np.radians(3.30875)
        dec_expected = np.radians(15.183416666666666)

        # Astropy 1.0rc1
        ra_astropy = np.radians(3.3094193224314625)
        dec_astropy = np.radians(15.183757021354532)

        # KPNO observatory
        longitude = -111.6
        latitude = 31.9633

        # Observation time
        jd = 2466879.7083333

        # Altitude Azimuth
        altitude = (37, 54, 41)
        azi = (264, 55, 6)

        # lst = clock.gmst_to_lst(clock.juliandate_to_gmst(jd), longitude)
        # Matches  LAST = +03 53 53.6  in the hor2eq.pro

        # SAPPHiRE
        utc = calendar.timegm(clock.juliandate_to_utc(jd).utctimetuple())
        gps = clock.utc_to_gps(utc)
        zenith, azimuth = celestial.horizontal_to_zenithazimuth(
            np.radians(base.sexagesimal_to_decimal(*altitude)),
            np.radians(base.sexagesimal_to_decimal(*azi)))
        ra, dec = celestial.zenithazimuth_to_equatorial(latitude, longitude,
                                                        gps, zenith, azimuth)

        # Test eq_to_zenaz merely against IDL
        zencalc, azcalc = celestial.equatorial_to_zenithazimuth(
            latitude, longitude, gps, ra_expected, dec_expected)

        self.assertAlmostEqual(ra, ra_expected, 1)
        self.assertAlmostEqual(ra, ra_astropy, 1)
        self.assertAlmostEqual(dec, dec_expected, 2)
        self.assertAlmostEqual(dec, dec_astropy, 2)

        self.assertAlmostEqual(zencalc, zenith, 1)
        self.assertAlmostEqual(azcalc, azimuth, 2)
    def test_against_hor2eq(self):
        """Check for consistent results with an IDL hor2eq example.

        See EXAMPLE input and output here:
        http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hor2eq.pro

        Observatory position for ``kpno`` from here:
        http://idlastro.gsfc.nasa.gov/ftp/pro/astro/observatory.pro

        """
        # IDL hor2eq
        ra_expected = np.radians(3.30875)
        dec_expected = np.radians(15.183416666666666)

        # Astropy 1.0rc1
        ra_astropy = np.radians(3.3094193224314625)
        dec_astropy = np.radians(15.183757021354532)

        # KPNO observatory
        longitude = -111.6
        latitude = 31.9633

        # Observation time
        jd = 2466879.7083333

        # Altitude Azimuth
        altitude = (37, 54, 41)
        azi = (264, 55, 6)

        # lst = clock.gmst_to_lst(clock.juliandate_to_gmst(jd), longitude)
        # Matches  LAST = +03 53 53.6  in the hor2eq.pro

        # SAPPHiRE
        utc = calendar.timegm(clock.juliandate_to_utc(jd).utctimetuple())
        gps = clock.utc_to_gps(utc)
        zenith, azimuth = celestial.horizontal_to_zenithazimuth(
            np.radians(base.sexagesimal_to_decimal(*altitude)),
            np.radians(base.sexagesimal_to_decimal(*azi)))
        ra, dec = celestial.zenithazimuth_to_equatorial(
            latitude, longitude, gps, zenith, azimuth)

        # Test eq_to_zenaz merely against IDL
        zencalc, azcalc = celestial.equatorial_to_zenithazimuth(
            latitude, longitude, gps, ra_expected, dec_expected)

        self.assertAlmostEqual(ra, ra_expected, 1)
        self.assertAlmostEqual(ra, ra_astropy, 1)
        self.assertAlmostEqual(dec, dec_expected, 2)
        self.assertAlmostEqual(dec, dec_astropy, 2)

        self.assertAlmostEqual(zencalc, zenith, 1)
        self.assertAlmostEqual(azcalc, azimuth, 2)
Exemple #9
0
def datetime_to_gpstimestamp_nanoseconds(date):
    """Convert datetime objects to GPS timestamp and nanoseconds

    :param date: datetime object of the absolute datetime

    :return: GPS time as timestamp in seconds
             microsecond part of the datetime as nanoseconds

    """
    timestamp = clock.utc_to_gps(calendar.timegm(date.utctimetuple()))
    nanosecond = date.microsecond * 1000

    return timestamp, nanosecond
Exemple #10
0
def test_against_pyephem():
    """Check that Astropy gives consistent results with one PyEphem example.

    PyEphem: http://rhodesmill.org/pyephem/

    See example input and output here:
    https://gist.github.com/zonca/1672906
    https://github.com/phn/pytpm/issues/2#issuecomment-3698679
    """
    print('PyEphem')
    obstime = Time('2011-09-18 08:50:00')
    location = EarthLocation(lon=Angle('-109d24m53.1s'),
                             lat=Angle('33d41m46.0s'),
                             height=0. * u.m)
    # We are using the default pressure and temperature in PyEphem
    altaz_frame = AltAz(obstime=obstime, location=location)

    altaz = SkyCoord('6.8927d -60.7665d', frame=altaz_frame)
    radec_actual = altaz.transform_to('icrs')
    print('Astropy: ', radec_actual)

    radec_expected = SkyCoord('196.497518d -4.569323d', frame='icrs')  # EPHEM
    print('Source:  ', radec_expected)
    # radec_expected = SkyCoord('196.496220d -4.569390d', frame='icrs')  # HORIZON
    distance = radec_actual.separation(radec_expected).to('arcsec')
    # TODO: why is this difference so large?
    # It currently is: 31.45187984720655 arcsec
    assert distance < 1e3 * u.arcsec

    # Add assert on current Astropy result so that we notice if something changes
    radec_expected = SkyCoord('196.495372d -4.560694d', frame='icrs')
    distance = radec_actual.separation(radec_expected).to('arcsec')
    # Current value: 0.0031402822944751997 arcsec
    #assert distance < 1 * u.arcsec

    # SAPPHiRE
    longitude = base.sexagesimal_to_decimal(-109, -24, -53.1)
    latitude = base.sexagesimal_to_decimal(33, 41, 46.0)
    utc = datetime.datetime(2011, 9, 18, 8, 50, 00)
    elevation = np.radians(-60.7665)
    azi = np.radians(6.8927)
    gps = clock.utc_to_gps(calendar.timegm(utc.utctimetuple()))
    zenith, azimuth = celestial.horizontal_to_zenithazimuth(elevation, azi)
    ra, dec = celestial.zenithazimuth_to_equatorial(longitude, latitude, gps,
                                                    zenith, azimuth)

    print('SAPPHiRE: ra=%f, dec=%f' % (np.degrees(ra), np.degrees(dec)))
def store_hisparc_event(cursor, ts, ns):
    t = datetime.datetime.utcfromtimestamp(clock.utc_to_gps(ts))
    trace = 'xxx'
    l = len(trace)

    msg = struct.pack(
        ">BBHBBBBBHIiHhhhhhhii%ds%dshhhhhhii%ds%ds" % (l, l, l, l),
        2,  # central database
        2,  # number of devices
        l * 2,  # length of two traces
        t.second,
        t.minute,
        t.hour,
        t.day,
        t.month,
        t.year,
        int(ns),
        0,  # SLVtime
        0,  # Trigger pattern
        0,  # baseline1
        0,  # baseline2
        0,  # npeaks1
        0,  # npeaks2
        0,  # pulseheight1
        0,  # pulseheight2
        0,  # integral1
        0,  # integral2
        trace,
        trace,
        0,  # baseline3
        0,  # baseline4
        0,  # npeaks3
        0,  # npeaks4
        0,  # pulseheight3
        0,  # pulseheight4
        0,  # integral3
        0,  # integral4
        trace,
        trace)

    cursor.execute(
        "INSERT INTO message (device_id, message) VALUES "
        "(601, %s)", (msg, ))
Exemple #12
0
def store_hisparc_event(cursor, ts, ns):
    t = datetime.datetime.utcfromtimestamp(clock.utc_to_gps(ts))
    trace = 'xxx'
    l = len(trace)

    msg = struct.pack(">BBHBBBBBHIiHhhhhhhii%ds%dshhhhhhii%ds%ds" %
                      (l, l, l, l),
                      2,        # central database
                      2,        # number of devices
                      l * 2,    # length of two traces
                      t.second,
                      t.minute,
                      t.hour,
                      t.day,
                      t.month,
                      t.year,
                      int(ns),
                      0,        # SLVtime
                      0,        # Trigger pattern
                      0,        # baseline1
                      0,        # baseline2
                      0,        # npeaks1
                      0,        # npeaks2
                      0,        # pulseheight1
                      0,        # pulseheight2
                      0,        # integral1
                      0,        # integral2
                      trace, trace,
                      0,        # baseline3
                      0,        # baseline4
                      0,        # npeaks3
                      0,        # npeaks4
                      0,        # pulseheight3
                      0,        # pulseheight4
                      0,        # integral3
                      0,        # integral4
                      trace, trace)

    cursor.execute("INSERT INTO message (device_id, message) VALUES "
                   "(601, %s)", (msg,))
Exemple #13
0
 def test_utc_to_gps(self):
     for date, _, _ in self.combinations:
         self.assertEqual(clock.utc_to_gps(clock.utc_from_string(date)),
                          clock.gps_from_string(date))
Exemple #14
0
 def test_utc_to_gps(self):
     for date, _, _ in self.combinations:
         self.assertEqual(clock.utc_to_gps(clock.utc_from_string(date)),
                          clock.gps_from_string(date))
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