Coverage for tests/testAfwCameraGeomAPI.py : 31%

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
5import numpy as np
6import os
8from lsst.sims.utils import ObservationMetaData
9from lsst.sims.coordUtils import lsst_camera
10from lsst.sims.coordUtils import getCornerRaDec
11from lsst.sims.coordUtils import focalPlaneCoordsFromRaDec
12from lsst.sims.coordUtils import pixelCoordsFromRaDec
13from lsst.sims.coordUtils import chipNameFromRaDec
14from lsst.sims.coordUtils import chipNameFromPupilCoords
16from lsst.sims.coordUtils import clean_up_lsst_camera
18def setup_module(module):
19 lsst.utils.tests.init()
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_lsstSim 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
31 $SIM_COORDUTILS_DIR/tests/lsstCameraData/make_test_catalog.py
32 """
34 @classmethod
35 def setUpClass(cls):
36 cls.camera = lsst_camera()
37 cls.data_dir = os.path.join(getPackageDir('sims_coordUtils'),
38 'tests', 'lsstCameraData')
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)])
45 cls.pix_data = np.genfromtxt(os.path.join(cls.data_dir,
46 'lsst_pixel_data.txt'),
47 delimiter=';', dtype=pix_dtype)
49 ra = 25.0
50 dec = -62.0
51 cls.obs = ObservationMetaData(pointingRA=ra, pointingDec=dec,
52 rotSkyPos=57.2, mjd=59586.2)
54 @classmethod
55 def tearDownClass(cls):
56 del cls.camera
57 clean_up_lsst_camera()
59 def test_chipName(self):
60 """
61 Verify that chipNameFromRaDecLSST has not changed.
62 """
63 chip_name_arr = chipNameFromRaDec(self.pix_data['ra'],
64 self.pix_data['dec'],
65 obs_metadata=self.obs,
66 camera=self.camera)
68 np.testing.assert_array_equal(chip_name_arr, self.pix_data['name'])
70 def test_pixelCoords(self):
71 """
72 Verify that pixelCoordsFromRaDecLSST has not changed
73 """
74 pix_x, pix_y = pixelCoordsFromRaDec(self.pix_data['ra'],
75 self.pix_data['dec'],
76 obs_metadata=self.obs,
77 camera=self.camera)
79 np.testing.assert_array_almost_equal(pix_x, self.pix_data['pixel_x'],
80 decimal=3)
81 np.testing.assert_array_almost_equal(pix_y, self.pix_data['pixel_y'],
82 decimal=3)
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)
94 np.testing.assert_array_almost_equal(foc_x, self.pix_data['focal_x'],
95 decimal=5)
96 np.testing.assert_array_almost_equal(foc_y, self.pix_data['focal_y'],
97 decimal=5)
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)])
109 data = np.genfromtxt(os.path.join(self.data_dir, 'lsst_camera_corners.txt'),
110 dtype=dtype, delimiter=';')
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)
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]
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)
145class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
146 pass
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()