Coverage for tests/testGalSimDetector.py : 24%

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
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
16def setup_module(module):
17 lsst.utils.tests.init()
19@unittest.skip('ReturnCamera deprecated - need replacement')
20class GalSimDetectorTest(unittest.TestCase):
22 @classmethod
23 def tearDownClass(cls):
24 sims_clean_up()
26 def setUp(self):
27 baseDir = os.path.join(getPackageDir('sims_GalSimInterface'),
28 'tests', 'cameraData')
30 self.camera = ReturnCamera(baseDir)
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)
44 def tearDown(self):
45 del self.camera
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 """
53 photParams = PhotometricParameters()
54 gsdet = GalSimDetector(self.camera[0].getName(),
55 GalSimCameraWrapper(self.camera),
56 self.obs, self.epoch,
57 photParams=photParams)
59 xxList = [gsdet.xMinPix, gsdet.xMaxPix]
60 yyList = [gsdet.yMinPix, gsdet.yMaxPix]
61 dxList = [-1.0, 1.0]
62 dyList = [-1.0, 1.0]
64 xPixList = []
65 yPixList = []
66 correctAnswer = []
68 for xx, yy, dx, dy in zip(xxList, yyList, dxList, dyList):
69 xPixList.append(xx)
70 yPixList.append(yy)
71 correctAnswer.append(True)
73 xPixList.append(xx+dx)
74 yPixList.append(yy)
75 correctAnswer.append(False)
77 xPixList.append(xx)
78 yPixList.append(yy+dy)
79 correctAnswer.append(False)
81 nameList = [gsdet.name]*len(xPixList)
82 xPixList = np.array(xPixList)
83 yPixList = np.array(yPixList)
85 raList, decList = _raDecFromPixelCoords(xPixList, yPixList,
86 nameList,
87 camera=self.camera,
88 obs_metadata=self.obs,
89 epoch=self.epoch)
91 testAnswer = gsdet.containsRaDec(raList, decList)
93 for c, t in zip(correctAnswer, testAnswer):
94 self.assertIs(c, t)
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 """
102 photParams = PhotometricParameters()
103 gsdet = GalSimDetector(self.camera[0].getName(),
104 GalSimCameraWrapper(self.camera),
105 self.obs, self.epoch,
106 photParams=photParams)
108 xxList = [gsdet.xMinPix, gsdet.xMaxPix]
109 yyList = [gsdet.yMinPix, gsdet.yMaxPix]
110 dxList = [-1.0, 1.0]
111 dyList = [-1.0, 1.0]
113 xPixList = []
114 yPixList = []
115 correctAnswer = []
117 for xx, yy, dx, dy in zip(xxList, yyList, dxList, dyList):
118 xPixList.append(xx)
119 yPixList.append(yy)
120 correctAnswer.append(True)
122 xPixList.append(xx+dx)
123 yPixList.append(yy)
124 correctAnswer.append(False)
126 xPixList.append(xx)
127 yPixList.append(yy+dy)
128 correctAnswer.append(False)
130 nameList = [gsdet.name]*len(xPixList)
131 xPixList = np.array(xPixList)
132 yPixList = np.array(yPixList)
134 xPupilList, yPupilList = \
135 pupilCoordsFromPixelCoords(xPixList, yPixList,
136 nameList, camera=self.camera)
138 testAnswer = gsdet.containsPupilCoordinates(xPupilList, yPupilList)
140 for c, t in zip(correctAnswer, testAnswer):
141 self.assertIs(c, t)
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)
165class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
166 pass
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()