Coverage for tests/test_snapPsfMatch.py: 27%

84 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-08-30 03:17 -0700

1# 

2# LSST Data Management System 

3# Copyright 2008-2016 AURA/LSST. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <https://www.lsstcorp.org/LegalNotices/>. 

21# 

22import unittest 

23 

24import lsst.utils.tests 

25import lsst.afw.image as afwImage 

26from lsst.afw.geom import makeSkyWcs 

27import lsst.meas.algorithms as measAlg 

28import lsst.ip.diffim as ipDiffim 

29import lsst.ip.diffim.diffimTools as diffimTools 

30import lsst.daf.base as dafBase 

31import lsst.utils.logging as logUtils 

32 

33logUtils.trace_set_at("lsst.ip.diffim", 4) 

34 

35 

36class PsfMatchTestCases(lsst.utils.tests.TestCase): 

37 

38 def setUp(self): 

39 self.configAL = ipDiffim.SnapPsfMatchTask.ConfigClass() 

40 self.configAL.kernel.name = "AL" 

41 self.subconfigAL = self.configAL.kernel.active 

42 

43 self.configDF = ipDiffim.SnapPsfMatchTask.ConfigClass() 

44 self.configDF.kernel.name = "DF" 

45 self.subconfigDF = self.configDF.kernel.active 

46 

47 self.configDFr = ipDiffim.SnapPsfMatchTask.ConfigClass() 

48 self.configDFr.kernel.name = "DF" 

49 self.subconfigDFr = self.configDFr.kernel.active 

50 

51 self.subconfigDF.useRegularization = False 

52 self.subconfigDFr.useRegularization = True 

53 

54 self.subconfigAL.afwBackgroundConfig.useApprox = False 

55 self.subconfigDF.afwBackgroundConfig.useApprox = False 

56 self.subconfigDFr.afwBackgroundConfig.useApprox = False 

57 

58 # variance is a hack 

59 self.subconfigAL.singleKernelClipping = False 

60 self.subconfigAL.spatialKernelClipping = False 

61 self.subconfigDF.singleKernelClipping = False 

62 self.subconfigDF.spatialKernelClipping = False 

63 self.subconfigDFr.singleKernelClipping = False 

64 self.subconfigDFr.spatialKernelClipping = False 

65 

66 # Send fake kernel a differential background 

67 self.bgValue = 100. 

68 self.subconfigAL.fitForBackground = True 

69 self.subconfigDF.fitForBackground = True 

70 self.subconfigDFr.fitForBackground = True 

71 

72 # Make ideal PSF 

73 self.ksize = 21 

74 self.sigma = 2.0 

75 self.psf = measAlg.DoubleGaussianPsf(self.ksize, self.ksize, self.sigma) 

76 

77 def makeWcs(self, offset=0): 

78 # taken from $AFW_DIR/tests/testMakeWcs.py 

79 metadata = dafBase.PropertySet() 

80 metadata.set("SIMPLE", "T") 

81 metadata.set("BITPIX", -32) 

82 metadata.set("NAXIS", 2) 

83 metadata.set("NAXIS1", 1024) 

84 metadata.set("NAXIS2", 1153) 

85 metadata.set("RADESYS", 'FK5') 

86 metadata.set("EQUINOX", 2000.) 

87 metadata.setDouble("CRVAL1", 215.604025685476) 

88 metadata.setDouble("CRVAL2", 53.1595451514076) 

89 metadata.setDouble("CRPIX1", 1109.99981456774 + offset) 

90 metadata.setDouble("CRPIX2", 560.018167811613 + offset) 

91 metadata.set("CTYPE1", 'RA---SIN') 

92 metadata.set("CTYPE2", 'DEC--SIN') 

93 metadata.setDouble("CD1_1", 5.10808596133527E-05) 

94 metadata.setDouble("CD1_2", 1.85579539217196E-07) 

95 metadata.setDouble("CD2_2", -5.10281493481982E-05) 

96 metadata.setDouble("CD2_1", -8.27440751733828E-07) 

97 return makeSkyWcs(metadata) 

98 

99 def testSnap(self): 

100 tMi, sMi, sK, kcs, confake = diffimTools.makeFakeKernelSet(bgValue=self.bgValue) 

101 

102 tWcs = self.makeWcs(offset=0) 

103 sWcs = self.makeWcs(offset=0) 

104 tExp = afwImage.ExposureF(tMi, tWcs) 

105 sExp = afwImage.ExposureF(sMi, sWcs) 

106 sExp.setPsf(self.psf) 

107 psfMatchAL = ipDiffim.SnapPsfMatchTask(config=self.configAL) 

108 psfMatchDF = ipDiffim.SnapPsfMatchTask(config=self.configDF) 

109 psfMatchDFr = ipDiffim.SnapPsfMatchTask(config=self.configDFr) 

110 psfMatchAL.subtractMaskedImages(tMi, sMi, psfMatchAL.makeCandidateList(tExp, sExp, self.ksize)) 

111 psfMatchDF.subtractMaskedImages(tMi, sMi, psfMatchDF.makeCandidateList(tExp, sExp, self.ksize)) 

112 psfMatchDFr.subtractMaskedImages(tMi, sMi, psfMatchDFr.makeCandidateList(tExp, sExp, self.ksize)) 

113 

114 def tearDown(self): 

115 del self.configAL 

116 del self.configDF 

117 del self.configDFr 

118 del self.psf 

119 

120 

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

122 pass 

123 

124 

125def setup_module(module): 

126 lsst.utils.tests.init() 

127 

128 

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

130 lsst.utils.tests.init() 

131 unittest.main()