Coverage for tests/test_exposureRecord.py: 26%
42 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-11 02:44 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-11 02:44 -0800
1# This file is part of afw.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import unittest
24import lsst.afw.geom
25import lsst.afw.table
26import lsst.geom
27import lsst.utils.tests
30class ExposureRecordTestCase(unittest.TestCase):
31 def setUp(self):
32 # Construct a trivial WCS:
33 #
34 # - reference pixel at position (10, 10) corresponds to a sky origin of (0, 0).
35 # - scale 1 arcsec per pixel.
36 self.crval = lsst.geom.SpherePoint(0, 0, lsst.geom.degrees)
37 self.crpix = lsst.geom.Point2D(10, 10)
38 cdMatrix = lsst.afw.geom.makeCdMatrix(1.0*lsst.geom.arcseconds)
39 self.wcs = lsst.afw.geom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=cdMatrix)
41 # It is not possible to directly construct an ExposureRecord.
42 # Instead, we construct an ExposureCatalog, then create a record in it.
43 # Note that the record's bounding box is centred on the WCS reference pixel.
44 catalog = lsst.afw.table.ExposureCatalog(lsst.afw.table.ExposureTable.makeMinimalSchema())
45 self.record = catalog.addNew()
46 self.record.setBBox(lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(20, 20)))
47 self.record.setWcs(self.wcs)
49 # Add a valid polygon to the record.
50 # Note that the polygon covers one half (along the x axis) of the record:
51 # 0 <= x < 10 is valid, 10 <= x < 20 is invalid.
52 polygon = lsst.afw.geom.Polygon([lsst.geom.Point2D(*pt)
53 for pt in [(0, 0), (0, 20), (10, 20), (10, 0)]])
54 self.record.setValidPolygon(polygon)
56 def testContainsSpherePoint(self):
57 """Test ExposureRecord.contains() with a SpherePoint.
58 """
59 # By construction, the CRVAL is contained within the record.
60 self.assertTrue(self.record.contains(self.crval))
62 # Rotate the test point about a vertical axis.
63 axis = lsst.geom.SpherePoint(0, 90, lsst.geom.degrees)
65 # A 180 degree rotation is far outside the record.
66 self.assertFalse(self.record.contains(self.crval.rotated(axis, 180*lsst.geom.degrees)))
68 # A 1 arcsecond rotation in either direction is within the record.
69 self.assertTrue(self.record.contains(self.crval.rotated(axis, 1.0 * lsst.geom.arcseconds)))
70 self.assertTrue(self.record.contains(self.crval.rotated(axis, -1.0 * lsst.geom.arcseconds)))
72 # A 1 arcsecond positive rotation is within the valid polygon.
73 self.assertTrue(self.record.contains(self.crval.rotated(axis, 1.0 * lsst.geom.arcseconds),
74 includeValidPolygon=True))
76 # A 1 arcsecond negative rotation is outside the valid polygon.
77 self.assertFalse(self.record.contains(self.crval.rotated(axis, -1.0 * lsst.geom.arcseconds),
78 includeValidPolygon=True))
80 def testContainsPoint(self):
81 """Test ExposureRecord.contains() with a Point and a WCS.
82 """
83 # By construction, the reference pixel is contained within the record.
84 self.assertTrue(self.record.contains(self.crpix, self.wcs))
86 # Some points are clearly outside the record.
87 self.assertFalse(self.record.contains(lsst.geom.Point2D(99, 99), self.wcs))
89 # A small offset from the center should be within the record.
90 points = [lsst.geom.Point2D(*pt) for pt in [(9, 10), (11, 10), (10, 9), (10, 11)]]
91 for point in points:
92 self.assertTrue(self.record.contains(point, self.wcs))
94 # But only with x < 10 if we use the valid polygon.
95 for point in points:
96 if point.getX() < 10:
97 self.assertTrue(self.record.contains(point, self.wcs, includeValidPolygon=True))
98 else:
99 self.assertFalse(self.record.contains(point, self.wcs, includeValidPolygon=True))
102class MemoryTester(lsst.utils.tests.MemoryTestCase):
103 pass
106def setup_module(module):
107 lsst.utils.tests.init()
110if __name__ == "__main__": 110 ↛ 111line 110 didn't jump to line 111, because the condition on line 110 was never true
111 lsst.utils.tests.init()
112 unittest.main()