def test_rotation_angle_pupil_coordinate_convention(self): """ Test the convention on how rotation angle affects the orientation of north on the focal plane (in pupil coordinates) by calculating the puipil coordinates of positions slightly displaced from the center of the camera. """ start = time.clock() ra = 30.0 dec = 0.0 delta = 0.001 pointing = CelestialCoord(ra*galsim.degrees, dec*galsim.degrees) north = CelestialCoord(ra*galsim.degrees, (dec+delta)*galsim.degrees) east = CelestialCoord((ra+delta)*galsim.degrees, dec*galsim.degrees) camera = LsstCamera(pointing, 0.0*galsim.degrees) x_0, y_0 = camera.pupilCoordsFromPoint(pointing) x_n, y_n = camera.pupilCoordsFromPoint(north) x_e, y_e = camera.pupilCoordsFromPoint(east) self.assertAlmostEqual(0.0, np.degrees(x_0), 7) self.assertAlmostEqual(0.0, np.degrees(y_0), 7) self.assertAlmostEqual(0.0, np.degrees(x_n), 7) self.assertGreater(np.degrees(y_n), 1.0e-4) self.assertLess(np.degrees(x_e), -1.0e-4) self.assertAlmostEqual(np.degrees(y_e), 0.0, 7) camera = LsstCamera(pointing, 90.0*galsim.degrees) x_n, y_n = camera.pupilCoordsFromPoint(north) x_e, y_e = camera.pupilCoordsFromPoint(east) self.assertLess(np.degrees(x_n), -1.0e-4) self.assertAlmostEqual(np.degrees(y_n), 0.0, 7) self.assertAlmostEqual(np.degrees(x_e), 0.0, 7) self.assertLess(np.degrees(y_e), -1.0e-4) camera = LsstCamera(pointing, -90.0*galsim.degrees) x_n, y_n = camera.pupilCoordsFromPoint(north) x_e, y_e = camera.pupilCoordsFromPoint(east) self.assertGreater(np.degrees(x_n), 1.0e-4) self.assertAlmostEqual(np.degrees(y_n), 0.0, 7) self.assertAlmostEqual(np.degrees(x_e), 0.0, 7) self.assertGreater(np.degrees(y_e), 1.0e-4) camera = LsstCamera(pointing, 180.0*galsim.degrees) x_n, y_n = camera.pupilCoordsFromPoint(north) x_e, y_e = camera.pupilCoordsFromPoint(east) self.assertAlmostEqual(np.degrees(x_n), 0, 7) self.assertLess(np.degrees(y_n), -1.0e-4) self.assertGreater(np.degrees(x_e), 1.0e-4) self.assertAlmostEqual(np.degrees(y_e), 0.0, 7) print 'time to run %s = %e sec' % (funcname(), time.clock()-start)
def test_pupil_coordinates_from_floats(self): """ Test that the method which converts floats into pupil coordinates agrees with the method that converts CelestialCoords into pupil coordinates """ start = time.clock() raPointing = 113.0 decPointing = -25.6 rot = 82.1 pointing = CelestialCoord(raPointing*galsim.degrees, decPointing*galsim.degrees) camera = LsstCamera(pointing, rot*galsim.degrees) arcsec_per_radian = 180.0*3600.0/np.pi rng = np.random.RandomState(33) raList = (rng.random_sample(100)-0.5)*20.0+raPointing decList = (rng.random_sample(100)-0.5)*20.0+decPointing pointingList = [] for rr, dd in zip(raList, decList): pointingList.append(CelestialCoord(rr*galsim.degrees, dd*galsim.degrees)) control_x, control_y = camera.pupilCoordsFromPoint(pointingList) test_x, test_y = camera.pupilCoordsFromFloat(np.radians(raList), np.radians(decList)) np.testing.assert_array_almost_equal((test_x - control_x)*arcsec_per_radian, np.zeros(len(test_x)), 10) np.testing.assert_array_almost_equal((test_y - control_y)*arcsec_per_radian, np.zeros(len(test_y)), 10) print 'time to run %s = %e sec' % (funcname(), time.clock()-start)
def test_pupil_coordinates(self): """ Test the conversion between (RA, Dec) and pupil coordinates. Results are checked against the routine provided by PALPY. """ start = time.clock() def palpyPupilCoords(star, pointing): """ This is just a copy of the PALPY method Ds2tp, which I am taking to be the ground truth for projection from a sphere onto the tangent plane inputs ------------ star is a CelestialCoord corresponding to the point being projected pointing is a CelestialCoord corresponding to the pointing of the 'telescope' outputs ------------ The x and y coordinates in the focal plane (radians) """ ra = star.ra/galsim.radians dec = star.dec/galsim.radians ra_pointing = pointing.ra/galsim.radians dec_pointing = pointing.dec/galsim.radians cdec = np.cos(dec) sdec = np.sin(dec) cdecz = np.cos(dec_pointing) sdecz = np.sin(dec_pointing) cradif = np.cos(ra - ra_pointing) sradif = np.sin(ra - ra_pointing) denom = sdec * sdecz + cdec * cdecz * cradif xx = cdec * sradif/denom yy = (sdec * cdecz - cdec * sdecz * cradif)/denom return xx, yy rng = np.random.RandomState(42) n_pointings = 10 ra_pointing_list = rng.random_sample(n_pointings)*2.0*np.pi dec_pointing_list = 0.5*(rng.random_sample(n_pointings)-0.5)*np.pi rotation_angle_list = rng.random_sample(n_pointings)*2.0*np.pi radians_to_arcsec = 3600.0*np.degrees(1.0) for ra, dec, rotation in zip(ra_pointing_list, dec_pointing_list, rotation_angle_list): pointing = CelestialCoord(ra*galsim.radians, dec*galsim.radians) camera = LsstCamera(pointing, rotation*galsim.radians) dra_list = (rng.random_sample(100)-0.5)*0.5 ddec_list = (rng.random_sample(100)-0.5)*0.5 star_list = np.array([CelestialCoord((ra+dra)*galsim.radians, (dec+ddec)*galsim.radians) for dra, ddec in zip(dra_list, ddec_list)]) xTest, yTest = camera.pupilCoordsFromPoint(star_list) xControl = [] yControl = [] for star in star_list: xx, yy = palpyPupilCoords(star, pointing) xx *= -1.0 xControl.append(xx*np.cos(rotation) - yy*np.sin(rotation)) yControl.append(yy*np.cos(rotation) + xx*np.sin(rotation)) xControl = np.array(xControl) yControl = np.array(yControl) np.testing.assert_array_almost_equal((xTest*radians_to_arcsec) - (xControl*radians_to_arcsec), np.zeros(len(xControl)), 7) np.testing.assert_array_almost_equal((yTest*radians_to_arcsec) - (yControl*radians_to_arcsec), np.zeros(len(yControl)), 7) print 'time to run %s = %e sec' % (funcname(), time.clock()-start)