Coverage for tests/test_pupilFactory.py: 29%
47 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-01 15:48 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-01 15:48 -0700
1#
2# LSST Data Management System
3# Copyright 2017 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#
22import unittest
23import numpy as np
25import lsst.utils.tests
26import lsst.afw.image as afwImage
27import lsst.afw.cameraGeom as afwCameraGeom
28from lsst.geom import degrees
31class PupilFactoryTestCase(lsst.utils.tests.TestCase):
32 """Test lsst.afw.cameraGeom.PupilFactory"""
34 def setUp(self):
35 self.visitInfo = afwImage.VisitInfo()
36 self.size = 16.8
37 self.npix = 1024
38 self.scale = self.size / self.npix
40 def testBasePupilFactory(self):
41 pupilFactory = afwCameraGeom.PupilFactory(
42 self.visitInfo, self.size, self.npix)
43 self.assertEqual(pupilFactory.pupilSize, self.size)
44 self.assertEqual(pupilFactory.pupilScale, self.scale)
45 self.assertEqual(pupilFactory.npix, self.npix)
46 with self.assertRaises(NotImplementedError):
47 pupilFactory.getPupil(point=None)
49 def testBasePupilFactoryMethods(self):
50 pupilFactory = afwCameraGeom.PupilFactory(
51 self.visitInfo, self.size, self.npix)
52 pupil = pupilFactory._fullPupil()
53 self.assertTrue(np.all(pupil.illuminated))
54 nFull = np.sum(pupil.illuminated)
56 # Cut out a primary aperture
57 pupilFactory._cutCircleExterior(pupil, (0.0, 0.0), 8.4/2)
58 nCircle = np.sum(pupil.illuminated)
59 self.assertFloatsAlmostEqual(
60 nCircle/nFull, np.pi*(8.4/2)**2 / 16.8**2, rtol=3e-4)
61 np.testing.assert_array_equal(pupil.illuminated, pupil.illuminated.T)
63 # Cut out a central obstruction making an annulus
64 pupilFactory._cutCircleInterior(pupil, (0.0, 0.0), 8.4/2 * 0.6)
65 nAnnulus = np.sum(pupil.illuminated)
66 self.assertFloatsAlmostEqual(
67 nAnnulus/nFull, nCircle/nFull * (1-0.6**2), rtol=3e-4)
68 np.testing.assert_array_equal(pupil.illuminated, pupil.illuminated.T)
70 # Cut a horizontal ray, which preserves vertical reflection symmetry
71 # but removes horizontal reflection symmetry, and transpositional
72 # symmetry.
73 pupilFactory._cutRay(pupil, (0.0, 0.0), 0*degrees, 0.1)
74 np.testing.assert_array_equal(pupil.illuminated, pupil.illuminated[::-1, :])
75 self.assertTrue(np.any(pupil.illuminated != pupil.illuminated[:, ::-1]))
76 self.assertTrue(np.any(pupil.illuminated != pupil.illuminated.T))
78 # Cut a vertical ray, which then gives transpositional symmetry but
79 # removes vertical and horizontal reflection symmetry
80 pupilFactory._cutRay(pupil, (0.0, 0.0), 90*degrees, 0.1)
81 self.assertTrue(np.any(pupil.illuminated != pupil.illuminated[::-1, :]))
82 self.assertTrue(np.any(pupil.illuminated != pupil.illuminated[:, ::-1]))
83 self.assertTrue(np.any(pupil.illuminated == pupil.illuminated.T))
86def setup_module(module):
87 lsst.utils.tests.init()
90class MemoryTester(lsst.utils.tests.MemoryTestCase):
91 pass
94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true
95 lsst.utils.tests.init()
96 unittest.main()