Coverage for tests/test_quickFrameMeasurement.py : 42%

Hot-keys 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-2017 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/>.
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, 1105),
41 "postISRCCD_2020021800027-KPNO_406_828nm~EMPTY-det000.fits.fz": (1550, 1423),
42 "postISRCCD_2020021800224-EMPTY~EMPTY-det000.fits.fz": (1866, 2274),
43 }
44 truthValuesDispersed = {
45 "postISRCCD_2020021700249-EMPTY~ronchi90lpmm-det000.fits.fz": (2531, 2286),
46 "postISRCCD_2020031500119-EMPTY~ronchi90lpmm-det000.fits.fz": (2112, 2183),
47 }
49 TOLERANCE = 5 # number of pixels total distance it's acceptable to miss by
51 @unittest.skipUnless(afwDataDir, "afwdata not available")
52 def setUp(self):
53 self.directConfig = QuickFrameMeasurementTaskConfig()
54 self.directTask = QuickFrameMeasurementTask(config=self.directConfig)
56 # support for handling dispersed images seperately in future via config
57 self.dispersedConfig = QuickFrameMeasurementTaskConfig()
58 self.dispersedTask = QuickFrameMeasurementTask(config=self.dispersedConfig)
60 @unittest.skipUnless(afwDataDir, "afwdata not available")
61 def testDirectCentroiding(self):
62 task = self.directTask
63 filenames = self.truthValuesDirect.keys()
65 for filename in filenames:
66 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", filename)
67 trueCentroid = self.truthValuesDirect[filename]
69 exp = afwImage.ExposureF(fullName)
70 result = task.run(exp)
71 foundCentroid = result.brightestObjCentroid
73 dist = np.linalg.norm(np.asarray(foundCentroid) - np.asarray(trueCentroid))
74 self.assertLess(dist, self.TOLERANCE)
76 # offset size shouldn't really matter, just make it >> PSF, and make
77 # sure the value isn't off-chip or right by the edge for any of the
78 # test images
79 offset = 250
80 wrongCentroid = (foundCentroid[0]+offset, foundCentroid[1]+offset)
81 with self.assertRaises(ValueError):
82 task.checkResult(exp, wrongCentroid, -1, self.directConfig.centroidPixelPercentile)
84 @unittest.skipUnless(afwDataDir, "afwdata not available")
85 def testDispersedCentroiding(self):
86 task = self.dispersedTask
87 filenames = self.truthValuesDispersed.keys()
89 for filename in filenames:
90 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", filename)
91 trueCentroid = self.truthValuesDispersed[filename]
93 exp = afwImage.ExposureF(fullName)
94 result = task.run(exp)
95 foundCentroid = result.brightestObjCentroid
97 dist = np.linalg.norm(np.asarray(foundCentroid) - np.asarray(trueCentroid))
99 self.assertLess(dist, self.TOLERANCE)
102def setup_module(module):
103 lsst.utils.tests.init()
106class MemoryTestCase(lsst.utils.tests.MemoryTestCase):
107 pass
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()