Coverage for tests / test_wcsSelectImages.py: 45%
61 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 08:30 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 08:30 +0000
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 excludeDetectors=[], dataId=None):
89 config = CoaddBaseTask.ConfigClass()
90 config.select.retarget(WcsSelectImagesTask)
91 config.select.excludeDetectors = excludeDetectors
92 task = CoaddBaseTask(config=config, name="CoaddBase")
94 cornerPosList = geom.Box2D(patch.getOuterBBox()).getCorners()
95 coordList = [patchWcs.pixelToSky(pos) for pos in cornerPosList]
97 result = task.select.run([wcs], [bbox], coordList, dataIds=[dataId])
99 numExpected = numExpected if doesOverlap else 0
100 self.assertEqual(len(result), numExpected)
102 def testIdentical(self):
103 self.check(*createPatch(), *createImage(), True)
105 def testImageContains(self):
106 self.check(*createPatch(), *createImage(scale=2*SCALE), True)
108 def testImageContained(self):
109 self.check(*createPatch(), *createImage(scale=0.5*SCALE), True)
111 def testDisjoint(self):
112 self.check(*createPatch(),
113 *createImage(center=geom.SpherePoint(0, -90, geom.degrees)),
114 False)
116 def testIntersect(self):
117 self.check(*createPatch(), *createImage(rotateAngle=0.5*geom.Extent2D(DIMS).computeNorm()*SCALE),
118 True)
120 def testWcsNone(self):
121 self.check(*createPatch(), *createImage(noWcs=True), True, numExpected=0)
123 def testExcludeDetectors(self):
124 self.check(*createPatch(), *createImage(), True, numExpected=0,
125 excludeDetectors=[5], dataId={"detector": 5})
128class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
129 pass
132def setup_module(module):
133 lsst.utils.tests.init()
136if __name__ == "__main__": 136 ↛ 137line 136 didn't jump to line 137 because the condition on line 136 was never true
137 lsst.utils.tests.init()
138 unittest.main()