Coverage for tests/test_setValidPolygonIntersect.py: 27%
62 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-29 03:26 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-29 03:26 -0700
1#
2# LSST Data Management System
3# Copyright 2008-2015 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
21#
23"""
24Tests setting of valid focal plane polygon intersection with ccd corners
26Run with:
27 python testSetValidPolygonIntersect.py
28or
29 python
30 >>> import testSetValidPolygonIntersect; testSetValidPolygonIntersect.run()
31"""
33import unittest
35import numpy as np
37import lsst.utils.tests
38import lsst.geom
39import lsst.afw.geom as afwGeom
40import lsst.afw.image as afwImage
41from lsst.ip.isr.vignette import setValidPolygonCcdIntersect
42from lsst.afw.cameraGeom.testUtils import DetectorWrapper
43from lsst.afw.cameraGeom import PIXELS, FOCAL_PLANE
46def makeCircularPolygon(fpCenterX, fpCenterY, fpRadius, numPolygonPoints):
47 theta = np.linspace(0, 2*np.pi, num=numPolygonPoints, endpoint=False)
48 xx = fpRadius*np.cos(theta) + fpCenterX
49 yy = fpRadius*np.sin(theta) + fpCenterY
50 points = np.array([xx, yy]).transpose()
51 polygon = afwGeom.Polygon([lsst.geom.Point2D(x, y) for x, y in reversed(points)])
52 return polygon
55def makeSquarePolygon(fpX0, fpY0, fpSize):
56 xx = [fpX0, fpX0, fpX0 + fpSize - 1, fpX0 + fpSize - 1, fpX0]
57 yy = [fpY0, fpY0 + fpSize - 1, fpY0 + fpSize - 1, fpY0, fpY0]
58 points = np.array([xx, yy]).transpose()
59 polygon = afwGeom.Polygon([lsst.geom.Point2D(x, y) for x, y in points])
60 return polygon
63class SetValidPolygonIntersectTestCase(lsst.utils.tests.TestCase):
64 """A test case for setting of valid focal plane polygon intersection with
65 ccd corners.
66 """
68 def testSetPolygonIntersect(self):
69 # Create a detector
70 detector = DetectorWrapper().detector
71 numPolygonPoints = 50
72 # Create an exposure with bounding box defined by detector
73 exposure = afwImage.ExposureF(detector.getBBox())
74 exposure.setDetector(detector)
76 pixelSizeMm = exposure.getDetector().getPixelSize()[0]
78 pixX0 = exposure.getX0()
79 pixY0 = exposure.getY0()
80 pixX1 = pixX0 + exposure.getWidth() - 1
81 pixY1 = pixY0 + exposure.getHeight() - 1
83 fpCenter = exposure.getDetector().getCenter(FOCAL_PLANE)
84 fpCenterX = fpCenter[0]
85 fpCenterY = fpCenter[1]
86 pixCenter = exposure.getDetector().getCenter(PIXELS)
88 # Make a polygon that encompases entire ccd (radius of 2*max of
89 # width/height)
90 fpRadius = 2.0*max(exposure.getWidth()*pixelSizeMm, exposure.getHeight()*pixelSizeMm)
91 fpPolygon = makeCircularPolygon(fpCenterX, fpCenterY, fpRadius, numPolygonPoints)
92 # Set the polygon that is the intersection of fpPolygon and ccd
93 setValidPolygonCcdIntersect(exposure, fpPolygon)
94 # Since the ccd is fully contained in the fpPolygon, the intersection
95 # should be the ccdPolygon itself
96 ccdPolygonPix = afwGeom.Polygon(exposure.getDetector().getCorners(PIXELS))
97 self.assertEqual(exposure.getInfo().getValidPolygon(), ccdPolygonPix)
99 # Make a polygon that is entirely within, but smaller than, the ccd
100 # (radius of 0.2*min of width/height)
101 fpRadius = 0.2*min(exposure.getWidth()*pixelSizeMm, exposure.getHeight()*pixelSizeMm)
102 fpPolygon = makeCircularPolygon(fpCenterX, fpCenterY, fpRadius, numPolygonPoints)
103 # Set the polygon that is the intersection of fpPolygon and ccd
104 setValidPolygonCcdIntersect(exposure, fpPolygon)
105 # all vertices of polygon should be contained within the ccd
106 for x in exposure.getInfo().getValidPolygon():
107 self.assertTrue(ccdPolygonPix.contains(lsst.geom.Point2D(x)))
108 # intersection is smaller than the ccd
109 self.assertNotEqual(exposure.getInfo().getValidPolygon(), ccdPolygonPix)
111 # make a simple square polygon that partly intersects the ccd, centered
112 # at ccd center
113 fpPolygonSize = max(exposure.getWidth()*pixelSizeMm, exposure.getHeight()*pixelSizeMm)
114 fpPolygon = makeSquarePolygon(fpCenterX, fpCenterY, fpPolygonSize)
115 setValidPolygonCcdIntersect(exposure, fpPolygon)
116 # Check that the polygon contains the central pixel (offset by one to
117 # actually be "contained")
118 pixCenterPlusOne = lsst.geom.Point2D(pixCenter[0] + 1, pixCenter[1] + 1)
119 self.assertTrue(exposure.getInfo().getValidPolygon().contains(lsst.geom.Point2D(pixCenterPlusOne)))
120 # Check that the polygon contains the upper right ccd edge
121 self.assertTrue(exposure.getInfo().getValidPolygon().contains(lsst.geom.Point2D(pixX1, pixY1)))
124class MemoryTester(lsst.utils.tests.MemoryTestCase):
125 pass
128def setup_module(module):
129 lsst.utils.tests.init()
132if __name__ == "__main__": 132 ↛ 133line 132 didn't jump to line 133, because the condition on line 132 was never true
133 lsst.utils.tests.init()
134 unittest.main()