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

1from builtins import zip 

2import unittest 

3import os 

4import numpy as np 

5from lsst.utils import getPackageDir 

6import lsst.utils.tests 

7 

8from lsst.sims.utils.CodeUtilities import sims_clean_up 

9from lsst.sims.utils import ObservationMetaData 

10from lsst.sims.photUtils import PhotometricParameters 

11#from lsst.sims.coordUtils.utils import ReturnCamera 

12from lsst.sims.coordUtils import _raDecFromPixelCoords, pupilCoordsFromPixelCoords 

13from lsst.sims.GalSimInterface import GalSimDetector, GalSimCameraWrapper 

14 

15 

16def setup_module(module): 

17 lsst.utils.tests.init() 

18 

19@unittest.skip('ReturnCamera deprecated - need replacement') 

20class GalSimDetectorTest(unittest.TestCase): 

21 

22 @classmethod 

23 def tearDownClass(cls): 

24 sims_clean_up() 

25 

26 def setUp(self): 

27 baseDir = os.path.join(getPackageDir('sims_GalSimInterface'), 

28 'tests', 'cameraData') 

29 

30 self.camera = ReturnCamera(baseDir) 

31 

32 ra = 145.0 

33 dec = -73.0 

34 self.epoch = 2000.0 

35 mjd = 49250.0 

36 rotSkyPos = 45.0 

37 self.obs = ObservationMetaData(pointingRA=ra, 

38 pointingDec=dec, 

39 boundType='circle', 

40 boundLength=1.0, 

41 mjd=mjd, 

42 rotSkyPos=rotSkyPos) 

43 

44 def tearDown(self): 

45 del self.camera 

46 

47 def testContainsRaDec(self): 

48 """ 

49 Test whether or not the method containsRaDec correctly identifies 

50 RA and Dec that fall inside and outside the detector 

51 """ 

52 

53 photParams = PhotometricParameters() 

54 gsdet = GalSimDetector(self.camera[0].getName(), 

55 GalSimCameraWrapper(self.camera), 

56 self.obs, self.epoch, 

57 photParams=photParams) 

58 

59 xxList = [gsdet.xMinPix, gsdet.xMaxPix] 

60 yyList = [gsdet.yMinPix, gsdet.yMaxPix] 

61 dxList = [-1.0, 1.0] 

62 dyList = [-1.0, 1.0] 

63 

64 xPixList = [] 

65 yPixList = [] 

66 correctAnswer = [] 

67 

68 for xx, yy, dx, dy in zip(xxList, yyList, dxList, dyList): 

69 xPixList.append(xx) 

70 yPixList.append(yy) 

71 correctAnswer.append(True) 

72 

73 xPixList.append(xx+dx) 

74 yPixList.append(yy) 

75 correctAnswer.append(False) 

76 

77 xPixList.append(xx) 

78 yPixList.append(yy+dy) 

79 correctAnswer.append(False) 

80 

81 nameList = [gsdet.name]*len(xPixList) 

82 xPixList = np.array(xPixList) 

83 yPixList = np.array(yPixList) 

84 

85 raList, decList = _raDecFromPixelCoords(xPixList, yPixList, 

86 nameList, 

87 camera=self.camera, 

88 obs_metadata=self.obs, 

89 epoch=self.epoch) 

90 

91 testAnswer = gsdet.containsRaDec(raList, decList) 

92 

93 for c, t in zip(correctAnswer, testAnswer): 

94 self.assertIs(c, t) 

95 

96 def testContainsPupilCoordinates(self): 

97 """ 

98 Test whether or not the method containsRaDec correctly identifies 

99 RA and Dec that fall inside and outside the detector 

100 """ 

101 

102 photParams = PhotometricParameters() 

103 gsdet = GalSimDetector(self.camera[0].getName(), 

104 GalSimCameraWrapper(self.camera), 

105 self.obs, self.epoch, 

106 photParams=photParams) 

107 

108 xxList = [gsdet.xMinPix, gsdet.xMaxPix] 

109 yyList = [gsdet.yMinPix, gsdet.yMaxPix] 

110 dxList = [-1.0, 1.0] 

111 dyList = [-1.0, 1.0] 

112 

113 xPixList = [] 

114 yPixList = [] 

115 correctAnswer = [] 

116 

117 for xx, yy, dx, dy in zip(xxList, yyList, dxList, dyList): 

118 xPixList.append(xx) 

119 yPixList.append(yy) 

120 correctAnswer.append(True) 

121 

122 xPixList.append(xx+dx) 

123 yPixList.append(yy) 

124 correctAnswer.append(False) 

125 

126 xPixList.append(xx) 

127 yPixList.append(yy+dy) 

128 correctAnswer.append(False) 

129 

130 nameList = [gsdet.name]*len(xPixList) 

131 xPixList = np.array(xPixList) 

132 yPixList = np.array(yPixList) 

133 

134 xPupilList, yPupilList = \ 

135 pupilCoordsFromPixelCoords(xPixList, yPixList, 

136 nameList, camera=self.camera) 

137 

138 testAnswer = gsdet.containsPupilCoordinates(xPupilList, yPupilList) 

139 

140 for c, t in zip(correctAnswer, testAnswer): 

141 self.assertIs(c, t) 

142 

143 def testFitsHeaderKeywords(self): 

144 """ 

145 Test that the FITS header keywords with the observing information 

146 are set correctly. 

147 """ 

148 photParams = PhotometricParameters() 

149 gsdet = GalSimDetector(self.camera[0].getName(), 

150 GalSimCameraWrapper(self.camera), 

151 self.obs, self.epoch, 

152 photParams=photParams) 

153 self.assertEqual(gsdet.wcs.fitsHeader.getScalar('MJD-OBS'), 

154 self.obs.mjd.TAI) 

155 self.assertEqual(gsdet.wcs.fitsHeader.getScalar('EXPTIME'), 

156 photParams.nexp*photParams.exptime) 

157 self.assertEqual(gsdet.wcs.fitsHeader.getScalar('RATEL'), 

158 self.obs.pointingRA) 

159 self.assertEqual(gsdet.wcs.fitsHeader.getScalar('DECTEL'), 

160 self.obs.pointingDec) 

161 self.assertEqual(gsdet.wcs.fitsHeader.getScalar('ROTANGLE'), 

162 self.obs.rotSkyPos) 

163 

164 

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

166 pass 

167 

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

169 lsst.utils.tests.init() 

170 unittest.main()