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=2) 

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

81 decimal=2) 

82 

83 

84 

85 def test_focalCoords(self): 

86 """ 

87 Verify that focalPlaneCoordsFromRaDec has not changed 

88 """ 

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

90 self.pix_data['dec'], 

91 camera=self.camera, 

92 obs_metadata=self.obs) 

93 

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

95 decimal=4) 

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

97 decimal=4) 

98 

99 def test_cornerRaDec(self): 

100 """ 

101 Verify that getCornerRaDec has not changed 

102 """ 

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

104 ('x0', float), ('y0', float), 

105 ('x1', float), ('y1', float), 

106 ('x2', float), ('y2', float), 

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

108 

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

110 dtype=dtype, delimiter=';') 

111 

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

113 detector_name_list.sort() 

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

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

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

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

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

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

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

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

122 

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

124 name = detector_name_list[i_chip] 

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

126 x0[i_chip] = corners[0][0] 

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

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

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

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

131 y1[i_chip] = corners[1][1] 

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

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

134 

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

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

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

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

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

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

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

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

143 

144 

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

146 pass 

147 

148 

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

150 lsst.utils.tests.init() 

151 unittest.main()