Coverage for tests/test_degenerateTemplate.py: 27%

60 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 22:50 -0800

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 

24import numpy as np 

25 

26import lsst.utils.tests 

27import lsst.afw.detection as afwDet 

28import lsst.geom as geom 

29import lsst.afw.image as afwImage 

30from lsst.meas.deblender.baseline import deblend 

31import lsst.meas.algorithms as measAlg 

32 

33 

34def imExt(img): 

35 bbox = img.getBBox() 

36 return [bbox.getMinX(), bbox.getMaxX(), bbox.getMinY(), bbox.getMaxY()] 

37 

38 

39def doubleGaussianPsf(W, H, fwhm1, fwhm2, a2): 

40 return measAlg.DoubleGaussianPsf(W, H, fwhm1, fwhm2, a2) 

41 

42 

43def gaussianPsf(W, H, fwhm): 

44 return measAlg.DoubleGaussianPsf(W, H, fwhm) 

45 

46 

47class DegenerateTemplateTestCase(lsst.utils.tests.TestCase): 

48 

49 def testPeakRemoval(self): 

50 """A simple example: three overlapping blobs (detected as 1 

51 footprint with three peaks). Additional peaks are added near 

52 the blob peaks that should be identified as degenerate. 

53 """ 

54 H, W = 100, 100 

55 

56 fpbb = geom.Box2I(geom.Point2I(0, 0), geom.Point2I(W - 1, H - 1)) 

57 

58 afwimg = afwImage.MaskedImageF(fpbb) 

59 imgbb = afwimg.getBBox() 

60 img = afwimg.getImage().getArray() 

61 

62 var = afwimg.getVariance().getArray() 

63 var[:, :] = 1. 

64 

65 blob_fwhm = 10. 

66 blob_psf = doubleGaussianPsf(99, 99, blob_fwhm, 2.*blob_fwhm, 0.03) 

67 

68 fakepsf_fwhm = 3. 

69 fakepsf = gaussianPsf(11, 11, fakepsf_fwhm) 

70 

71 blobimgs = [] 

72 x = 75. 

73 XY = [(x, 35.), (x, 65.), (50., 50.)] 

74 flux = 1e6 

75 for x, y in XY: 

76 bim = blob_psf.computeImage(geom.Point2D(x, y)) 

77 bbb = bim.getBBox() 

78 bbb.clip(imgbb) 

79 

80 bim = bim.Factory(bim, bbb) 

81 bim2 = bim.getArray() 

82 

83 blobimg = np.zeros_like(img) 

84 blobimg[bbb.getMinY():bbb.getMaxY()+1, bbb.getMinX():bbb.getMaxX()+1] += flux*bim2 

85 blobimgs.append(blobimg) 

86 

87 img[bbb.getMinY():bbb.getMaxY()+1, 

88 bbb.getMinX():bbb.getMaxX()+1] += flux * bim2 

89 

90 # Run the detection code to get a ~ realistic footprint 

91 thresh = afwDet.createThreshold(5., 'value', True) 

92 fpSet = afwDet.FootprintSet(afwimg, thresh, 'DETECTED', 1) 

93 fps = fpSet.getFootprints() 

94 

95 self.assertTrue(len(fps) == 1) 

96 

97 # Add new peaks near to the first peaks that will be degenerate 

98 fp0 = fps[0] 

99 for x, y in XY: 

100 fp0.addPeak(x - 10, y + 6, 10) 

101 

102 deb = deblend(fp0, afwimg, fakepsf, fakepsf_fwhm, verbose=True, removeDegenerateTemplates=True) 

103 

104 self.assertTrue(deb.deblendedParents[0].peaks[3].degenerate) 

105 self.assertTrue(deb.deblendedParents[0].peaks[4].degenerate) 

106 self.assertTrue(deb.deblendedParents[0].peaks[5].degenerate) 

107 

108 

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

110 pass 

111 

112 

113def setup_module(module): 

114 lsst.utils.tests.init() 

115 

116 

117if __name__ == "__main__": 117 ↛ 118line 117 didn't jump to line 118, because the condition on line 117 was never true

118 lsst.utils.tests.init() 

119 unittest.main()