Coverage for tests/test_skySources.py: 40%

43 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-03 03:41 -0700

1# This file is part of pipe_tasks. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

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 GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22import os 

23import unittest 

24import logging 

25 

26import lsst.afw.image as afwImage 

27import lsst.meas.extensions.piff.piffPsfDeterminer 

28import lsst.utils.tests 

29from lsst.utils import getPackageDir 

30from lsst.pipe.tasks.characterizeImage import CharacterizeImageTask, CharacterizeImageConfig 

31from lsst.pipe.tasks.calibrate import CalibrateTask, CalibrateConfig 

32 

33 

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

35 

36 def setUp(self): 

37 # Load sample input from disk 

38 expPath = os.path.join(getPackageDir("pipe_tasks"), "tests", "data", "v695833-e0-c000-a00.sci.fits") 

39 self.exposure = afwImage.ExposureF(expPath) 

40 # set log level so that warnings do not display 

41 logging.getLogger("lsst.calibrate").setLevel(logging.ERROR) 

42 

43 def tearDown(self): 

44 del self.exposure 

45 

46 def testDoSkySources(self): 

47 """Tests sky_source column gets added when run. 

48 """ 

49 self._checkSkySourceColumnExistence(doSkySources=True) 

50 self._checkSkySourceColumnExistence(doSkySources=False) 

51 

52 def _checkSkySourceColumnExistence(self, doSkySources): 

53 """Implements sky_source column checking. 

54 

55 Parameters 

56 ---------- 

57 doSkySource : `bool` 

58 Value of the config flag determining whether to insert sky sources. 

59 """ 

60 charImConfig = CharacterizeImageConfig() 

61 charImConfig.measurePsf.psfDeterminer = 'piff' 

62 charImConfig.measurePsf.psfDeterminer['piff'].spatialOrder = 0 

63 charImConfig.measureApCorr.sourceSelector["science"].doSignalToNoise = False 

64 charImTask = CharacterizeImageTask(config=charImConfig) 

65 charImResults = charImTask.run(self.exposure) 

66 calibConfig = CalibrateConfig() 

67 calibConfig.doAstrometry = False 

68 calibConfig.doPhotoCal = False 

69 calibConfig.doSkySources = doSkySources 

70 calibConfig.doComputeSummaryStats = False 

71 calibTask = CalibrateTask(config=calibConfig) 

72 calibResults = calibTask.run(charImResults.exposure) 

73 if doSkySources: 

74 self.assertTrue('sky_source' in calibResults.outputCat.schema.getNames()) 

75 else: 

76 self.assertFalse('sky_source' in calibResults.outputCat.schema.getNames()) 

77 

78 

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

80 pass 

81 

82 

83def setup_module(module): 

84 lsst.utils.tests.init() 

85 

86 

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

88 lsst.utils.tests.init() 

89 unittest.main()