Coverage for tests/test_ticket-2871.py: 28%

55 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-13 10:28 +0000

1# 

2# LSST Data Management System 

3# 

4# Copyright 2008-2016 AURA/LSST. 

5# 

6# This product includes software developed by the 

7# LSST Project (http://www.lsst.org/). 

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 LSST License Statement and 

20# the GNU General Public License along with this program. If not, 

21# see <https://www.lsstcorp.org/LegalNotices/>. 

22# 

23import unittest 

24 

25import lsst.utils.tests 

26import lsst.afw.detection as afwDetection 

27import lsst.afw.image as afwImage 

28import lsst.geom as geom 

29import lsst.afw.geom as afwGeom 

30import lsst.afw.table as afwTable 

31import lsst.meas.algorithms as algorithms 

32 

33 

34class DeblendTestCase(unittest.TestCase): 

35 """A test case for deblending 

36 """ 

37 

38 def checkDeblender(self): 

39 try: 

40 import lsst.meas.deblender # noqa F401 

41 except ImportError as e: 

42 self.skipTest("Cannot import lsst.meas.deblender: %s" % e) 

43 

44 def testFailures(self): 

45 """Test deblender failure flagging (#2871) 

46 

47 We create a good source which is expected to pass and a bad source 

48 which is expected to fail because its footprint goes off the image. 

49 This latter case may not happen in practise, but it is useful for 

50 checking the plumbing of the deblender. 

51 """ 

52 import lsst.meas.deblender as measDeb 

53 

54 self.checkDeblender() 

55 xGood, yGood = 57, 86 

56 # Required to be in image so we can evaluate the PSF; will put neighbour just outside 

57 xBad, yBad = 0, 0 

58 flux = 100.0 

59 dims = geom.Extent2I(128, 128) 

60 

61 mi = afwImage.MaskedImageF(dims) 

62 mi.getVariance().set(1.0) 

63 image = mi.getImage() 

64 image.set(0) 

65 image[xGood, yGood, afwImage.LOCAL] = flux 

66 

67 exposure = afwImage.makeExposure(mi) 

68 psf = algorithms.DoubleGaussianPsf(21, 21, 3.) 

69 exposure.setPsf(psf) 

70 

71 schema = afwTable.SourceTable.makeMinimalSchema() 

72 

73 config = measDeb.SourceDeblendConfig() 

74 config.catchFailures = True 

75 # We can't use this dict, because this test doesn't set a mask plane. 

76 config.maskLimits = {} 

77 task = measDeb.SourceDeblendTask(schema, config=config) 

78 

79 catalog = afwTable.SourceCatalog(schema) 

80 

81 def makeSource(x, y, offset=-2, size=3.0): 

82 """Make a source in the catalog 

83 

84 Two peaks are created: one at the specified 

85 position, and one offset in x,y. 

86 The footprint is of the nominated size. 

87 """ 

88 src = catalog.addNew() 

89 spans = afwGeom.SpanSet.fromShape(int(size), offset=(x, y)) 

90 foot = afwDetection.Footprint(spans) 

91 foot.addPeak(x, y, flux) 

92 foot.addPeak(x + offset, y + offset, flux) 

93 src.setFootprint(foot) 

94 return src 

95 

96 good = makeSource(xGood, yGood) 

97 bad = makeSource(xBad, yBad) 

98 

99 task.run(exposure, catalog) 

100 

101 self.assertFalse(good.get('deblend_failed')) 

102 self.assertTrue(bad.get('deblend_failed')) 

103 

104 

105class TestMemory(lsst.utils.tests.MemoryTestCase): 

106 pass 

107 

108 

109def setup_module(module): 

110 lsst.utils.tests.init() 

111 

112 

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()