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 os 

24import unittest 

25 

26import lsst.utils.tests 

27import lsst.afw.image as afwImage 

28import lsst.afw.table as afwTable 

29from lsst.meas.algorithms.detection import SourceDetectionTask 

30from lsst.meas.base import SingleFrameMeasurementTask 

31import lsst.meas.deblender as measDeb 

32 

33try: 

34 type(display) 

35except NameError: 

36 display = False 

37 

38DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data") 

39 

40 

41class IncludeTestCase(lsst.utils.tests.TestCase): 

42 """ Test case for DM-1738: test that include method successfully 

43 expands footprint to include the union of itself and all others provided. 

44 

45 In the current version of meas_deblender, children's Footprints can extend outside 

46 that of the parent. The replace-by-noise code thus fails to reinstate the pixels 

47 that are outside the parent but within the children. Calling include() prior 

48 to noise replacement solves this issue. 

49 

50 The test data used here (./data/ticket1738.fits) is a cutout of an HSC observed M31 

51 field in which this pathology occured: 

52 --id field=M31 dateObs=2014-11-24 visit=14770 ccd=27 

53 bbox = afwGeom.Box2I(afwGeom.Point2I(720, 460), afwGeom.Extent2I(301, 301)) 

54 

55 See data/ticket1738_noInclude.png or data/ticket1738_noInclude.fits for a visual 

56 of this pathology). 

57 

58 """ 

59 

60 def setUp(self): 

61 self.calexpOrig = afwImage.ExposureF(os.path.join(DATA_DIR, "ticket1738.fits")) 

62 self.calexp = afwImage.ExposureF(os.path.join(DATA_DIR, "ticket1738.fits")) 

63 

64 def tearDown(self): 

65 del self.calexpOrig 

66 del self.calexp 

67 

68 def testInclude(self): 

69 schema = afwTable.SourceTable.makeMinimalSchema() 

70 

71 # Create the detection task 

72 config = SourceDetectionTask.ConfigClass() 

73 config.reEstimateBackground = False # Turn off so that background does not change from orig 

74 detectionTask = SourceDetectionTask(config=config, schema=schema) 

75 

76 # Create the deblender Task 

77 debConfig = measDeb.SourceDeblendConfig() 

78 debTask = measDeb.SourceDeblendTask(schema, config=debConfig) 

79 

80 # Create the measurement Task 

81 config = SingleFrameMeasurementTask.ConfigClass() 

82 measureTask = SingleFrameMeasurementTask(schema, config=config) 

83 

84 # Create the output table 

85 tab = afwTable.SourceTable.make(schema) 

86 

87 # Process the data 

88 result = detectionTask.run(tab, self.calexp) 

89 sources = result.sources 

90 

91 # Run the deblender 

92 debTask.run(self.calexp, sources) 

93 

94 # Run the measurement task: this where the replace-with-noise occurs 

95 measureTask.run(sources, self.calexp) 

96 

97 plotOnFailure = False 

98 if display: 

99 plotOnFailure = True 

100 

101 # The relative differences ranged from 0.02 to ~2. This rtol is somewhat 

102 # random, but will certainly catch the pathology if it occurs. 

103 self.assertFloatsAlmostEqual(self.calexpOrig.getMaskedImage().getImage().getArray(), 

104 self.calexp.getMaskedImage().getImage().getArray(), 

105 rtol=1E-3, printFailures=False, plotOnFailure=plotOnFailure) 

106 

107 

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

109 pass 

110 

111 

112def setup_module(module): 

113 lsst.utils.tests.init() 

114 

115 

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

117 lsst.utils.tests.init() 

118 unittest.main()