Coverage for tests/test_dodecaSkyMap.py: 18%
90 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-11 02:49 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-11 02:49 -0800
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 neighbors
92 # explore the boundary between tract 0 and tract 1
93 # 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 tract 0 and tract 1,
99 # else explore the boundary between tract 0 and tract 2
101 if isNearest0:
102 expectedTractId = tractId0
103 elif exploreBoundary1:
104 expectedTractId = tractId1
105 else:
106 expectedTractId = tractId2
108 for farFrac in (0.0, 0.05, 0.3, (1.0/3.0) - 0.01):
109 # farFrac is the fraction of the tract center vector point whose boundary
110 # is not being explored; it must be less than 1/3;
111 # remFrac is the remaining fraction, which is divided between tract 0
112 # and the tract whose boundary is being explored
113 remFrac = 1.0 - farFrac
114 frac0 = (remFrac / 2.0) + deltaFrac
115 boundaryFrac = (remFrac / 2.0) - deltaFrac
117 if exploreBoundary1:
118 frac2 = farFrac
119 frac1 = boundaryFrac
120 else:
121 frac1 = farFrac
122 frac2 = boundaryFrac
124 testVector = (vector0 * frac0) + (vector1 * frac1) + (vector2 * frac2)
125 vecLen = math.sqrt(numpy.sum(testVector**2))
126 testVector /= vecLen
127 testCoord = geom.SpherePoint(lsst.sphgeom.Vector3d(*testVector))
128 nearestTractInfo = skyMap.findTract(testCoord)
129 nearestTractId = nearestTractInfo.getId()
131 if expectedTractId != nearestTractId:
132 nearestCtrCoord = nearestTractInfo.getCtrCoord()
133 nearestVector = nearestCtrCoord.getVector()
135 print("tractId0=%s; tractId1=%s; tractId2=%s; nearestTractId=%s" %
136 (tractId0, tractId1, tractId2, nearestTractId))
137 print("vector0=%s; vector1=%s; vector2=%s; nearestVector=%s" %
138 (vector0, vector1, vector2, nearestVector))
139 print("frac0=%s; frac1=%s; frac2=%s" % (frac0, frac1, frac2))
140 print("testVector=", testVector)
142 print("dist0=%s; dist1=%s; dist2=%s; nearDist=%s" % (
143 testCoord.separation(ctrCoord0).asDegrees(),
144 testCoord.separation(ctrCoord1).asDegrees(),
145 testCoord.separation(ctrCoord2).asDegrees(),
146 testCoord.separation(nearestCtrCoord).asDegrees(),
147 ))
148 self.fail("Expected nearest tractId=%s; got tractId=%s" %
149 (expectedTractId, nearestTractId))
151 patchInfo = nearestTractInfo.findPatch(testCoord)
152 pixelInd = geom.Point2I(
153 nearestTractInfo.getWcs().skyToPixel(testCoord))
154 self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd))
157def getCornerCoords(wcs, bbox):
158 """Return the coords of the four corners of a bounding box
159 """
160 bbox = geom.Box2D(bbox) # mak
161 cornerPosList = (
162 bbox.getMin(),
163 geom.Point2D(bbox.getMaxX(), bbox.getMinY()),
164 bbox.getMax(),
165 geom.Point2D(bbox.getMinX(), bbox.getMaxY()),
166 )
167 return wcs.pixelToSky(cornerPosList)
170class MemoryTester(lsst.utils.tests.MemoryTestCase):
171 pass
174def setup_module(module):
175 lsst.utils.tests.init()
178if __name__ == "__main__": 178 ↛ 179line 178 didn't jump to line 179, because the condition on line 178 was never true
179 lsst.utils.tests.init()
180 unittest.main()