Exemple #1
0
    def test_pyephem_etoha(self):
        """Check celestial.equatorial_to_horizontal_astropy"""

        # This is the transform inputs
        eq = [(-39.34633914878846, -112.2277168069694, 1295503840,
               3.8662384455822716, -0.31222454326513827),
              (53.13143508448587, -49.24074935964933, 985619982,
               3.901575896592809, -0.3926720112815971),
              (48.02031016860923, -157.4023812557098, 1126251396,
               3.366278312183976, -1.3610394240813288)]
        # result of pyephem eq->hor
        altaz = [(2.175107479095459, -0.19537943601608276),
                 (5.25273323059082, -0.8308737874031067),
                 (3.4536221027374268, -0.894329845905304)]

        etoha_test = []

        # Produce equatorial_to_horizontal_astropy results
        for latitude, longitude, gps, ra, dec in eq:
            result = celestial.equatorial_to_horizontal_astropy(
                latitude, longitude, gps, [(ra, dec)])

            etoha_test.extend(result)

        # Check if all inputs are correct
        np.testing.assert_almost_equal(altaz, etoha_test, 4)
    def test_pyephem_etoha(self):
        """Check celestial.equatorial_to_horizontal_astropy"""

        # This is the transform inputs
        eq = [(-39.34633914878846, -112.2277168069694, 1295503840,
               3.8662384455822716, -0.31222454326513827),
              (53.13143508448587, -49.24074935964933, 985619982,
               3.901575896592809, -0.3926720112815971),
              (48.02031016860923, -157.4023812557098, 1126251396,
               3.366278312183976, -1.3610394240813288)]
        # result of pyephem eq->hor
        altaz = [(2.175107479095459, -0.19537943601608276),
                 (5.25273323059082, -0.8308737874031067),
                 (3.4536221027374268, -0.894329845905304)]

        etoha_test = []

        # Produce equatorial_to_horizontal_astropy results
        for latitude, longitude, gps, ra, dec in eq:
            result = celestial.equatorial_to_horizontal_astropy(
                latitude, longitude, gps, [(ra, dec)])

            etoha_test.extend(result)

        # Check if all inputs are correct
        np.testing.assert_almost_equal(altaz, etoha_test, 4)
def transformspeeds():
    print("Running speeds for 100.000 transformations of the astropy functions:")
    a = np.array([(0, 0)] * 100000)

    t0 = time.clock()

    celestial.equatorial_to_horizontal_astropy(0, 0, int(1e9), a)
    t1 = time.clock() - t0

    celestial.equatorial_to_zenithazimuth_astropy(0, 0, int(1e9), a)
    t2 = time.clock() - t0

    celestial.zenithazimuth_to_equatorial_astropy(0, 0, int(1e9), a)
    t3 = time.clock() - t0

    celestial.zenithazimuth_to_equatorial_astropy(0, 0, int(1e9), a)
    t4 = time.clock() - t0

    print("EQ->HO, EQ-> ZA, HO->EQ, ZA->EQ runtimes:")

    print(t1, t2, t3, t4)
