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 

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 ''' 

51 A simple example: three overlapping blobs (detected as 1 

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

53 the blob peaks that should be identified as degenerate. 

54 ''' 

55 H, W = 100, 100 

56 

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

58 

59 afwimg = afwImage.MaskedImageF(fpbb) 

60 imgbb = afwimg.getBBox() 

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

62 

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

64 var[:, :] = 1. 

65 

66 blob_fwhm = 10. 

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

68 

69 fakepsf_fwhm = 3. 

70 fakepsf = gaussianPsf(11, 11, fakepsf_fwhm) 

71 

72 blobimgs = [] 

73 x = 75. 

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

75 flux = 1e6 

76 for x, y in XY: 

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

78 bbb = bim.getBBox() 

79 bbb.clip(imgbb) 

80 

81 bim = bim.Factory(bim, bbb) 

82 bim2 = bim.getArray() 

83 

84 blobimg = np.zeros_like(img) 

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

86 blobimgs.append(blobimg) 

87 

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

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

90 

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

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

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

94 fps = fpSet.getFootprints() 

95 

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

97 

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

99 fp0 = fps[0] 

100 for x, y in XY: 

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

102 

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

104 

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

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

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

108 

109 

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

111 pass 

112 

113 

114def setup_module(module): 

115 lsst.utils.tests.init() 

116 

117 

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

119 lsst.utils.tests.init() 

120 unittest.main()