Coverage for tests/test_wcsSelectImages.py: 52%
54 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-12 01:27 -0700
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-12 01:27 -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):
74 crpix = geom.Point2D(geom.Extent2D(dims)*0.5)
75 center = center.rotated(rotateAxis, rotateAngle)
76 cdMatrix = afwGeom.makeCdMatrix(scale=scale)
77 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=center, cdMatrix=cdMatrix)
78 return wcs, geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(dims[0], dims[1]))
81class WcsSelectImagesTestCase(unittest.TestCase):
83 def check(self, patch, patchWcs, wcs, bbox, doesOverlap):
84 config = CoaddBaseTask.ConfigClass()
85 config.select.retarget(WcsSelectImagesTask)
86 task = CoaddBaseTask(config=config, name="CoaddBase")
88 cornerPosList = geom.Box2D(patch.getOuterBBox()).getCorners()
89 coordList = [patchWcs.pixelToSky(pos) for pos in cornerPosList]
91 result = task.select.run([wcs], [bbox], coordList)
93 numExpected = 1 if doesOverlap else 0
94 self.assertEqual(len(result), numExpected)
96 def testIdentical(self):
97 self.check(*createPatch(), *createImage(), True)
99 def testImageContains(self):
100 self.check(*createPatch(), *createImage(scale=2*SCALE), True)
102 def testImageContained(self):
103 self.check(*createPatch(), *createImage(scale=0.5*SCALE), True)
105 def testDisjoint(self):
106 self.check(*createPatch(),
107 *createImage(center=geom.SpherePoint(0, -90, geom.degrees)),
108 False)
110 def testIntersect(self):
111 self.check(*createPatch(), *createImage(rotateAngle=0.5*geom.Extent2D(DIMS).computeNorm()*SCALE),
112 True)
115class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
116 pass
119def setup_module(module):
120 lsst.utils.tests.init()
123if __name__ == "__main__": 123 ↛ 124line 123 didn't jump to line 124, because the condition on line 123 was never true
124 lsst.utils.tests.init()
125 unittest.main()