Coverage for tests / test_brighterFatter.py: 25%

59 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-01 08:30 +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 

29from lsst.ip.isr import BrighterFatterKernel 

30from lsst.ip.isr.brighterFatterKernel import (brighterFatterCorrection, 

31 fluxConservingBrighterFatterCorrection) 

32 

33 

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

35 

36 def setUp(self): 

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

38 """ 

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

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

41 self.detector = detectorWrapper.detector 

42 camera = cameraBuilder.finish() 

43 

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

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

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

47 

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

49 covar[0, 0] = 1.0 

50 

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

52 kernel[8, 8] = 1.0 

53 

54 for amp in self.detector: 

55 ampName = amp.getName() 

56 if amp in self.bfk.badAmps: 

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

58 False] 

59 else: 

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

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

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

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

64 self.bfk.gain[ampName] = 1.0 

65 self.bfk.noise[ampName] = 5.0 

66 

67 self.bfk.meanXcorrs[ampName] = kernel 

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

69 

70 self.bfk.ampKernels[ampName] = kernel 

71 

72 def test_BrighterFatterInterface(self): 

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

74 kernel on a flat image""" 

75 

76 image = afwImage.ImageF(100, 100) 

77 image.set(100) 

78 ref_image = afwImage.ImageF(image, True) 

79 

80 mi = afwImage.makeMaskedImage(image) 

81 exp = afwImage.makeExposure(mi) 

82 

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

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

85 

86 brighterFatterCorrection(exp, kernelToUse, 5, 100, False) 

87 self.assertImagesEqual(ref_image, image) 

88 

89 fluxConservingBrighterFatterCorrection(exp, kernelToUse, 5, 100, False) 

90 self.assertImagesEqual(ref_image, image) 

91 

92 def test_BrighterFatterIO(self): 

93 dictionary = self.bfk.toDict() 

94 newBfk = BrighterFatterKernel().fromDict(dictionary) 

95 self.assertEqual(self.bfk, newBfk) 

96 

97 tables = self.bfk.toTable() 

98 newBfk = BrighterFatterKernel().fromTable(tables) 

99 self.assertEqual(self.bfk, newBfk) 

100 

101 

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

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

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

111 lsst.utils.tests.init() 

112 unittest.main()