Coverage for tests/test_kernelCandidateDetection.py: 32%
79 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-21 09:12 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-21 09:12 +0000
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.ImagePsfMatchTask.ConfigClass()
28 self.subconfig = self.config.kernel.active
29 self.ps = pexConfig.makePropertySet(self.subconfig)
30 self.kSize = self.ps['kernelSize']
32 # gaussian reference kernel
33 self.gSize = self.kSize
34 self.gaussFunction = afwMath.GaussianFunction2D(2, 3)
35 self.gaussKernel = afwMath.AnalyticKernel(self.gSize, self.gSize, self.gaussFunction)
37 if defDataDir:
38 defImagePath = os.path.join(defDataDir, "DC3a-Sim", "sci", "v5-e0",
39 "v5-e0-c011-a00.sci.fits")
40 self.templateImage = afwImage.MaskedImageF(defImagePath)
41 self.scienceImage = self.templateImage.Factory(self.templateImage.getDimensions())
43 convolutionControl = afwMath.ConvolutionControl()
44 convolutionControl.setDoNormalize(False)
45 afwMath.convolve(self.scienceImage, self.templateImage, self.gaussKernel, convolutionControl)
47 def tearDown(self):
48 del self.config
49 del self.ps
50 del self.gaussFunction
51 del self.gaussKernel
52 if defDataDir:
53 del self.templateImage
54 del self.scienceImage
56 @unittest.skipIf(not defDataDir,
57 "Warning: afwdata is not set up; not running KernelCandidateDetection.py")
58 def testGetCollection(self):
59 # NOTE - you need to subtract off background from the image
60 # you run detection on. Here it is the template.
61 bgConfig = self.subconfig.afwBackgroundConfig
62 diffimTools.backgroundSubtract(bgConfig, [self.templateImage, ])
64 detConfig = self.subconfig.detectionConfig
65 maskPlane = detConfig.badMaskPlanes[0]
66 maskVal = afwImage.Mask.getPlaneBitMask(maskPlane)
68 kcDetect = ipDiffim.KernelCandidateDetectionF(pexConfig.makePropertySet(detConfig))
69 kcDetect.apply(self.templateImage, self.scienceImage)
70 fpList1 = kcDetect.getFootprints()
72 self.assertNotEqual(len(fpList1), 0)
74 for fp in fpList1:
75 bbox = fp.getBBox()
76 tmi = afwImage.MaskedImageF(self.templateImage, bbox, origin=afwImage.LOCAL)
77 smi = afwImage.MaskedImageF(self.scienceImage, bbox, origin=afwImage.LOCAL)
78 tmask = tmi.getMask()
79 smask = smi.getMask()
81 for j in range(tmask.getHeight()):
82 for i in range(tmask.getWidth()):
83 # No masked pixels in either image
84 self.assertEqual(tmask[i, j, afwImage.LOCAL], 0)
85 self.assertEqual(smask[i, j, afwImage.LOCAL], 0)
87 # add a masked pixel to the template image and make sure you don't get it
88 tp = geom.Point2I(tmask.getWidth()//2, tmask.getHeight()//2)
89 self.templateImage.mask[fpList1[0].getBBox(), afwImage.LOCAL][tp, afwImage.LOCAL] = maskVal
90 kcDetect.apply(self.templateImage, self.scienceImage)
91 fpList2 = kcDetect.getFootprints()
92 self.assertEqual(len(fpList2), (len(fpList1)-1))
94 # add a masked pixel to the science image and make sure you don't get it
95 sp = geom.Point2I(smask.getWidth()//2, smask.getHeight()//2)
96 self.scienceImage.mask[fpList1[1].getBBox(), afwImage.LOCAL][sp, afwImage.LOCAL] = maskVal
97 self.scienceImage.mask[fpList1[2].getBBox(), afwImage.LOCAL][sp, afwImage.LOCAL] = maskVal
98 kcDetect.apply(self.templateImage, self.scienceImage)
99 fpList3 = kcDetect.getFootprints()
100 self.assertEqual(len(fpList3), (len(fpList1)-3))
102#####
105class TestMemory(lsst.utils.tests.MemoryTestCase):
106 pass
109def setup_module(module):
110 lsst.utils.tests.init()
113if __name__ == "__main__": 113 ↛ 114line 113 didn't jump to line 114, because the condition on line 113 was never true
114 lsst.utils.tests.init()
115 unittest.main()