Coverage for tests/test_setValidPolygonIntersect.py: 31%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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.isrTask import IsrTask
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 ccd corners """
66 def testSetPolygonIntersect(self):
67 # Create a detector
68 detector = DetectorWrapper().detector
69 numPolygonPoints = 50
70 # Create an exposure with bounding box defined by detector
71 exposure = afwImage.ExposureF(detector.getBBox())
72 exposure.setDetector(detector)
74 pixelSizeMm = exposure.getDetector().getPixelSize()[0]
76 pixX0 = exposure.getX0()
77 pixY0 = exposure.getY0()
78 pixX1 = pixX0 + exposure.getWidth() - 1
79 pixY1 = pixY0 + exposure.getHeight() - 1
81 fpCenter = exposure.getDetector().getCenter(FOCAL_PLANE)
82 fpCenterX = fpCenter[0]
83 fpCenterY = fpCenter[1]
84 pixCenter = exposure.getDetector().getCenter(PIXELS)
86 # Create an instance of IsrTask
87 task = IsrTask()
89 # Make a polygon that encompases entire ccd (radius of 2*max of 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 task.setValidPolygonIntersect(exposure, fpPolygon)
94 # Since the ccd is fully contained in the fpPolygon, the intersection should be the ccdPolygon itself
95 ccdPolygonPix = afwGeom.Polygon(exposure.getDetector().getCorners(PIXELS))
96 self.assertEqual(exposure.getInfo().getValidPolygon(), ccdPolygonPix)
98 # Make a polygon that is entirely within, but smaller than, the ccd
99 # (radius of 0.2*min of width/height)
100 fpRadius = 0.2*min(exposure.getWidth()*pixelSizeMm, exposure.getHeight()*pixelSizeMm)
101 fpPolygon = makeCircularPolygon(fpCenterX, fpCenterY, fpRadius, numPolygonPoints)
102 # Set the polygon that is the intersection of fpPolygon and ccd
103 task.setValidPolygonIntersect(exposure, fpPolygon)
104 # all vertices of polygon should be contained within the ccd
105 for x in exposure.getInfo().getValidPolygon():
106 self.assertTrue(ccdPolygonPix.contains(lsst.geom.Point2D(x)))
107 # intersection is smaller than the ccd
108 self.assertNotEqual(exposure.getInfo().getValidPolygon(), ccdPolygonPix)
110 # make a simple square polygon that partly intersects the ccd, centered at ccd center
111 fpPolygonSize = max(exposure.getWidth()*pixelSizeMm, exposure.getHeight()*pixelSizeMm)
112 fpPolygon = makeSquarePolygon(fpCenterX, fpCenterY, fpPolygonSize)
113 task.setValidPolygonIntersect(exposure, fpPolygon)
114 # Check that the polygon contains the central pixel (offset by one to actually be "contained")
115 pixCenterPlusOne = lsst.geom.Point2D(pixCenter[0] + 1, pixCenter[1] + 1)
116 self.assertTrue(exposure.getInfo().getValidPolygon().contains(lsst.geom.Point2D(pixCenterPlusOne)))
117 # Check that the polygon contains the upper right ccd edge
118 self.assertTrue(exposure.getInfo().getValidPolygon().contains(lsst.geom.Point2D(pixX1, pixY1)))
121class MemoryTester(lsst.utils.tests.MemoryTestCase):
122 pass
125def setup_module(module):
126 lsst.utils.tests.init()
129if __name__ == "__main__": 129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never true
130 lsst.utils.tests.init()
131 unittest.main()