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 numpy as np 

3import lsst.utils.tests 

4import lsst.geom as LsstGeom 

5from lsst.sims.utils.CodeUtilities import sims_clean_up 

6from lsst.sims.utils import ObservationMetaData, haversine, arcsecFromRadians 

7from lsst.sims.GalSimInterface.wcsUtils import tanWcsFromDetector, tanSipWcsFromDetector 

8from lsst.sims.GalSimInterface import LSSTCameraWrapper 

9from lsst.sims.coordUtils import lsst_camera 

10 

11from lsst.sims.coordUtils import chipNameFromPupilCoordsLSST 

12from lsst.sims.coordUtils import focalPlaneCoordsFromPupilCoordsLSST 

13from lsst.sims.coordUtils import pupilCoordsFromFocalPlaneCoordsLSST 

14 

15 

16def setup_module(module): 

17 lsst.utils.tests.init() 

18 

19 

20class WcsTest(unittest.TestCase): 

21 

22 @classmethod 

23 def setUpClass(cls): 

24 

25 cls.camera_wrapper = LSSTCameraWrapper() 

26 cls.detector = cls.camera_wrapper.camera['R:1,1 S:2,2'] 

27 

28 cls.obs = ObservationMetaData(pointingRA=25.0, pointingDec=-10.0, 

29 boundType='circle', boundLength=1.0, 

30 mjd=49250.0, rotSkyPos=0.0, 

31 bandpassName='g') 

32 cls.epoch = 2000.0 

33 

34 @classmethod 

35 def tearDownClass(cls): 

36 sims_clean_up() 

37 del cls.detector 

38 del cls.camera_wrapper 

39 

40 if hasattr(chipNameFromPupilCoordsLSST, '_detector_arr'): 

41 del chipNameFromPupilCoordsLSST._detector_arr 

42 if hasattr(focalPlaneCoordsFromPupilCoordsLSST, '_z_fitter'): 

43 del focalPlaneCoordsFromPupilCoordsLSST._z_fitter 

44 if hasattr(pupilCoordsFromFocalPlaneCoordsLSST, '_z_fitter'): 

45 del pupilCoordsFromFocalPlaneCoordsLSST._z_fitter 

46 if hasattr(lsst_camera, '_lsst_camera'): 

47 del lsst_camera._lsst_camera 

48 

49 def testTanSipWcs(self): 

50 """ 

51 Test that tanSipWcsFromDetector works by fitting a TAN WCS and a TAN-SIP WCS to 

52 a detector with distortions and verifying that the TAN-SIP WCS better approximates 

53 the truth. 

54 """ 

55 

56 tanWcs = tanWcsFromDetector(self.detector.getName(), self.camera_wrapper, 

57 self.obs, self.epoch) 

58 tanSipWcs = tanSipWcsFromDetector(self.detector.getName(), self.camera_wrapper, 

59 self.obs, self.epoch) 

60 

61 tanWcsRa = [] 

62 tanWcsDec = [] 

63 tanSipWcsRa = [] 

64 tanSipWcsDec = [] 

65 

66 xPixList = [] 

67 yPixList = [] 

68 for xx in np.arange(0.0, 4001.0, 100.0): 

69 for yy in np.arange(0.0, 4001.0, 100.0): 

70 xPixList.append(xx) 

71 yPixList.append(yy) 

72 

73 pt = LsstGeom.Point2D(xx, yy) 

74 skyPt = tanWcs.pixelToSky(pt).getPosition(LsstGeom.degrees) 

75 tanWcsRa.append(skyPt.getX()) 

76 tanWcsDec.append(skyPt.getY()) 

77 

78 skyPt = tanSipWcs.pixelToSky(pt).getPosition(LsstGeom.degrees) 

79 tanSipWcsRa.append(skyPt.getX()) 

80 tanSipWcsDec.append(skyPt.getY()) 

81 

82 tanWcsRa = np.radians(np.array(tanWcsRa)) 

83 tanWcsDec = np.radians(np.array(tanWcsDec)) 

84 

85 tanSipWcsRa = np.radians(np.array(tanSipWcsRa)) 

86 tanSipWcsDec = np.radians(np.array(tanSipWcsDec)) 

87 

88 xPixList = np.array(xPixList) 

89 yPixList = np.array(yPixList) 

90 

91 (raTest, 

92 decTest) = self.camera_wrapper._raDecFromPixelCoords(xPixList, yPixList, 

93 [self.detector.getName()]*len(xPixList), 

94 obs_metadata=self.obs, 

95 epoch=self.epoch) 

96 

97 tanDistanceList = arcsecFromRadians(haversine(raTest, decTest, tanWcsRa, tanWcsDec)) 

98 tanSipDistanceList = arcsecFromRadians(haversine(raTest, decTest, tanSipWcsRa, tanSipWcsDec)) 

99 

100 maxDistanceTan = tanDistanceList.max() 

101 maxDistanceTanSip = tanSipDistanceList.max() 

102 

103 msg = 'max error in TAN WCS %e arcsec; in TAN-SIP %e arcsec' % (maxDistanceTan, maxDistanceTanSip) 

104 self.assertLess(maxDistanceTanSip, 0.01, msg=msg) 

105 self.assertGreater(maxDistanceTan-maxDistanceTanSip, 1.0e-10, msg=msg) 

106 

107 

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

109 pass 

110 

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

112 lsst.utils.tests.init() 

113 unittest.main()