Coverage for tests/test_defaultZeroPoint.py: 41%

33 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-10 12:01 +0000

1# 

2# LSST Data Management System 

3# 

4# Copyright 2008-2016 AURA/LSST. 

5# 

6# This product includes software developed by the 

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

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

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

22# 

23import unittest 

24import numpy as np 

25 

26import lsst.afw.image as afwImage 

27import lsst.afw.geom as afwGeom 

28import lsst.geom as geom 

29import lsst.meas.modelfit as measModel 

30import lsst.utils 

31 

32 

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

34 """Test that photoCalib objects containing invalid calibrations are 

35 replaced with a default having a zero-point of magnitude 27. 

36 """ 

37 

38 def setUp(self): 

39 """Create two calibs, one with a valid zero-point and one without. 

40 

41 Use these to create two UnitSystem objects. 

42 """ 

43 self.mag2Flux = lambda m: 10.0**(m/2.5) 

44 self.flux2Mag = lambda f: 2.5*np.log10(f) 

45 

46 photoCalibNoZero = afwImage.PhotoCalib() 

47 photoCalibWithZero = afwImage.makePhotoCalibFromCalibZeroPoint(self.mag2Flux(25)) 

48 

49 scale = 0.2 * geom.arcseconds 

50 wcs = afwGeom.makeSkyWcs(crpix=geom.Point2D(), 

51 crval=geom.SpherePoint(45.0, 45.0, geom.degrees), 

52 cdMatrix=afwGeom.makeCdMatrix(scale=scale)) 

53 

54 self.unitNoZero = measModel.UnitSystem(wcs, photoCalibNoZero) 

55 self.unitWithZero = measModel.UnitSystem(wcs, photoCalibWithZero) 

56 

57 def testZeroPoint(self): 

58 """Verify that the UnitSystem with an invalid photoCalib gets populated 

59 with a valid photoCalib, and that nothing happens to the UnitSystem 

60 with a valid photoCalib. 

61 """ 

62 magNoZero = self.flux2Mag(self.unitNoZero.photoCalib.getInstFluxAtZeroMagnitude()) 

63 magWithZero = self.flux2Mag(self.unitWithZero.photoCalib.getInstFluxAtZeroMagnitude()) 

64 

65 print((magNoZero, magWithZero)) 

66 

67 self.assertAlmostEqual(magNoZero, 27, 6) 

68 self.assertAlmostEqual(magWithZero, 25, 6) 

69 

70 def tearDown(self): 

71 del self.unitNoZero 

72 del self.unitWithZero 

73 

74 

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

76 pass 

77 

78 

79def setup_module(module): 

80 lsst.utils.tests.init() 

81 

82 

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

84 lsst.utils.tests.init() 

85 unittest.main()