Coverage for tests/test_brighterFatter.py: 25%

57 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-14 12:22 +0000

1# 

2# LSST Data Management System 

3# Copyright 2008-2017 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# 

22 

23import unittest 

24import numpy as np 

25 

26import lsst.utils.tests 

27import lsst.afw.cameraGeom as cameraGeom 

28import lsst.afw.image as afwImage 

29import lsst.ip.isr.isrFunctions as isrFunctions 

30from lsst.ip.isr import BrighterFatterKernel 

31 

32 

33class BrighterFatterTestCases(lsst.utils.tests.TestCase): 

34 

35 def setUp(self): 

36 """Set up a no-op BFK dataset 

37 """ 

38 cameraBuilder = cameraGeom.Camera.Builder('fake camera') 

39 detectorWrapper = cameraGeom.testUtils.DetectorWrapper(numAmps=4, cameraBuilder=cameraBuilder) 

40 self.detector = detectorWrapper.detector 

41 camera = cameraBuilder.finish() 

42 

43 self.bfk = BrighterFatterKernel(level='AMP', camera=camera, detectorId=1) 

44 self.bfk.shape = (17, 17) 

45 self.bfk.badAmps = ['amp 3'] 

46 

47 covar = np.zeros((8, 8)) 

48 covar[0, 0] = 1.0 

49 

50 kernel = np.zeros(self.bfk.shape) 

51 kernel[8, 8] = 1.0 

52 

53 for amp in self.detector: 

54 ampName = amp.getName() 

55 if amp in self.bfk.badAmps: 

56 self.bfk.expIdMask[ampName] = [False, False, False, False, False, False, False, False, False, 

57 False] 

58 else: 

59 self.bfk.expIdMask[ampName] = [True, True, True, True, True, True, True, True, False, False] 

60 self.bfk.rawMeans[ampName] = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] 

61 self.bfk.rawVariances[ampName] = np.array(self.bfk.rawMeans[ampName], dtype=float) 

62 self.bfk.rawXcorrs[ampName] = [covar for _ in self.bfk.rawMeans[ampName]] 

63 self.bfk.gain[ampName] = 1.0 

64 self.bfk.noise[ampName] = 5.0 

65 

66 self.bfk.meanXcorrs[ampName] = kernel 

67 self.bfk.valid[ampName] = (ampName != 'amp 3') 

68 

69 self.bfk.ampKernels[ampName] = kernel 

70 

71 def test_BrighterFatterInterface(self): 

72 """Test brighter fatter correction interface using a delta function 

73 kernel on a flat image""" 

74 

75 image = afwImage.ImageF(100, 100) 

76 image.set(100) 

77 ref_image = afwImage.ImageF(image, True) 

78 

79 mi = afwImage.makeMaskedImage(image) 

80 exp = afwImage.makeExposure(mi) 

81 

82 self.bfk.makeDetectorKernelFromAmpwiseKernels(self.detector.getName()) 

83 kernelToUse = self.bfk.detKernels[self.detector.getName()] 

84 

85 isrFunctions.brighterFatterCorrection(exp, kernelToUse, 5, 100, False) 

86 self.assertImagesEqual(ref_image, image) 

87 

88 def test_BrighterFatterIO(self): 

89 dictionary = self.bfk.toDict() 

90 newBfk = BrighterFatterKernel().fromDict(dictionary) 

91 self.assertEqual(self.bfk, newBfk) 

92 

93 tables = self.bfk.toTable() 

94 newBfk = BrighterFatterKernel().fromTable(tables) 

95 self.assertEqual(self.bfk, newBfk) 

96 

97 

98class MemoryTester(lsst.utils.tests.MemoryTestCase): 

99 pass 

100 

101 

102def setup_module(module): 

103 lsst.utils.tests.init() 

104 

105 

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

107 lsst.utils.tests.init() 

108 unittest.main()