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)
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) zencalc, azcalc = celestial.equatorial_to_zenithazimuth(latitude, longitude, gps, ra_expected, dec_expected) self.assertAlmostEqual(ra, ra_expected, 3) self.assertAlmostEqual(ra, ra_astropy, 3) self.assertAlmostEqual(dec, dec_expected, 2) self.assertAlmostEqual(dec, dec_astropy, 2) self.assertAlmostEqual(zencalc, zenith, 2) self.assertAlmostEqual(azcalc, azimuth, 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) zencalc, azcalc = celestial.equatorial_to_zenithazimuth( latitude, longitude, gps, ra_expected, dec_expected) self.assertAlmostEqual(ra, ra_expected, 2) self.assertAlmostEqual(ra, ra_astropy, 2) self.assertAlmostEqual(dec, dec_expected, 2) self.assertAlmostEqual(dec, dec_astropy, 2) self.assertAlmostEqual(zencalc, zenith, 2) self.assertAlmostEqual(azcalc, azimuth, 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) zencalc, azcalc = celestial.equatorial_to_zenithazimuth( latitude, longitude, gps, ra_expected, dec_expected) self.assertAlmostEqual(ra, ra_expected, 3) self.assertAlmostEqual(ra, ra_astropy, 3) self.assertAlmostEqual(dec, dec_expected, 2) self.assertAlmostEqual(dec, dec_astropy, 2) self.assertAlmostEqual(zencalc, zenith, 2) self.assertAlmostEqual(azcalc, azimuth, 2)
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