Coverage for tests/test_FPPosition.py: 33%
37 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-09 11:19 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-09 11:19 +0000
1# This file is part of meas_base.
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.geom
25import lsst.meas.base.tests
26import lsst.utils.tests
28from lsst.afw.cameraGeom.testUtils import DetectorWrapper
29from lsst.meas.base.tests import AlgorithmTestCase
32class FPPositionTestCase(AlgorithmTestCase, lsst.utils.tests.TestCase):
34 def setUp(self):
35 # Define point2D object which are distributed about a detector
36 self.positions = [lsst.geom.Point2D(*x) for x in ((50.1, 49.8), (12, 15.6), (13.4, 100.0))]
38 # Define a box which will be used to as boundaries to construct an
39 # detector object
40 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-20, -30),
41 lsst.geom.Extent2I(140, 160))
42 self.dataset = lsst.meas.base.tests.TestDataset(self.bbox)
44 # Add in sources to synthetic dataset at defined positions with an
45 # arbitrary value
46 for pos in self.positions:
47 self.dataset.addSource(100000.0, pos)
48 self.dw = DetectorWrapper()
50 def tearDown(self):
51 del self.positions
52 del self.bbox
53 del self.dataset
54 del self.dw
56 def testFPPosition(self):
57 task = self.makeSingleFrameMeasurementTask("base_FPPosition")
58 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0)
59 exposure.setDetector(self.dw.detector)
60 task.run(catalog, exposure)
61 pointKey = lsst.afw.table.Point2DKey(catalog.schema["base_FPPosition"])
62 # Compare the derived focal plane position to the true position. True
63 # position is calculated as pixel coordinate plus half pixel offset to
64 # the center of a pixel, times the pixel scale.
65 for record, pos in zip(catalog, self.positions):
66 self.assertFalse(record.get("base_FPPosition_flag"))
67 point = record.get(pointKey)
68 self.assertAlmostEqual(point.getX(), self.dw.pixelSize[0] * (0.5 + pos[0]), 3)
69 self.assertAlmostEqual(point.getY(), self.dw.pixelSize[1] * (0.5 + pos[1]), 3)
72class TestMemory(lsst.utils.tests.MemoryTestCase):
73 pass
76def setup_module(module):
77 lsst.utils.tests.init()
80if __name__ == "__main__": 80 ↛ 81line 80 didn't jump to line 81, because the condition on line 80 was never true
81 lsst.utils.tests.init()
82 unittest.main()