def transformspeeds():
    print(
        "Running speeds for 100.000 transformations of the astropy functions:")
    a = np.array([(0, 0)] * 100000)

    t0 = time.clock()

    celestial.equatorial_to_horizontal_astropy(0, 0, int(1e9), a)
    t1 = time.clock() - t0

    celestial.equatorial_to_zenithazimuth_astropy(0, 0, int(1e9), a)
    t2 = time.clock() - t0

    celestial.zenithazimuth_to_equatorial_astropy(0, 0, int(1e9), a)
    t3 = time.clock() - t0

    celestial.zenithazimuth_to_equatorial_astropy(0, 0, int(1e9), a)
    t4 = time.clock() - t0

    print("EQ->HO, EQ-> ZA, HO->EQ, ZA->EQ runtimes:")

    print(t1, t2, t3, t4)
    def pyephem_comp():
        """
        This function compares the values from transformations done by our
        new astropy functions with the pyephem numbers. It generates
        correlation graphs between the new and old functions
        and histograms of the frequency of errors. Most errors do not much
        exceed 10 arcsec. There is complete correlation
        i.e. visually all points are on the same 1:1 line.
        These comparisons are done on the basis of 100 randomly generated
        points
        :return: None

        Ethan van Woerkom is responsible for the benchmarking functions;
        refer to him for when something is unclear
        """
        # Set up randoms equatorial J2000 bodies
        # that we will convert the RAs/Decs of.
        eq = [] # random frames to use
        for i in range(100):
            eq.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)))
        efemeq = [] # store pyephem transformations to equatorial
        altaz = [] # store pyephem transformations to altaz (horizontal)
        htoea = [] # store astropy transformations to equatorial
        etoha = [] # store astropy transformations to horizontal (altaz)
        for latitude, longitude, utc, ra, dec in eq:
            # Calculate altaz
            # Set observer for each case
            obs = ephem.Observer()
            obs.lat = str(latitude)
            obs.lon = str(longitude)
            obs.date = datetime.datetime.utcfromtimestamp(utc)
            obs.pressure = 0 # Crucial to prevent refraction correction!

            # Set body for each case
            coord = ephem.FixedBody()
            coord._ra = ra
            coord._dec = dec

            # Do calculation and add to list, it is necessary
            # to force the coords into radians
            coord.compute(obs)
            altaz.append((float(coord.az), float(coord.alt)))

            # Also calculate efemeq using eq
            result = obs.radec_of(ra, dec) # This is of course not ra,dec but
            # actually az, alt.

            efemeq.append((float(result[0]), float(result[1])))

        # Produce horizontal_to_equatorial_astropy results
        for latitude, longitude, utc, az, alt in eq:
            result = celestial.horizontal_to_equatorial_astropy(latitude, longitude, utc, [(az, alt)])
            htoea.extend(result)

        # Produce equatorial_to_horizontal_astropy results
        for latitude, longitude, utc, ra, dec in eq:
            result = celestial.equatorial_to_horizontal_astropy(latitude, longitude, utc, [(ra, dec)])
            etoha.extend(result)

        altdecrange = [-0.5 * np.pi, 0.5 * np.pi]
        azrarange = [0, 2 * np.pi]

        plt.figure(1)
        plt.suptitle('RA/Dec correlation Altaz->(Astropy/Pyephem)->RA,DEC')

        # Create RA correlation subplot
        plt.subplot(211)
        plt.title('RA')
        plt.axis(azrarange * 2)
        plt.xlabel('Pyephem RA (rad)')
        plt.ylabel('Astropy RA (rad)')

        # Plot RA correlation and trendline
        plt.plot([co[0] for co in efemeq], [co[0] for co in htoea], 'b.', azrarange, azrarange, '-')

        # DEC correlation subplot
        plt.subplot(212)
        plt.title('DEC')
        plt.axis(altdecrange*2)
        plt.xlabel('Pyephem DEC (rad)')
        plt.ylabel('Astropy DEC (rad)')

        # Plot DEC correlation and trendline
        plt.plot([co[1] for co in efemeq], [co[1] for co in htoea], 'r.', altdecrange, altdecrange, '-')

        # Formatting
        plt.tight_layout()
        plt.subplots_adjust(top=0.85)

        # Make RA error histogram
        plt.figure(2)
        plt.title('RA Error Altaz->(Astropy/Pyephem)->RA,DEC')

        nieuw = (np.array(htoea) - np.array(efemeq))
        # Get differences in arcsec
        nieuw *= 360 * 3600 / (2 * np.pi)

        plt.hist([co[0] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Make DEC error histogram
        plt.figure(3)
        plt.title('DEC Error Altaz->(Astropy/Pyephem)->RA,DEC')
        plt.hist([co[1] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Altaz comparison plot
        plt.figure(4)
        plt.suptitle('Alt/Az correlation RA,DEC->(pyephem/astropy)->Altaz')

        # Altitude
        plt.subplot(211)
        plt.title('Altitude')
        plt.axis(altdecrange*2)
        plt.xlabel('Pyephem Altitude (rad)')
        plt.ylabel('Astropy Altitude (rad')

        # Plot with trendline
        plt.plot([co[1] for co in altaz], [co[1] for co in etoha], 'b.', altdecrange, altdecrange, '-')

        # Azimuth
        plt.subplot(212)
        plt.title('Azimuth')
        plt.axis(azrarange*2)
        plt.xlabel('Pyephem Azimuth (rad)')
        plt.ylabel('Astropy Azimuth (rad)')

        plt.plot([co[0] for co in altaz], [co[0] for co in etoha], 'r.', azrarange, azrarange, '-')

        # Formatting
        plt.tight_layout()
        plt.subplots_adjust(top=0.85)

        # Alt error histogram
        plt.figure(5)
        plt.title('Altitude Error RA,DEC->(pyephem/astropy)->Altaz')
        nieuw = (np.array(etoha) - np.array(altaz))
        nieuw *= 360 * 3600 / (2 * np.pi)
        plt.hist([co[1] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Az error histogram
        plt.figure(6)
        plt.title('Azimuth Error RA,DEC->(pyephem/astropy)->Altaz')
        plt.hist([co[0] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Make histograms of differences using the absolute distance in arcsec
        # these graphs have no wrapping issues

        plt.figure(7)
        nieuw = np.array([angle_between_horizontal(altaz[i][0], altaz[i][1], etoha[i][0], etoha[i][1])
                          for i in range(len(etoha))])
        nieuw *= 360 * 3600 / (2 * np.pi)
        plt.hist(nieuw, bins=20)
        plt.title('Alt+Azi Error RA,DEC->(pyephem/astropy)->Altaz')
        plt.xlabel('Error (arcsec)')
        plt.ylabel('Counts')

        plt.figure(8)
        nieuw = np.array([angle_between_horizontal(efemeq[i][0], efemeq[i][1], htoea[i][0], htoea[i][1])
                          for i in range(len(htoea))])
        # Take difference and convert to arcsec
        nieuw *= 360 * 3600 / (2 * np.pi)

        plt.hist(nieuw, bins=20)
        plt.title('RA+DEC Error Altaz->(pyephem/astropy)->RA,DEC')
        plt.xlabel('Error (arcsec)')
        plt.ylabel('Counts')

        # Done; output
        plt.show()
    def pyephem_comp():
        """
        This function compares the values from transformations done by our
        new astropy functions with the pyephem numbers. It generates
        correlation graphs between the new and old functions
        and histograms of the frequency of errors. Most errors do not much
        exceed 10 arcsec. There is complete correlation
        i.e. visually all points are on the same 1:1 line.
        These comparisons are done on the basis of 100 randomly generated
        points
        :return: None

        Ethan van Woerkom is responsible for the benchmarking functions;
        refer to him for when something is unclear
        """
        # Set up randoms equatorial J2000 bodies
        # that we will convert the RAs/Decs of.
        eq = []  # random frames to use
        for i in range(100):
            eq.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)))
        efemeq = []  # store pyephem transformations to equatorial
        altaz = []  # store pyephem transformations to altaz (horizontal)
        htoea = []  # store astropy transformations to equatorial
        etoha = []  # store astropy transformations to horizontal (altaz)
        for latitude, longitude, utc, ra, dec in eq:
            # Calculate altaz
            # Set observer for each case
            obs = ephem.Observer()
            obs.lat = str(latitude)
            obs.lon = str(longitude)
            obs.date = datetime.datetime.utcfromtimestamp(utc)
            obs.pressure = 0  # Crucial to prevent refraction correction!

            # Set body for each case
            coord = ephem.FixedBody()
            coord._ra = ra
            coord._dec = dec

            # Do calculation and add to list, it is necessary
            # to force the coords into radians
            coord.compute(obs)
            altaz.append((float(coord.az), float(coord.alt)))

            # Also calculate efemeq using eq
            result = obs.radec_of(ra, dec)  # This is of course not ra,dec but
            # actually az, alt.

            efemeq.append((float(result[0]), float(result[1])))

        # Produce horizontal_to_equatorial_astropy results
        for latitude, longitude, utc, az, alt in eq:
            result = celestial.horizontal_to_equatorial_astropy(
                latitude, longitude, utc, [(az, alt)])
            htoea.extend(result)

        # Produce equatorial_to_horizontal_astropy results
        for latitude, longitude, utc, ra, dec in eq:
            result = celestial.equatorial_to_horizontal_astropy(
                latitude, longitude, utc, [(ra, dec)])
            etoha.extend(result)

        altdecrange = [-0.5 * np.pi, 0.5 * np.pi]
        azrarange = [0, 2 * np.pi]

        plt.figure(1)
        plt.suptitle('RA/Dec correlation Altaz->(Astropy/Pyephem)->RA,DEC')

        # Create RA correlation subplot
        plt.subplot(211)
        plt.title('RA')
        plt.axis(azrarange * 2)
        plt.xlabel('Pyephem RA (rad)')
        plt.ylabel('Astropy RA (rad)')

        # Plot RA correlation and trendline
        plt.plot([co[0] for co in efemeq], [co[0] for co in htoea], 'b.',
                 azrarange, azrarange, '-')

        # DEC correlation subplot
        plt.subplot(212)
        plt.title('DEC')
        plt.axis(altdecrange * 2)
        plt.xlabel('Pyephem DEC (rad)')
        plt.ylabel('Astropy DEC (rad)')

        # Plot DEC correlation and trendline
        plt.plot([co[1] for co in efemeq], [co[1] for co in htoea], 'r.',
                 altdecrange, altdecrange, '-')

        # Formatting
        plt.tight_layout()
        plt.subplots_adjust(top=0.85)

        # Make RA error histogram
        plt.figure(2)
        plt.title('RA Error Altaz->(Astropy/Pyephem)->RA,DEC')

        nieuw = (np.array(htoea) - np.array(efemeq))
        # Get differences in arcsec
        nieuw *= 360 * 3600 / (2 * np.pi)

        plt.hist([co[0] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Make DEC error histogram
        plt.figure(3)
        plt.title('DEC Error Altaz->(Astropy/Pyephem)->RA,DEC')
        plt.hist([co[1] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Altaz comparison plot
        plt.figure(4)
        plt.suptitle('Alt/Az correlation RA,DEC->(pyephem/astropy)->Altaz')

        # Altitude
        plt.subplot(211)
        plt.title('Altitude')
        plt.axis(altdecrange * 2)
        plt.xlabel('Pyephem Altitude (rad)')
        plt.ylabel('Astropy Altitude (rad')

        # Plot with trendline
        plt.plot([co[1] for co in altaz], [co[1] for co in etoha], 'b.',
                 altdecrange, altdecrange, '-')

        # Azimuth
        plt.subplot(212)
        plt.title('Azimuth')
        plt.axis(azrarange * 2)
        plt.xlabel('Pyephem Azimuth (rad)')
        plt.ylabel('Astropy Azimuth (rad)')

        plt.plot([co[0] for co in altaz], [co[0] for co in etoha], 'r.',
                 azrarange, azrarange, '-')

        # Formatting
        plt.tight_layout()
        plt.subplots_adjust(top=0.85)

        # Alt error histogram
        plt.figure(5)
        plt.title('Altitude Error RA,DEC->(pyephem/astropy)->Altaz')
        nieuw = (np.array(etoha) - np.array(altaz))
        nieuw *= 360 * 3600 / (2 * np.pi)
        plt.hist([co[1] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Az error histogram
        plt.figure(6)
        plt.title('Azimuth Error RA,DEC->(pyephem/astropy)->Altaz')
        plt.hist([co[0] for co in nieuw], bins=20)

        plt.ylabel('Counts')
        plt.xlabel('Error (arcsec)')

        # Make histograms of differences using the absolute distance in arcsec
        # these graphs have no wrapping issues

        plt.figure(7)
        nieuw = np.array([
            angle_between_horizontal(altaz[i][0], altaz[i][1], etoha[i][0],
                                     etoha[i][1]) for i in range(len(etoha))
        ])
        nieuw *= 360 * 3600 / (2 * np.pi)
        plt.hist(nieuw, bins=20)
        plt.title('Alt+Azi Error RA,DEC->(pyephem/astropy)->Altaz')
        plt.xlabel('Error (arcsec)')
        plt.ylabel('Counts')

        plt.figure(8)
        nieuw = np.array([
            angle_between_horizontal(efemeq[i][0], efemeq[i][1], htoea[i][0],
                                     htoea[i][1]) for i in range(len(htoea))
        ])
        # Take difference and convert to arcsec
        nieuw *= 360 * 3600 / (2 * np.pi)

        plt.hist(nieuw, bins=20)
        plt.title('RA+DEC Error Altaz->(pyephem/astropy)->RA,DEC')
        plt.xlabel('Error (arcsec)')
        plt.ylabel('Counts')

        # Done; output
        plt.show()