def test_zenithazimuth_to_horizontal(self): for zenith, altitude in zip(self.zenith, self.altitude): self.assertEqual(celestial.zenithazimuth_to_horizontal(zenith, 0)[0], altitude) self.assertEqual(celestial.horizontal_to_zenithazimuth(altitude, 0)[0], zenith) for azimuth, Azimuth in zip(self.azimuth, self.Azimuth): self.assertEqual(celestial.zenithazimuth_to_horizontal(0, azimuth)[1], Azimuth) self.assertEqual(celestial.horizontal_to_zenithazimuth(0, Azimuth)[1], azimuth)
def test_zenithazimuth_to_horizontal(self): for zenith, altitude in zip(self.zenith, self.altitude): self.assertEqual( celestial.zenithazimuth_to_horizontal(zenith, 0)[0], altitude) self.assertEqual( celestial.horizontal_to_zenithazimuth(altitude, 0)[0], zenith) for azimuth, Azimuth in zip(self.azimuth, self.Azimuth): self.assertEqual( celestial.zenithazimuth_to_horizontal(0, azimuth)[1], Azimuth) self.assertEqual( celestial.horizontal_to_zenithazimuth(0, Azimuth)[1], azimuth)
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)))
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_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)
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)
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)))
def angle_between_horizontal(azimuth1, altitude1, azimuth2, altitude2): """Calculate the angle between two horizontal coordinates Using the haversine formula, from: http://www.movable-type.co.uk/scripts/latlong.html :param azimuth#: Azimuth parts of the coordinates in radians. :param altitude#: Altitude parts of the coordinates in radians. :return: Angle between the two coordinates in radians. """ zenith1, azimuth1 = celestial.horizontal_to_zenithazimuth(altitude1, azimuth1) zenith2, azimuth2 = celestial.horizontal_to_zenithazimuth(altitude2, azimuth2) dlat = zenith1 - zenith2 dlon = azimuth2 - azimuth1 a = (np.sin(dlat / 2) ** 2 + np.sin(zenith1) * np.sin(zenith2) * np.sin(dlon / 2) ** 2) angle = 2 * np.arcsin(np.sqrt(a)) return angle
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 angle_between_horizontal(azimuth1, altitude1, azimuth2, altitude2): """Calculate the angle between two horizontal coordinates Using the haversine formula, from: http://www.movable-type.co.uk/scripts/latlong.html :param azimuth#: Azimuth parts of the coordinates in radians. :param altitude#: Altitude parts of the coordinates in radians. :return: Angle between the two coordinates in radians. """ zenith1, azimuth1 = celestial.horizontal_to_zenithazimuth( altitude1, azimuth1) zenith2, azimuth2 = celestial.horizontal_to_zenithazimuth( altitude2, azimuth2) dlat = zenith1 - zenith2 dlon = azimuth2 - azimuth1 a = (np.sin(dlat / 2)**2 + np.sin(zenith1) * np.sin(zenith2) * np.sin(dlon / 2)**2) angle = 2 * np.arcsin(np.sqrt(a)) return angle
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)))