Coverage for tests/test_dodecaSkyMap.py: 18%
90 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-26 10:03 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-26 10:03 +0000
1#
2# LSST Data Management System
3# Copyright 2008, 2009, 2010 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
22"""Test DodecaSkyMap class
23"""
24import math
25import unittest
27import numpy
29import lsst.sphgeom
30import lsst.geom as geom
31import lsst.utils.tests
33from lsst.skymap import DodecaSkyMap
34from helper import skyMapTestCase
37# dodecahedron properties
38_Phi = (1.0 + math.sqrt(5.0)) / 2.0
39_DihedralAngle = geom.Angle(2.0 * math.atan(_Phi), geom.radians)
42class DodecaSkyMapTestCase(skyMapTestCase.SkyMapTestCase):
44 def setUp(self):
45 self.setAttributes(
46 SkyMapClass=DodecaSkyMap,
47 name="dodeca",
48 numNeighbors=6,
49 numTracts=12,
50 neighborAngularSeparation=180*geom.degrees - _DihedralAngle,
51 )
53 def testSha1Compare(self):
54 """Test that DodecaSkyMap's extra state is included in its hash."""
55 defaultSkyMap = self.getSkyMap()
56 config = self.getConfig()
57 config.withTractsOnPoles = True
58 skyMap = self.getSkyMap(config=config)
59 self.assertNotEqual(skyMap, defaultSkyMap)
61 def testFindTract(self):
62 """Test findTract and tractInfo.findPatch
63 """
64 skyMap = DodecaSkyMap()
65 for tractInfo0 in skyMap:
66 tractId0 = tractInfo0.getId()
67 ctrCoord0 = tractInfo0.getCtrCoord()
68 vector0 = numpy.array(ctrCoord0.getVector())
70 # make a list of all 5 nearest neighbors
71 nbrTractList = []
72 for otherTractInfo in skyMap:
73 otherCtrCoord = otherTractInfo.getCtrCoord()
74 dist = ctrCoord0.separation(otherCtrCoord)
75 if abs(dist - self.neighborAngularSeparation) < geom.Angle(0.1, geom.degrees):
76 nbrTractList.append(otherTractInfo)
77 self.assertEqual(len(nbrTractList), 5)
79 for tractInfo1 in nbrTractList:
80 tractId1 = tractInfo1.getId()
81 ctrCoord1 = tractInfo1.getCtrCoord()
82 vector1 = numpy.array(ctrCoord1.getVector())
83 for tractInfo2 in nbrTractList[tractInfo1.getId():]:
84 dist = ctrCoord1.separation(tractInfo2.getCtrCoord())
85 if abs(dist - self.neighborAngularSeparation) > geom.Angle(0.1, geom.degrees):
86 continue
87 tractId2 = tractInfo2.getId()
88 ctrCoord2 = tractInfo2.getCtrCoord()
89 vector2 = numpy.array(ctrCoord2.getVector())
91 # Sky tracts 0, 1 and 2 form a triangle of nearest
92 # neighbors explore the boundary between tract 0 and tract
93 # 1 and also the boundary between tract 0 and tract 2.
94 for deltaFrac in (-0.001, 0.001):
95 isNearest0 = deltaFrac > 0.0
97 for exploreBoundary1 in (True, False):
98 # If exploreBoundary1, explore boundary between
99 # tract 0 and tract 1,
100 # else explore the boundary between tract 0 and
101 # tract 2.
103 if isNearest0:
104 expectedTractId = tractId0
105 elif exploreBoundary1:
106 expectedTractId = tractId1
107 else:
108 expectedTractId = tractId2
110 for farFrac in (0.0, 0.05, 0.3, (1.0/3.0) - 0.01):
111 # farFrac is the fraction of the tract center
112 # vector point whose boundary is not being
113 # explored; it must be less than 1/3;
114 # remFrac is the remaining fraction, which is
115 # divided between tract 0 and the tract whose
116 # boundary is being explored
117 remFrac = 1.0 - farFrac
118 frac0 = (remFrac / 2.0) + deltaFrac
119 boundaryFrac = (remFrac / 2.0) - deltaFrac
121 if exploreBoundary1:
122 frac2 = farFrac
123 frac1 = boundaryFrac
124 else:
125 frac1 = farFrac
126 frac2 = boundaryFrac
128 testVector = (vector0 * frac0) + (vector1 * frac1) + (vector2 * frac2)
129 vecLen = math.sqrt(numpy.sum(testVector**2))
130 testVector /= vecLen
131 testCoord = geom.SpherePoint(lsst.sphgeom.Vector3d(*testVector))
132 nearestTractInfo = skyMap.findTract(testCoord)
133 nearestTractId = nearestTractInfo.getId()
135 if expectedTractId != nearestTractId:
136 nearestCtrCoord = nearestTractInfo.getCtrCoord()
137 nearestVector = nearestCtrCoord.getVector()
139 print("tractId0=%s; tractId1=%s; tractId2=%s; nearestTractId=%s" %
140 (tractId0, tractId1, tractId2, nearestTractId))
141 print("vector0=%s; vector1=%s; vector2=%s; nearestVector=%s" %
142 (vector0, vector1, vector2, nearestVector))
143 print("frac0=%s; frac1=%s; frac2=%s" % (frac0, frac1, frac2))
144 print("testVector=", testVector)
146 print("dist0=%s; dist1=%s; dist2=%s; nearDist=%s" % (
147 testCoord.separation(ctrCoord0).asDegrees(),
148 testCoord.separation(ctrCoord1).asDegrees(),
149 testCoord.separation(ctrCoord2).asDegrees(),
150 testCoord.separation(nearestCtrCoord).asDegrees(),
151 ))
152 self.fail("Expected nearest tractId=%s; got tractId=%s" %
153 (expectedTractId, nearestTractId))
155 patchInfo = nearestTractInfo.findPatch(testCoord)
156 pixelInd = geom.Point2I(
157 nearestTractInfo.getWcs().skyToPixel(testCoord))
158 self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd))
161def getCornerCoords(wcs, bbox):
162 """Return the coords of the four corners of a bounding box
163 """
164 bbox = geom.Box2D(bbox) # mak
165 cornerPosList = (
166 bbox.getMin(),
167 geom.Point2D(bbox.getMaxX(), bbox.getMinY()),
168 bbox.getMax(),
169 geom.Point2D(bbox.getMinX(), bbox.getMaxY()),
170 )
171 return wcs.pixelToSky(cornerPosList)
174class MemoryTester(lsst.utils.tests.MemoryTestCase):
175 pass
178def setup_module(module):
179 lsst.utils.tests.init()
182if __name__ == "__main__": 182 ↛ 183line 182 didn't jump to line 183, because the condition on line 182 was never true
183 lsst.utils.tests.init()
184 unittest.main()