Coverage for tests/test_wcsSelectImages.py: 44%
58 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-12 01:56 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-12 01:56 -0700
1#
2# LSST Data Management System
3# Copyright 2008-2013 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#
23import unittest
25import lsst.utils.tests
26import lsst.geom as geom
27import lsst.afw.geom as afwGeom
28from lsst.pipe.tasks.selectImages import WcsSelectImagesTask
29from lsst.pipe.tasks.coaddBase import CoaddBaseTask
32class DummyPatch:
34 """Quacks like a lsst.skymap.PatchInfo"""
36 def __init__(self, xy0, dims):
37 self._outerBBox = geom.Box2I(xy0, dims)
39 def getOuterBBox(self):
40 return self._outerBBox
43# Common defaults for createPatch and createImage
44CENTER = geom.SpherePoint(0, 90, geom.degrees)
45ROTATEAXIS = geom.SpherePoint(0, 0, geom.degrees)
46DIMS = geom.Extent2I(3600, 3600)
47SCALE = 0.5*geom.arcseconds
50def createPatch(
51 tractId=1, patchId=(2, 3), # Tract and patch identifier, for dataId
52 dims=DIMS, # Patch dimensions (Extent2I)
53 xy0=geom.Point2I(1234, 5678), # Patch xy0 (Point2I)
54 center=CENTER, # ICRS sky position of center (lsst.afw.geom.SpherePoint)
55 scale=SCALE # Pixel scale (Angle)
56):
57 crpix = geom.Point2D(xy0) + geom.Extent2D(dims)*0.5
58 cdMatrix = afwGeom.makeCdMatrix(scale=scale)
59 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=center, cdMatrix=cdMatrix)
60 patch = DummyPatch(xy0, dims)
61 # tract = DummyTract(patchId, patch, wcs)
62 # skymap = DummySkyMap(tractId, tract)
63 return patch, wcs
66def createImage(
67 dataId={"name": "foobar"}, # Data identifier
68 center=CENTER, # ICRS sky position of center (lsst.afw.geom.SpherePoint)
69 rotateAxis=ROTATEAXIS, # Rotation axis (lsst.afw.geom.SpherePoint)
70 rotateAngle=0*geom.degrees, # Rotation angle/distance to move (Angle)
71 dims=DIMS, # Image dimensions (Extent2I)
72 scale=SCALE, # Pixel scale (Angle)
73 noWcs=False, # Set WCS to None
74):
75 crpix = geom.Point2D(geom.Extent2D(dims)*0.5)
76 center = center.rotated(rotateAxis, rotateAngle)
77 cdMatrix = afwGeom.makeCdMatrix(scale=scale)
78 if noWcs:
79 wcs = None
80 else:
81 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=center, cdMatrix=cdMatrix)
82 return wcs, geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(dims[0], dims[1]))
85class WcsSelectImagesTestCase(unittest.TestCase):
87 def check(self, patch, patchWcs, wcs, bbox, doesOverlap, numExpected=1):
88 config = CoaddBaseTask.ConfigClass()
89 config.select.retarget(WcsSelectImagesTask)
90 task = CoaddBaseTask(config=config, name="CoaddBase")
92 cornerPosList = geom.Box2D(patch.getOuterBBox()).getCorners()
93 coordList = [patchWcs.pixelToSky(pos) for pos in cornerPosList]
95 result = task.select.run([wcs], [bbox], coordList)
97 numExpected = numExpected if doesOverlap else 0
98 self.assertEqual(len(result), numExpected)
100 def testIdentical(self):
101 self.check(*createPatch(), *createImage(), True)
103 def testImageContains(self):
104 self.check(*createPatch(), *createImage(scale=2*SCALE), True)
106 def testImageContained(self):
107 self.check(*createPatch(), *createImage(scale=0.5*SCALE), True)
109 def testDisjoint(self):
110 self.check(*createPatch(),
111 *createImage(center=geom.SpherePoint(0, -90, geom.degrees)),
112 False)
114 def testIntersect(self):
115 self.check(*createPatch(), *createImage(rotateAngle=0.5*geom.Extent2D(DIMS).computeNorm()*SCALE),
116 True)
118 def testWcsNone(self):
119 self.check(*createPatch(), *createImage(noWcs=True), True, numExpected=0)
122class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
123 pass
126def setup_module(module):
127 lsst.utils.tests.init()
130if __name__ == "__main__": 130 ↛ 131line 130 didn't jump to line 131, because the condition on line 130 was never true
131 lsst.utils.tests.init()
132 unittest.main()