Coverage for tests/test_ringsSkyMap.py: 21%
117 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-20 11:10 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-20 11:10 +0000
1import unittest
2import math
3import numpy as np
5import lsst.utils.tests
6import lsst.geom
8from lsst.skymap.ringsSkyMap import RingsSkyMap
9from helper import skyMapTestCase
12class RingsTestCase(skyMapTestCase.SkyMapTestCase):
14 def setUp(self):
15 config = RingsSkyMap.ConfigClass()
16 config.numRings = 3
17 self.setAttributes(
18 SkyMapClass=RingsSkyMap,
19 name="rings",
20 config=config,
21 numTracts=26,
22 neighborAngularSeparation=None, # no uniform tract separation
23 numNeighbors=None, # ignored because neighborAngularSeparation=None
24 )
26 def testPoles(self):
27 """Test that findAllTracts behaves at the poles
29 Testing fix to DM-10686.
30 """
31 skymap = self.getSkyMap()
32 for ra in (0, 123, 321, 359.9):
33 tracts = skymap.findAllTracts(lsst.geom.SpherePoint(ra, 90, lsst.geom.degrees))
34 self.assertListEqual(tracts, [skymap[len(skymap) - 1]])
35 tracts = skymap.findAllTracts(lsst.geom.SpherePoint(ra, -90, lsst.geom.degrees))
36 self.assertListEqual(tracts, [skymap[0]])
38 def testSha1Compare(self):
39 """Test that RingsSkyMap's extra state is included in its hash."""
40 defaultSkyMap = self.getSkyMap()
41 for numRings in (4, 5):
42 config = self.getConfig()
43 config.numRings = numRings
44 skyMap = self.getSkyMap(config=config)
45 self.assertNotEqual(skyMap, defaultSkyMap)
46 for raStart in (60.0, 75.0):
47 config = self.getConfig()
48 config.raStart = raStart
49 skyMap = self.getSkyMap(config=config)
50 self.assertNotEqual(skyMap, defaultSkyMap)
52 def testCorners(self):
53 """Test that corners of a tract can be found in the tract"""
54 skymap = self.getSkyMap()
55 for tract in skymap:
56 vertices = tract.getVertexList()
57 for coord in vertices:
58 self.assertIn(tract.getId(), [tt.getId() for tt in skymap.findAllTracts(coord)])
61class NonzeroRaStartRingsTestCase(RingsTestCase):
62 """Test that setting raStart != 0 works"""
63 def getConfig(self):
64 config = super().getConfig()
65 config.raStart = 234
66 return config
69class HscRingsTestCase(lsst.utils.tests.TestCase):
70 def getConfig(self):
71 """Return a configuration matching that used for the HSC SSP"""
72 config = RingsSkyMap.ConfigClass()
73 config.numRings = 120
74 config.projection = "TAN"
75 config.tractOverlap = 1.0/60 # Overlap between tracts (degrees)
76 config.pixelScale = 0.168
77 return config
79 def setUp(self):
80 self.skymap = RingsSkyMap(self.getConfig())
82 def tearDown(self):
83 del self.skymap
85 def testDm7770(self):
86 """Test that DM-7770 has been fixed
88 These operations previously caused:
89 lsst::pex::exceptions::RuntimeError: 'Error: wcslib
90 returned a status code of 9 at sky 30.18, -3.8 deg:
91 One or more of the world coordinates were invalid'
93 We are only testing function, and not the actual results.
94 """
95 coordList = [lsst.geom.SpherePoint(ra, dec, lsst.geom.degrees) for
96 ra, dec in [(30.18, -3.8), (31.3, -3.8), (31.3, -2.7), (30.18, -2.7)]]
97 for coord in coordList:
98 self.skymap.findAllTracts(coord)
99 self.skymap.findTractPatchList(coordList)
101 def testDm14809(self):
102 """Test that DM-14809 has been fixed"""
103 skyMapTestCase.checkDm14809(self, self.skymap)
105 # Check that the first tract in the last ring exists
106 coord = self.getFirstTractLastRingCoord()
107 tract = self.skymap.findTract(coord)
108 self.assertTrue(tract.contains(coord))
110 tractId = self.skymap.findTractIdArray(coord.getLongitude().asRadians(),
111 coord.getLatitude().asRadians(),
112 degrees=False)
113 self.assertEqual(tractId[0], tract.getId())
115 def testWraparound(self):
116 """Check wrapping at RA=0
118 How-to-reproduce of a bug identified by Sogo Mineo.
119 """
120 tractId = 9712
121 deviation = 10 / 3600.0 # 10 arcsec
122 tract = self.skymap[tractId]
123 center = tract.getCtrCoord()
124 centerRa = center.getRa().asDegrees()
125 centerDec = center.getDec().asDegrees()
126 for devRa in [-deviation, deviation]:
127 coord = lsst.geom.SpherePoint(centerRa + devRa, centerDec, lsst.geom.degrees)
128 foundTractId = self.skymap.findTract(coord).getId()
129 self.assertEqual(tractId, foundTractId)
131 foundTractArrayId = self.skymap.findTractIdArray([centerRa + devRa],
132 [centerDec],
133 degrees=True)
134 self.assertEqual(tractId, foundTractArrayId[0])
136 def testFindTractIdArray(self):
137 """Test findTractIdArray.
139 Test an array of positions to ensure that ``findTract`` and
140 ``findTractIdArray`` give the same answers.
141 """
142 np.random.seed(12345)
144 ras = np.random.uniform(low=0.0, high=360.0, size=1000)
145 decs = np.random.uniform(low=-90.0, high=90.0, size=1000)
147 coords = [lsst.geom.SpherePoint(ra*lsst.geom.degrees, dec*lsst.geom.degrees)
148 for ra, dec in zip(ras, decs)]
150 indexes = [self.skymap.findTract(coord).getId() for coord in coords]
151 indexes2 = self.skymap.findTractIdArray(ras, decs, degrees=True)
153 np.testing.assert_array_equal(indexes2, indexes)
155 def getFirstTractLastRingCoord(self):
156 """Return the coordinates of the first tract in the last ring
158 This tract is missing in version=0, but this is fixed in version=1.in
159 """
160 ringNum = self.skymap.config.numRings - 1
161 ringSize = math.pi/(self.skymap.config.numRings + 1)
162 firstRingStart = ringSize*0.5 - 0.5*math.pi
163 dec = ringNum*ringSize + firstRingStart
164 return lsst.geom.SpherePoint(self.skymap.config.raStart*lsst.geom.degrees,
165 dec*lsst.geom.radians)
168class Version0HscRingsTestCase(HscRingsTestCase):
169 """Testing that the version=0 RingsSkyMap works in the expected way"""
170 def setUp(self):
171 self.skymap = RingsSkyMap(self.getConfig(), version=0)
173 def testDm14809(self):
174 """Test that DM-14809 has been partially fixed
176 The observed behaviour was:
178 skyMap.findTract(skyMap[9712].getCtrCoord()).getId() != 9712
180 and
182 skyMap[1].getCtrCoord() == skyMap[11].getCtrCoord()
184 Specifically for version=0, we fixed the ``findTract`` behaviour but
185 left the tract duplication (tract 11 duplicates tract 1) and the
186 missing tract (the first tract in the last ring) so that the tract
187 numbering would remain unchanged.
188 """
189 # Check that the tract found for central coordinate of a tract is that
190 # tract.
191 expect = [tract.getId() for tract in self.skymap]
192 expect[self.skymap._ringNums[0] + 1] = 1 # Due to the bug
193 got = [self.skymap.findTract(tract.getCtrCoord()).getId() for tract in self.skymap]
194 self.assertEqual(got, expect)
196 # Check that the tract central coordinates are unique
197 # Round to integer arcminutes so differences are relatively immune to
198 # small numerical inaccuracies.
199 centers = set([(int(coord.getRa().asArcminutes()), int(coord.getDec().asArcminutes())) for
200 coord in (tract.getCtrCoord() for tract in self.skymap)])
201 self.assertEqual(len(centers), len(self.skymap) - 1) # One tract is duplicated
202 self.assertEqual(self.skymap[1].getCtrCoord(),
203 self.skymap[self.skymap._ringNums[0] + 1].getCtrCoord()) # This is the duplicate
205 # Check that some particular tracts we know and love haven't moved
206 degrees = lsst.geom.degrees
207 # 9712 is at RA=0, and was identified as problematic in DM-14809
208 self.assertEqual(self.skymap[9712].getCtrCoord(),
209 lsst.geom.SpherePoint(0.0*degrees, 0.7438016528925696*degrees))
210 # The Cosmos field
211 self.assertEqual(self.skymap[9813].getCtrCoord(),
212 lsst.geom.SpherePoint(150.2479338842975*degrees, 2.2314049586776834*degrees))
214 # Check that the first tract in the last ring does NOT exist
215 # (due to the bug).
216 coord = self.getFirstTractLastRingCoord()
217 tract = self.skymap.findTract(coord)
218 self.assertFalse(tract.contains(coord))
221class MemoryTester(lsst.utils.tests.MemoryTestCase):
222 pass
225def setup_module(module):
226 lsst.utils.tests.init()
229if __name__ == "__main__": 229 ↛ 230line 229 didn't jump to line 230, because the condition on line 229 was never true
230 lsst.utils.tests.init()
231 unittest.main()