Coverage for tests/testCameraUtils.py : 26%

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 numpy as np
4import lsst.utils.tests
5from lsst.sims.coordUtils import (chipNameFromPupilCoords,
6 _chipNameFromRaDec, chipNameFromRaDec,
7 _pixelCoordsFromRaDec, pixelCoordsFromRaDec,
8 pixelCoordsFromPupilCoords)
9from lsst.sims.utils import pupilCoordsFromRaDec, radiansFromArcsec
10from lsst.sims.utils import ObservationMetaData
11from lsst.obs.lsst.phosim import PhosimMapper
12from lsst.sims.utils import angularSeparation
14from lsst.sims.coordUtils import clean_up_lsst_camera
16def setup_module(module):
17 lsst.utils.tests.init()
20class ChipNameTestCase(unittest.TestCase):
22 longMessage = True
24 @classmethod
25 def setUpClass(cls):
26 cls.camera = PhosimMapper().camera
28 @classmethod
29 def tearDownClass(cls):
30 del cls.camera
31 clean_up_lsst_camera()
33 def test_outside_radius(self):
34 """
35 Test that methods can gracefully handle points
36 outside of the focal plane
37 """
38 rng = np.random.RandomState(7123)
39 ra = 145.0
40 dec = -25.0
41 obs = ObservationMetaData(pointingRA=ra, pointingDec=dec,
42 mjd=59580.0, rotSkyPos=113.0)
44 rr = rng.random_sample(100)*5.0
45 self.assertGreater(rr.max(), 4.5)
46 theta = rng.random_sample(100)*2.0*np.pi
47 ra_vec = ra + rr*np.cos(theta)
48 dec_vec = dec + rr*np.sin(theta)
49 chip_name_list = chipNameFromRaDec(ra_vec, dec_vec,
50 obs_metadata=obs, camera=self.camera)
52 rr = angularSeparation(ra, dec, ra_vec, dec_vec)
54 ct_none = 0
55 for rr, name in zip(rr, chip_name_list):
56 if rr > 2.0:
57 self.assertIsNone(name)
58 ct_none += 1
59 self.assertGreater(ct_none, 0)
61 def test_chip_center(self):
62 """
63 Test that, if we ask for the chip at the bore site,
64 we get back 'R:2,2 S:1,1'
65 """
67 ra = 145.0
68 dec = -25.0
69 obs = ObservationMetaData(pointingRA=ra, pointingDec=dec,
70 mjd=59580.0, rotSkyPos=113.0)
72 name = chipNameFromRaDec(ra, dec, obs_metadata=obs, camera=self.camera)
73 self.assertEqual(name, 'R22_S11')
75 def test_one_by_one(self):
76 """
77 test that running RA, Dec pairs in one at a time gives the same
78 results as running them in in batches
79 """
81 ra = 145.0
82 dec = -25.0
83 obs = ObservationMetaData(pointingRA=ra, pointingDec=dec,
84 mjd=59580.0, rotSkyPos=113.0)
85 rng = np.random.RandomState(100)
86 theta = rng.random_sample(100)*2.0*np.pi
87 rr = rng.random_sample(len(theta))*2.0
88 ra_list = ra + rr*np.cos(theta)
89 dec_list = dec + rr*np.sin(theta)
90 name_control = chipNameFromRaDec(ra_list, dec_list, obs_metadata=obs, camera=self.camera)
91 is_none = 0
92 for ra, dec, name in zip(ra_list, dec_list, name_control):
93 test_name = chipNameFromRaDec(ra, dec, obs_metadata=obs, camera=self.camera)
94 self.assertEqual(test_name, name)
95 if test_name is None:
96 is_none += 1
98 self.assertGreater(is_none, 0)
99 self.assertLess(is_none, (3*len(ra_list))//4)
102class MotionTestCase(unittest.TestCase):
103 """
104 This class will contain test methods to verify that the LSST camera utils
105 work correctly when proper motion, parallax, and v_rad are non-zero
106 """
107 @classmethod
108 def setUpClass(cls):
109 cls.camera = PhosimMapper().camera
111 @classmethod
112 def tearDownClass(cls):
113 del cls.camera
114 clean_up_lsst_camera()
116 def set_data(self, seed):
117 """
118 Accept a seed integer. Return an ObservationMetaData
119 and numpy arrays of RA, Dec (in degrees),
120 pm_ra, pm_dec, parallax (in arcsec) and v_rad (in km/s)
121 centered on that bore site.
122 """
123 rng = np.random.RandomState(seed)
124 n_obj = 30
125 ra = 23.1
126 dec = -15.6
127 rotSkyPos = 23.56
128 mjd = 59723.2
129 obs = ObservationMetaData(pointingRA=ra, pointingDec=dec,
130 rotSkyPos=rotSkyPos, mjd=mjd)
131 rr = rng.random_sample(n_obj)*1.75
132 theta = rng.random_sample(n_obj)*2.0*np.pi
133 ra_list = ra + rr*np.cos(theta)
134 dec_list = dec + rr*np.sin(theta)
135 pm_ra = rng.random_sample(n_obj)*20.0 - 10.0
136 pm_dec = rng.random_sample(n_obj)*20.0 - 10.0
137 parallax = rng.random_sample(n_obj)*1.0 - 0.5
138 v_rad = rng.random_sample(n_obj)*600.0 - 300.0
139 return obs, ra_list, dec_list, pm_ra, pm_dec, parallax, v_rad
142class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
143 pass
145if __name__ == "__main__": 145 ↛ 146line 145 didn't jump to line 146, because the condition on line 145 was never true
146 lsst.utils.tests.init()
147 unittest.main()