Coverage for tests/test_include.py: 45%

45 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-14 10:30 +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 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 def setUp(self): 

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

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

62 

63 def tearDown(self): 

64 del self.calexpOrig 

65 del self.calexp 

66 

67 def testInclude(self): 

68 schema = afwTable.SourceTable.makeMinimalSchema() 

69 

70 # Create the detection task 

71 config = SourceDetectionTask.ConfigClass() 

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

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

74 

75 # Create the deblender Task 

76 debConfig = measDeb.SourceDeblendConfig() 

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

78 

79 # Create the measurement Task 

80 config = SingleFrameMeasurementTask.ConfigClass() 

81 measureTask = SingleFrameMeasurementTask(schema, config=config) 

82 

83 # Create the output table 

84 tab = afwTable.SourceTable.make(schema) 

85 

86 # Process the data 

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

88 sources = result.sources 

89 

90 # Run the deblender 

91 debTask.run(self.calexp, sources) 

92 

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

94 measureTask.run(sources, self.calexp) 

95 

96 plotOnFailure = False 

97 if display: 

98 plotOnFailure = True 

99 

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

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

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

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

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

105 

106 

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

108 pass 

109 

110 

111def setup_module(module): 

112 lsst.utils.tests.init() 

113 

114 

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

116 lsst.utils.tests.init() 

117 unittest.main()