Hide keyboard shortcuts

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# 

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 def checkDeblender(self): 

38 try: 

39 import lsst.meas.deblender # noqa F401 

40 except ImportError as e: 

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

42 

43 def testFailures(self): 

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

45 

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

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

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

49 checking the plumbing of the deblender. 

50 """ 

51 import lsst.meas.deblender as measDeb 

52 

53 self.checkDeblender() 

54 xGood, yGood = 57, 86 

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

56 xBad, yBad = 0, 0 

57 flux = 100.0 

58 dims = geom.Extent2I(128, 128) 

59 

60 mi = afwImage.MaskedImageF(dims) 

61 mi.getVariance().set(1.0) 

62 image = mi.getImage() 

63 image.set(0) 

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

65 

66 exposure = afwImage.makeExposure(mi) 

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

68 exposure.setPsf(psf) 

69 

70 schema = afwTable.SourceTable.makeMinimalSchema() 

71 

72 config = measDeb.SourceDeblendConfig() 

73 config.catchFailures = True 

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

75 

76 catalog = afwTable.SourceCatalog(schema) 

77 

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

79 """Make a source in the catalog 

80 

81 Two peaks are created: one at the specified 

82 position, and one offset in x,y. 

83 The footprint is of the nominated size. 

84 """ 

85 src = catalog.addNew() 

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

87 foot = afwDetection.Footprint(spans) 

88 foot.addPeak(x, y, flux) 

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

90 src.setFootprint(foot) 

91 return src 

92 

93 good = makeSource(xGood, yGood) 

94 bad = makeSource(xBad, yBad) 

95 

96 task.run(exposure, catalog) 

97 

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

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

100 

101 

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

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

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