Coverage for tests / test_brighterFatter.py: 25%
59 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-22 09:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-22 09:07 +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#
23import unittest
24import numpy as np
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)
34class BrighterFatterTestCases(lsst.utils.tests.TestCase):
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()
44 self.bfk = BrighterFatterKernel(level='AMP', camera=camera, detectorId=1)
45 self.bfk.shape = (17, 17)
46 self.bfk.badAmps = ['amp 3']
48 covar = np.zeros((8, 8))
49 covar[0, 0] = 1.0
51 kernel = np.zeros(self.bfk.shape)
52 kernel[8, 8] = 1.0
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
67 self.bfk.meanXcorrs[ampName] = kernel
68 self.bfk.valid[ampName] = (ampName != 'amp 3')
70 self.bfk.ampKernels[ampName] = kernel
72 def test_BrighterFatterInterface(self):
73 """Test brighter fatter correction interface using a delta function
74 kernel on a flat image"""
76 image = afwImage.ImageF(100, 100)
77 image.set(100)
78 ref_image = afwImage.ImageF(image, True)
80 mi = afwImage.makeMaskedImage(image)
81 exp = afwImage.makeExposure(mi)
83 self.bfk.makeDetectorKernelFromAmpwiseKernels(self.detector.getName())
84 kernelToUse = self.bfk.detKernels[self.detector.getName()]
86 brighterFatterCorrection(exp, kernelToUse, 5, 100, False)
87 self.assertImagesEqual(ref_image, image)
89 fluxConservingBrighterFatterCorrection(exp, kernelToUse, 5, 100, False)
90 self.assertImagesEqual(ref_image, image)
92 def test_BrighterFatterIO(self):
93 dictionary = self.bfk.toDict()
94 newBfk = BrighterFatterKernel().fromDict(dictionary)
95 self.assertEqual(self.bfk, newBfk)
97 tables = self.bfk.toTable()
98 newBfk = BrighterFatterKernel().fromTable(tables)
99 self.assertEqual(self.bfk, newBfk)
102class MemoryTester(lsst.utils.tests.MemoryTestCase):
103 pass
106def setup_module(module):
107 lsst.utils.tests.init()
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()