Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import unittest 

2import lsst.utils.tests 

3from lsst.utils import getPackageDir 

4 

5import numpy as np 

6import os 

7 

8import lsst.obs.lsst.phosim as obs_lsst_phosim 

9 

10from lsst.sims.utils import ObservationMetaData 

11from lsst.sims.coordUtils import getCornerRaDec 

12from lsst.sims.coordUtils import focalPlaneCoordsFromRaDec 

13from lsst.sims.coordUtils import pixelCoordsFromRaDec 

14from lsst.sims.coordUtils import chipNameFromRaDec 

15from lsst.sims.coordUtils import chipNameFromPupilCoords 

16 

17 

18def setup_module(module): 

19 lsst.utils.tests.init() 

20 

21 

22class AfwCameraGeomAPITestCase(unittest.TestCase): 

23 """ 

24 This test case is meant to verify that we have correctly incorporated 

25 any API changes in afwCameraGeom by verifying RA, Dec to pixel results 

26 against identical results generated from the w.2017.50 version of 

27 afw. If obs_lsst ever changes in a physically meaningful way, these 

28 tests will break, but hopefully we will be aware that that happened and 

29 we will be able to regenerate the underlying test data with 

30 

31 $SIM_COORDUTILS_DIR/tests/lsstCameraData/make_test_catalog.py 

32 """ 

33 

34 @classmethod 

35 def setUpClass(cls): 

36 cls.camera = obs_lsst_phosim.PhosimMapper().camera 

37 cls.data_dir = os.path.join(getPackageDir('sims_coordUtils'), 

38 'tests', 'lsstCameraData') 

39 

40 pix_dtype = np.dtype([('ra', float), ('dec', float), 

41 ('name', str, 15), 

42 ('focal_x', float), ('focal_y', float), 

43 ('pixel_x', float), ('pixel_y', float)]) 

44 

45 cls.pix_data = np.genfromtxt(os.path.join(cls.data_dir, 

46 'lsst_pixel_data.txt'), 

47 delimiter=';', dtype=pix_dtype) 

48 

49 ra = 25.0 

50 dec = -62.0 

51 cls.obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, 

52 rotSkyPos=57.2, mjd=59586.2) 

53 

54 @classmethod 

55 def tearDownClass(cls): 

56 del cls.camera 

57 

58 def test_chipName(self): 

59 """ 

60 Verify that chipNameFromRaDec has not changed. 

61 """ 

62 chip_name_arr = chipNameFromRaDec(self.pix_data['ra'], 

63 self.pix_data['dec'], 

64 obs_metadata=self.obs, 

65 camera=self.camera) 

66 

67 np.testing.assert_array_equal(chip_name_arr, self.pix_data['name']) 

68 

69 def test_pixelCoords(self): 

70 """ 

71 Verify that pixelCoordsFromRaDec has not changed 

72 """ 

73 pix_x, pix_y = pixelCoordsFromRaDec(self.pix_data['ra'], 

74 self.pix_data['dec'], 

75 obs_metadata=self.obs, 

76 camera=self.camera) 

77 

78 np.testing.assert_array_almost_equal(pix_x, self.pix_data['pixel_x'], 

79 decimal=3) 

80 np.testing.assert_array_almost_equal(pix_y, self.pix_data['pixel_y'], 

81 decimal=3) 

82 

83 

84 def test_focalCoords(self): 

85 """ 

86 Verify that focalPlaneCoordsFromRaDec has not changed 

87 """ 

88 foc_x, foc_y = focalPlaneCoordsFromRaDec(self.pix_data['ra'], 

89 self.pix_data['dec'], 

90 camera=self.camera, 

91 obs_metadata=self.obs) 

92 

93 np.testing.assert_array_almost_equal(foc_x, self.pix_data['focal_x'], 

94 decimal=5) 

95 np.testing.assert_array_almost_equal(foc_y, self.pix_data['focal_y'], 

96 decimal=5) 

97 

98 def test_cornerRaDec(self): 

99 """ 

100 Verify that getCornerRaDec has not changed 

101 """ 

102 dtype = np.dtype([('name', str, 15), 

103 ('x0', float), ('y0', float), 

104 ('x1', float), ('y1', float), 

105 ('x2', float), ('y2', float), 

106 ('x3', float), ('y3', float)]) 

107 

108 data = np.genfromtxt(os.path.join(self.data_dir, 'lsst_camera_corners.txt'), 

109 dtype=dtype, delimiter=';') 

110 

111 detector_name_list = [dd.getName() for dd in self.camera] 

112 detector_name_list.sort() 

113 x0 = np.zeros(len(detector_name_list), dtype=float) 

114 x1 = np.zeros(len(detector_name_list), dtype=float) 

115 x2 = np.zeros(len(detector_name_list), dtype=float) 

116 x3 = np.zeros(len(detector_name_list), dtype=float) 

117 y0 = np.zeros(len(detector_name_list), dtype=float) 

118 y1 = np.zeros(len(detector_name_list), dtype=float) 

119 y2 = np.zeros(len(detector_name_list), dtype=float) 

120 y3 = np.zeros(len(detector_name_list), dtype=float) 

121 

122 for i_chip in range(len(detector_name_list)): 

123 name = detector_name_list[i_chip] 

124 corners = getCornerRaDec(name, self.camera, self.obs) 

125 x0[i_chip] = corners[0][0] 

126 x1[i_chip] = corners[1][0] 

127 x2[i_chip] = corners[2][0] 

128 x3[i_chip] = corners[3][0] 

129 y0[i_chip] = corners[0][1] 

130 y1[i_chip] = corners[1][1] 

131 y2[i_chip] = corners[2][1] 

132 y3[i_chip] = corners[3][1] 

133 

134 np.testing.assert_array_almost_equal(x0, data['x0'], decimal=4) 

135 np.testing.assert_array_almost_equal(x1, data['x1'], decimal=4) 

136 np.testing.assert_array_almost_equal(x2, data['x2'], decimal=4) 

137 np.testing.assert_array_almost_equal(x3, data['x3'], decimal=4) 

138 np.testing.assert_array_almost_equal(y0, data['y0'], decimal=4) 

139 np.testing.assert_array_almost_equal(y1, data['y1'], decimal=4) 

140 np.testing.assert_array_almost_equal(y2, data['y2'], decimal=4) 

141 np.testing.assert_array_almost_equal(y3, data['y3'], decimal=4) 

142 

143 

144class MemoryTestClass(lsst.utils.tests.MemoryTestCase): 

145 pass 

146 

147 

148if __name__ == "__main__": 148 ↛ 149line 148 didn't jump to line 149, because the condition on line 148 was never true

149 lsst.utils.tests.init() 

150 unittest.main()