Coverage for tests/test_scaleZeroPoint.py: 25%

42 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-24 00:14 +0000

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 LSST Corporation. 

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 <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22import unittest 

23 

24import lsst.afw.image as afwImage 

25import lsst.utils.tests 

26from lsst.pipe.tasks.scaleZeroPoint import ScaleZeroPointTask 

27 

28 

29class ScaleZeroPointTaskTestCase(lsst.utils.tests.TestCase): 

30 

31 """A test case for ScaleZeroPointTask 

32 """ 

33 

34 def testBasics(self): 

35 for outZeroPoint in (23, 24): 

36 config = ScaleZeroPointTask.ConfigClass() 

37 config.zeroPoint = outZeroPoint 

38 zpScaler = ScaleZeroPointTask(config=config) 

39 outPhotoCalib = zpScaler.getPhotoCalib() 

40 

41 self.assertAlmostEqual(outPhotoCalib.instFluxToMagnitude(1.0), outZeroPoint) 

42 

43 for inZeroPoint in (24, 25.5): 

44 exposure = afwImage.ExposureF(10, 10) 

45 mi = exposure.getMaskedImage() 

46 mi.set(1.0) 

47 var = mi.getVariance() 

48 var.set(1.0) 

49 

50 inPhotoCalib = self.makePhotoCalib(inZeroPoint) 

51 exposure.setPhotoCalib(inPhotoCalib) 

52 imageScaler = zpScaler.computeImageScaler(exposure) 

53 

54 predScale = 1.0 / inPhotoCalib.magnitudeToInstFlux(outZeroPoint) 

55 self.assertAlmostEqual(predScale, imageScaler._scale) 

56 

57 inFluxAtOutZeroPoint = exposure.getPhotoCalib().magnitudeToInstFlux(outZeroPoint) 

58 outFluxAtOutZeroPoint = outPhotoCalib.magnitudeToInstFlux(outZeroPoint) 

59 self.assertAlmostEqual(outFluxAtOutZeroPoint / imageScaler._scale, inFluxAtOutZeroPoint) 

60 

61 inFluxMag0 = exposure.getPhotoCalib().getInstFluxAtZeroMagnitude() 

62 outFluxMag0 = outPhotoCalib.getInstFluxAtZeroMagnitude() 

63 self.assertFloatsAlmostEqual(outFluxMag0 / imageScaler._scale, inFluxMag0, rtol=5e-15) 

64 

65 imageScaler.scaleMaskedImage(mi) 

66 self.assertAlmostEqual(mi.image[1, 1, afwImage.LOCAL], predScale) 

67 self.assertAlmostEqual(mi.variance[1, 1, afwImage.LOCAL], predScale**2) 

68 

69 def makePhotoCalib(self, zeroPoint): 

70 fluxMag0 = 10**(0.4 * zeroPoint) 

71 return afwImage.makePhotoCalibFromCalibZeroPoint(fluxMag0, 1.0) 

72 

73 

74class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

75 pass 

76 

77 

78def setup_module(module): 

79 lsst.utils.tests.init() 

80 

81 

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

83 lsst.utils.tests.init() 

84 unittest.main()