Coverage for tests/test_kernelCandidateDetection.py: 29%
78 statements
« prev ^ index » next coverage.py v7.2.6, created at 2023-05-27 02:48 -0700
« prev ^ index » next coverage.py v7.2.6, created at 2023-05-27 02:48 -0700
1import os
2import unittest
5import lsst.utils.tests
6import lsst.utils
7import lsst.afw.image as afwImage
8import lsst.afw.math as afwMath
9import lsst.geom as geom
10import lsst.ip.diffim as ipDiffim
11import lsst.ip.diffim.diffimTools as diffimTools
12import lsst.utils.logging as logUtils
13import lsst.pex.config as pexConfig
15logUtils.trace_set_at("lsst.ip.diffim", 2)
17# known input images
18try:
19 defDataDir = lsst.utils.getPackageDir('afwdata')
20except Exception:
21 defDataDir = None
24class DiffimTestCases(lsst.utils.tests.TestCase):
26 def setUp(self):
27 self.config = ipDiffim.PsfMatchConfigAL()
28 self.ps = pexConfig.makePropertySet(self.config)
29 self.kSize = self.ps['kernelSize']
31 # gaussian reference kernel
32 self.gSize = self.kSize
33 self.gaussFunction = afwMath.GaussianFunction2D(2, 3)
34 self.gaussKernel = afwMath.AnalyticKernel(self.gSize, self.gSize, self.gaussFunction)
36 if defDataDir:
37 defImagePath = os.path.join(defDataDir, "DC3a-Sim", "sci", "v5-e0",
38 "v5-e0-c011-a00.sci.fits")
39 self.templateImage = afwImage.MaskedImageF(defImagePath)
40 self.scienceImage = self.templateImage.Factory(self.templateImage.getDimensions())
42 convolutionControl = afwMath.ConvolutionControl()
43 convolutionControl.setDoNormalize(False)
44 afwMath.convolve(self.scienceImage, self.templateImage, self.gaussKernel, convolutionControl)
46 def tearDown(self):
47 del self.config
48 del self.ps
49 del self.gaussFunction
50 del self.gaussKernel
51 if defDataDir:
52 del self.templateImage
53 del self.scienceImage
55 @unittest.skipIf(not defDataDir,
56 "Warning: afwdata is not set up; not running KernelCandidateDetection.py")
57 def testGetCollection(self):
58 # NOTE - you need to subtract off background from the image
59 # you run detection on. Here it is the template.
60 bgConfig = self.config.afwBackgroundConfig
61 diffimTools.backgroundSubtract(bgConfig, [self.templateImage, ])
63 detConfig = self.config.detectionConfig
64 maskPlane = detConfig.badMaskPlanes[0]
65 maskVal = afwImage.Mask.getPlaneBitMask(maskPlane)
67 kcDetect = ipDiffim.KernelCandidateDetectionF(pexConfig.makePropertySet(detConfig))
68 kcDetect.apply(self.templateImage, self.scienceImage)
69 fpList1 = kcDetect.getFootprints()
71 self.assertNotEqual(len(fpList1), 0)
73 for fp in fpList1:
74 bbox = fp.getBBox()
75 tmi = afwImage.MaskedImageF(self.templateImage, bbox, origin=afwImage.LOCAL)
76 smi = afwImage.MaskedImageF(self.scienceImage, bbox, origin=afwImage.LOCAL)
77 tmask = tmi.mask
78 smask = smi.mask
80 for j in range(tmask.getHeight()):
81 for i in range(tmask.getWidth()):
82 # No masked pixels in either image
83 self.assertEqual(tmask[i, j, afwImage.LOCAL], 0)
84 self.assertEqual(smask[i, j, afwImage.LOCAL], 0)
86 # add a masked pixel to the template image and make sure you don't get it
87 tp = geom.Point2I(tmask.getWidth()//2, tmask.getHeight()//2)
88 self.templateImage.mask[fpList1[0].getBBox(), afwImage.LOCAL][tp, afwImage.LOCAL] = maskVal
89 kcDetect.apply(self.templateImage, self.scienceImage)
90 fpList2 = kcDetect.getFootprints()
91 self.assertEqual(len(fpList2), (len(fpList1)-1))
93 # add a masked pixel to the science image and make sure you don't get it
94 sp = geom.Point2I(smask.getWidth()//2, smask.getHeight()//2)
95 self.scienceImage.mask[fpList1[1].getBBox(), afwImage.LOCAL][sp, afwImage.LOCAL] = maskVal
96 self.scienceImage.mask[fpList1[2].getBBox(), afwImage.LOCAL][sp, afwImage.LOCAL] = maskVal
97 kcDetect.apply(self.templateImage, self.scienceImage)
98 fpList3 = kcDetect.getFootprints()
99 self.assertEqual(len(fpList3), (len(fpList1)-3))
101#####
104class TestMemory(lsst.utils.tests.MemoryTestCase):
105 pass
108def setup_module(module):
109 lsst.utils.tests.init()
112if __name__ == "__main__": 112 ↛ 113line 112 didn't jump to line 113, because the condition on line 112 was never true
113 lsst.utils.tests.init()
114 unittest.main()