def test_raDecFromAltAz_noref(self): """ test that raDecFromAltAz correctly inverts altAzPaFromRaDec, even when refraction is turned off """ rng = np.random.RandomState(55) n_samples = 10 n_batches = 10 for i_batch in range(n_batches): d_sun = 0.0 while d_sun < 45.0: # because ICRS->Observed transformation breaks down close to the sun alt_in = rng.random_sample(n_samples)*50.0 + 20.0 az_in = rng.random_sample(n_samples)*360.0 obs = utils.ObservationMetaData(mjd=43000.0) ra_in, dec_in = utils.raDecFromAltAz(alt_in, az_in, obs=obs, includeRefraction=False) d_sun = utils.distanceToSun(ra_in, dec_in, obs.mjd).min() alt_out, az_out, pa_out = utils.altAzPaFromRaDec(ra_in, dec_in, obs=obs, includeRefraction=False) dd = utils.haversine(np.radians(alt_out), np.radians(az_out), np.radians(alt_in), np.radians(az_in)) self.assertLess(utils.arcsecFromRadians(dd).max(), 0.01)
def testRaDecFromPupil(self): """ Test conversion from pupil coordinates back to Ra, Dec """ mjd = ModifiedJulianDate(TAI=52000.0) solarRA, solarDec = solarRaDec(mjd.TDB) # to make sure that we are more than 45 degrees from the Sun as required # for _icrsFromObserved to be at all accurate raCenter = solarRA + 100.0 decCenter = solarDec - 30.0 obs = ObservationMetaData(pointingRA=raCenter, pointingDec=decCenter, boundType='circle', boundLength=0.1, rotSkyPos=23.0, mjd=mjd) nSamples = 1000 numpy.random.seed(42) ra = (numpy.random.random_sample(nSamples)*0.1-0.2) + numpy.radians(raCenter) dec = (numpy.random.random_sample(nSamples)*0.1-0.2) + numpy.radians(decCenter) xp, yp = _pupilCoordsFromRaDec(ra, dec, obs_metadata=obs, epoch=2000.0) raTest, decTest = _raDecFromPupilCoords(xp, yp, obs_metadata=obs, epoch=2000.0) distance = arcsecFromRadians(haversine(ra, dec, raTest, decTest)) dex = numpy.argmax(distance) worstSolarDistance = distanceToSun(numpy.degrees(ra[dex]), numpy.degrees(dec[dex]), mjd.TDB) msg = "_raDecFromPupilCoords off by %e arcsec at distance to Sun of %e degrees" % \ (distance.max(), worstSolarDistance) self.assertLess(distance.max(), 0.005, msg=msg)
def testDistanceToSunDeg(self): """ Test that distanceToSun is consistent with _distanceToSun """ for mjd, ra, dec in zip((57632.1, 45623.4, 55682.3), (112.0, 24.0, 231.2), (-25.0, 23.4, -60.0)): dd_deg = distanceToSun(ra, dec, mjd) dd_rad = _distanceToSun(numpy.radians(ra), numpy.radians(dec), mjd) self.assertAlmostEqual(numpy.radians(dd_deg), dd_rad, 10)
def testRaDecFromPupil(self): """ Test conversion from pupil coordinates back to Ra, Dec """ mjd = ModifiedJulianDate(TAI=52000.0) solarRA, solarDec = solarRaDec(mjd) # to make sure that we are more than 45 degrees from the Sun as required # for _icrsFromObserved to be at all accurate raCenter = solarRA + 100.0 decCenter = solarDec - 30.0 obs = ObservationMetaData(pointingRA=raCenter, pointingDec=decCenter, boundType='circle', boundLength=0.1, rotSkyPos=23.0, mjd=mjd) nSamples = 1000 rng = np.random.RandomState(42) ra = (rng.random_sample(nSamples) * 0.1 - 0.2) + np.radians(raCenter) dec = (rng.random_sample(nSamples) * 0.1 - 0.2) + np.radians(decCenter) xp, yp = _pupilCoordsFromRaDec(ra, dec, obs_metadata=obs, epoch=2000.0) raTest, decTest = _raDecFromPupilCoords(xp, yp, obs_metadata=obs, epoch=2000.0) distance = arcsecFromRadians(haversine(ra, dec, raTest, decTest)) dex = np.argmax(distance) worstSolarDistance = distanceToSun(np.degrees(ra[dex]), np.degrees(dec[dex]), mjd) msg = "_raDecFromPupilCoords off by %e arcsec at distance to Sun of %e degrees" % \ (distance.max(), worstSolarDistance) self.assertLess(distance.max(), 1.0e-6, msg=msg) # now check that passing in the xp, yp values one at a time still gives # the right answer for ix in range(len(ra)): ra_f, dec_f = _raDecFromPupilCoords(xp[ix], yp[ix], obs_metadata=obs, epoch=2000.0) self.assertIsInstance(ra_f, np.float) self.assertIsInstance(dec_f, np.float) dist_f = arcsecFromRadians( haversine(ra_f, dec_f, raTest[ix], decTest[ix])) self.assertLess(dist_f, 1.0e-9)
def testRaDecFromPupil_noRefraction(self): """ Test conversion from pupil coordinates back to Ra, Dec with includeRefraction=False """ mjd = ModifiedJulianDate(TAI=52000.0) solarRA, solarDec = solarRaDec(mjd) # to make sure that we are more than 45 degrees from the Sun as required # for _icrsFromObserved to be at all accurate raCenter = solarRA + 100.0 decCenter = solarDec - 30.0 obs = ObservationMetaData(pointingRA=raCenter, pointingDec=decCenter, boundType='circle', boundLength=0.1, rotSkyPos=23.0, mjd=mjd) nSamples = 1000 rng = np.random.RandomState(42) ra = (rng.random_sample(nSamples) * 0.1 - 0.2) + np.radians(raCenter) dec = (rng.random_sample(nSamples) * 0.1 - 0.2) + np.radians(decCenter) xp, yp = _pupilCoordsFromRaDec(ra, dec, obs_metadata=obs, epoch=2000.0, includeRefraction=False) raTest, decTest = _raDecFromPupilCoords( xp, yp, obs_metadata=obs, epoch=2000.0, includeRefraction=False) distance = arcsecFromRadians(haversine(ra, dec, raTest, decTest)) dex = np.argmax(distance) worstSolarDistance = distanceToSun( np.degrees(ra[dex]), np.degrees(dec[dex]), mjd) msg = "_raDecFromPupilCoords off by %e arcsec at distance to Sun of %e degrees" % \ (distance.max(), worstSolarDistance) self.assertLess(distance.max(), 1.0e-6, msg=msg) # now check that passing in the xp, yp values one at a time still gives # the right answer for ix in range(len(ra)): ra_f, dec_f = _raDecFromPupilCoords(xp[ix], yp[ix], obs_metadata=obs, epoch=2000.0, includeRefraction=False) self.assertIsInstance(ra_f, np.float) self.assertIsInstance(dec_f, np.float) dist_f = arcsecFromRadians(haversine(ra_f, dec_f, raTest[ix], decTest[ix])) self.assertLess(dist_f, 1.0e-9)
def test_with_proper_motion(self): """ Test that calculating pupil coordinates in the presence of proper motion, parallax, and radial velocity is equivalent to observedFromICRS -> icrsFromObserved -> pupilCoordsFromRaDec (mostly to make surethat pupilCoordsFromRaDec is correctly calling observedFromICRS with non-zero proper motion, etc.) """ rng = np.random.RandomState(38442) is_valid = False while not is_valid: mjd_tai = 59580.0 + 10000.0*rng.random_sample() obs = ObservationMetaData(mjd=mjd_tai) ra, dec = raDecFromAltAz(78.0, 112.0, obs) dd = distanceToSun(ra, dec, obs.mjd) if dd > 45.0: is_valid = True n_obj = 1000 rr = rng.random_sample(n_obj)*2.0 theta = rng.random_sample(n_obj)*2.0*np.pi ra_list = ra + rr*np.cos(theta) dec_list = dec + rr*np.sin(theta) obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, mjd=mjd_tai, rotSkyPos=19.0) pm_ra_list = rng.random_sample(n_obj)*100.0 - 50.0 pm_dec_list = rng.random_sample(n_obj)*100.0 - 50.0 px_list = rng.random_sample(n_obj) + 0.05 v_rad_list = rng.random_sample(n_obj)*600.0 - 300.0 for includeRefraction in (True, False): ra_obs, dec_obs = observedFromICRS(ra_list, dec_list, pm_ra=pm_ra_list, pm_dec=pm_dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) ra_icrs, dec_icrs = icrsFromObserved(ra_obs, dec_obs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_control, yp_control = pupilCoordsFromRaDec(ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_test, yp_test = pupilCoordsFromRaDec(ra_list, dec_list, pm_ra=pm_ra_list, pm_dec=pm_dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) distance = arcsecFromRadians(np.sqrt(np.power(xp_test-xp_control, 2) + np.power(yp_test-yp_control, 2))) self.assertLess(distance.max(), 0.006) # now test it in radians xp_rad, yp_rad = _pupilCoordsFromRaDec(np.radians(ra_list), np.radians(dec_list), pm_ra=radiansFromArcsec(pm_ra_list), pm_dec=radiansFromArcsec(pm_dec_list), parallax=radiansFromArcsec(px_list), v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) np.testing.assert_array_equal(xp_rad, xp_test) np.testing.assert_array_equal(yp_rad, yp_test) # now test it with proper motion = 0 ra_obs, dec_obs = observedFromICRS(ra_list, dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) ra_icrs, dec_icrs = icrsFromObserved(ra_obs, dec_obs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_control, yp_control = pupilCoordsFromRaDec(ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_test, yp_test = pupilCoordsFromRaDec(ra_list, dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) distance = arcsecFromRadians(np.sqrt(np.power(xp_test-xp_control, 2) + np.power(yp_test-yp_control, 2))) self.assertLess(distance.max(), 1.0e-6)
def test_naive_focal_plane_position(self): """ Test deprecession of PhoSim coordinates by comparing the focal plane position predicted by CatSim from ICRS with the focal plane position predicted by CatSim from deprecessed coordinates. """ phosim_mixin = PhoSimAstrometryBase() mjd = 59587.2 # create site with no atmosphere so that we can avoid # refraction site = Site(name="LSST", pressure=0.0, humidity=0.0) obs = ObservationMetaData(mjd=mjd, site=site) ra, dec = raDecFromAltAz(31.0, 112.0, obs) d_sun = distanceToSun(ra, dec, obs.mjd) self.assertGreater(d_sun, 45.0) obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, rotSkyPos=27.3, mjd=mjd, site=site) ra_icrs = np.arange(obs.pointingRA-2.0, obs.pointingRA+2.0, 0.05) dec_icrs = np.arange(obs.pointingDec-2.0, obs.pointingDec+2.0, 0.05) coord_grid = np.meshgrid(ra_icrs, dec_icrs) ra_icrs = coord_grid[0].flatten() dec_icrs = coord_grid[1].flatten() (xpup_icrs, ypup_icrs) = pupilCoordsFromRaDec(ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=False) (x_focal_icrs, y_focal_icrs) = focalPlaneCoordsFromPupilCoords(xpup_icrs, ypup_icrs, camera=lsst_camera()) ra_obs, dec_obs = observedFromICRS(ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=False) ra_obs_rad = np.radians(ra_obs) dec_obs_rad = np.radians(dec_obs) (ra_deprecessed_rad, dec_deprecessed_rad) = phosim_mixin._dePrecess(ra_obs_rad, dec_obs_rad, obs) (xpup_deprecessed, ypup_deprecessed) = _naivePupilCoordsFromObserved(ra_deprecessed_rad, dec_deprecessed_rad, obs._pointingRA, obs._pointingDec, obs._rotSkyPos) (x_focal_deprecessed, y_focal_deprecessed) = focalPlaneCoordsFromPupilCoords(xpup_deprecessed, ypup_deprecessed, camera=lsst_camera()) dd = np.sqrt((x_focal_icrs-x_focal_deprecessed)**2 +(y_focal_icrs-y_focal_deprecessed)**2) self.assertLess(dd.max(), 5.0e-8)
def test_with_proper_motion(self): """ Test that calculating pupil coordinates in the presence of proper motion, parallax, and radial velocity is equivalent to observedFromICRS -> icrsFromObserved -> pupilCoordsFromRaDec (mostly to make surethat pupilCoordsFromRaDec is correctly calling observedFromICRS with non-zero proper motion, etc.) """ rng = np.random.RandomState(38442) is_valid = False while not is_valid: mjd_tai = 59580.0 + 10000.0 * rng.random_sample() obs = ObservationMetaData(mjd=mjd_tai) ra, dec = raDecFromAltAz(78.0, 112.0, obs) dd = distanceToSun(ra, dec, obs.mjd) if dd > 45.0: is_valid = True n_obj = 1000 rr = rng.random_sample(n_obj) * 2.0 theta = rng.random_sample(n_obj) * 2.0 * np.pi ra_list = ra + rr * np.cos(theta) dec_list = dec + rr * np.sin(theta) obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, mjd=mjd_tai, rotSkyPos=19.0) pm_ra_list = rng.random_sample(n_obj) * 100.0 - 50.0 pm_dec_list = rng.random_sample(n_obj) * 100.0 - 50.0 px_list = rng.random_sample(n_obj) + 0.05 v_rad_list = rng.random_sample(n_obj) * 600.0 - 300.0 for includeRefraction in (True, False): ra_obs, dec_obs = observedFromICRS( ra_list, dec_list, pm_ra=pm_ra_list, pm_dec=pm_dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) ra_icrs, dec_icrs = icrsFromObserved( ra_obs, dec_obs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_control, yp_control = pupilCoordsFromRaDec( ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_test, yp_test = pupilCoordsFromRaDec( ra_list, dec_list, pm_ra=pm_ra_list, pm_dec=pm_dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) distance = arcsecFromRadians( np.sqrt( np.power(xp_test - xp_control, 2) + np.power(yp_test - yp_control, 2))) self.assertLess(distance.max(), 0.006) # now test it in radians xp_rad, yp_rad = _pupilCoordsFromRaDec( np.radians(ra_list), np.radians(dec_list), pm_ra=radiansFromArcsec(pm_ra_list), pm_dec=radiansFromArcsec(pm_dec_list), parallax=radiansFromArcsec(px_list), v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) np.testing.assert_array_equal(xp_rad, xp_test) np.testing.assert_array_equal(yp_rad, yp_test) # now test it with proper motion = 0 ra_obs, dec_obs = observedFromICRS( ra_list, dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) ra_icrs, dec_icrs = icrsFromObserved( ra_obs, dec_obs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_control, yp_control = pupilCoordsFromRaDec( ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) xp_test, yp_test = pupilCoordsFromRaDec( ra_list, dec_list, parallax=px_list, v_rad=v_rad_list, obs_metadata=obs, epoch=2000.0, includeRefraction=includeRefraction) distance = arcsecFromRadians( np.sqrt( np.power(xp_test - xp_control, 2) + np.power(yp_test - yp_control, 2))) self.assertLess(distance.max(), 1.0e-6)
rot_list = rng.random_sample(50) * 360.0 mjd_list = rng.random_sample(50) * 10000.0 + 59580.0 for ra, dec, rot, mjd in zip(ra_list, dec_list, rot_list, mjd_list): obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, rotSkyPos=rot, mjd=mjd) alt, az, pa = altAzPaFromRaDec(ra, dec, obs) ra_corner, dec_corner = fovCorners(obs, side_length=20.0) print ra_corner print dec_corner max_orthogonal = -1.0 for ix1, ix2 in zip((0, 0, 1, 2), (1, 3, 2, 3)): dd = distance_in_arcminutes(ra_corner[ix1], dec_corner[ix1], ra_corner[ix2], dec_corner[ix2]) if np.abs(dd - 20.0) > max_orthogonal: max_orthogonal = np.abs(dd - 20.0) dd = distance_in_arcminutes(ra_corner[2], dec_corner[2], ra_corner[0], dec_corner[0]) d_sun = distanceToSun(ra, dec, obs.mjd.TDB) print 'max orthogonal errr ', max_orthogonal, ra, dec, rot, d_sun, alt
def test_naive_focal_plane_position(self): """ Test deprecession of PhoSim coordinates by comparing the focal plane position predicted by CatSim from ICRS with the focal plane position predicted by CatSim from deprecessed coordinates. """ phosim_mixin = PhoSimAstrometryBase() mjd = 59587.2 # create site with no atmosphere so that we can avoid # refraction site = Site(name="LSST", pressure=0.0, humidity=0.0) obs = ObservationMetaData(mjd=mjd, site=site) ra, dec = raDecFromAltAz(31.0, 112.0, obs) d_sun = distanceToSun(ra, dec, obs.mjd) self.assertGreater(d_sun, 45.0) obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, rotSkyPos=27.3, mjd=mjd, site=site) ra_icrs = np.arange(obs.pointingRA - 2.0, obs.pointingRA + 2.0, 0.05) dec_icrs = np.arange(obs.pointingDec - 2.0, obs.pointingDec + 2.0, 0.05) coord_grid = np.meshgrid(ra_icrs, dec_icrs) ra_icrs = coord_grid[0].flatten() dec_icrs = coord_grid[1].flatten() (xpup_icrs, ypup_icrs) = pupilCoordsFromRaDec(ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=False) (x_focal_icrs, y_focal_icrs) = focalPlaneCoordsFromPupilCoords(xpup_icrs, ypup_icrs, camera=lsst_camera()) ra_obs, dec_obs = observedFromICRS(ra_icrs, dec_icrs, obs_metadata=obs, epoch=2000.0, includeRefraction=False) ra_obs_rad = np.radians(ra_obs) dec_obs_rad = np.radians(dec_obs) (ra_deprecessed_rad, dec_deprecessed_rad) = phosim_mixin._dePrecess( ra_obs_rad, dec_obs_rad, obs) (xpup_deprecessed, ypup_deprecessed) = _naivePupilCoordsFromObserved( ra_deprecessed_rad, dec_deprecessed_rad, obs._pointingRA, obs._pointingDec, obs._rotSkyPos) (x_focal_deprecessed, y_focal_deprecessed) = focalPlaneCoordsFromPupilCoords( xpup_deprecessed, ypup_deprecessed, camera=lsst_camera()) dd = np.sqrt((x_focal_icrs - x_focal_deprecessed)**2 + (y_focal_icrs - y_focal_deprecessed)**2) self.assertLess(dd.max(), 1.0e-8)