Coverage for tests / test_quickFrameMeasurement.py: 40%
61 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-01 08:40 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-01 08:40 +0000
1# This file is part of pipe_tasks.
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 os
24import unittest
25import numpy as np
27import lsst.afw.image as afwImage
28import lsst.utils
29import lsst.utils.tests
30from lsst.pipe.tasks.quickFrameMeasurement import QuickFrameMeasurementTask, QuickFrameMeasurementTaskConfig
33class QuickFrameMeasurementTaskTestCase(lsst.utils.tests.TestCase):
34 try:
35 afwDataDir = lsst.utils.getPackageDir('afwdata')
36 except Exception:
37 afwDataDir = None
39 truthValuesDirect = {
40 "postISRCCD_2020021800073-KPNO_406_828nm~EMPTY-det000.fits.fz": (2496.296, 1104.171),
41 "postISRCCD_2020021800027-KPNO_406_828nm~EMPTY-det000.fits.fz": (1540.807, 1421.422),
42 "postISRCCD_2020021800224-EMPTY~EMPTY-det000.fits.fz": (1865.814, 2273.021),
43 }
44 truthValuesDispersed = {
45 "postISRCCD_2020021700249-EMPTY~ronchi90lpmm-det000.fits.fz": (2531.088, 2287.149),
46 "postISRCCD_2020031500119-EMPTY~ronchi90lpmm-det000.fits.fz": (2112.865, 2181.377),
47 }
49 CENTROID_TOLERANCE = 2 # number of pixels total distance it's acceptable to miss by
50 COM_TOLERANCE = 8 # number of pixels the center of mass is allowed to be off by
52 @unittest.skipUnless(afwDataDir, "afwdata not available")
53 def setUp(self):
54 self.directConfig = QuickFrameMeasurementTaskConfig()
55 self.directTask = QuickFrameMeasurementTask(config=self.directConfig)
57 # support for handling dispersed images seperately in future via config
58 self.dispersedConfig = QuickFrameMeasurementTaskConfig()
59 self.dispersedTask = QuickFrameMeasurementTask(config=self.dispersedConfig)
61 @unittest.skipUnless(afwDataDir, "afwdata not available")
62 def testDirectCentroiding(self):
63 task = self.directTask
64 filenames = self.truthValuesDirect.keys()
66 for filename in filenames:
67 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", filename)
68 trueCentroid = self.truthValuesDirect[filename]
70 exp = afwImage.ExposureF(fullName)
71 result = task.run(exp)
72 foundCentroid = result.brightestObjCentroid
74 dist = np.linalg.norm(np.asarray(foundCentroid) - np.asarray(trueCentroid))
75 distCoM = np.linalg.norm(np.asarray(result.brightestObjCentroidCofM) - np.asarray(trueCentroid))
77 self.assertLess(dist, self.CENTROID_TOLERANCE)
78 self.assertLess(distCoM, self.COM_TOLERANCE)
80 # offset size shouldn't really matter, just make it >> PSF, and make
81 # sure the value isn't off-chip or right by the edge for any of the
82 # test images
83 offset = 300
84 wrongCentroid = (foundCentroid[0]+offset, foundCentroid[1]+offset)
85 with self.assertRaises(ValueError):
86 task.checkResult(exp, wrongCentroid, -1, self.directConfig.centroidPixelPercentile)
88 @unittest.skipUnless(afwDataDir, "afwdata not available")
89 def testDispersedCentroiding(self):
90 task = self.dispersedTask
91 filenames = self.truthValuesDispersed.keys()
93 for filename in filenames:
94 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", filename)
95 trueCentroid = self.truthValuesDispersed[filename]
97 exp = afwImage.ExposureF(fullName)
98 result = task.run(exp)
99 foundCentroid = result.brightestObjCentroid
101 dist = np.linalg.norm(np.asarray(foundCentroid) - np.asarray(trueCentroid))
102 self.assertLess(dist, self.CENTROID_TOLERANCE)
104 # this doesn't matter much as CoM centroid is for donuts
105 # and we don't intend to do dispersed donuts, but good to catch
106 # big regressions. Can be removed later if needed
107 distCoM = np.linalg.norm(np.asarray(result.brightestObjCentroidCofM) - np.asarray(trueCentroid))
108 self.assertLess(distCoM, self.COM_TOLERANCE)
111def setup_module(module):
112 lsst.utils.tests.init()
115class MemoryTestCase(lsst.utils.tests.MemoryTestCase):
116 pass
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120 because the condition on line 119 was never true
120 lsst.utils.tests.init()
121 unittest.main()