Coverage for tests / test_skySources.py: 40%

41 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-22 09:17 +0000

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 

24 

25import lsst.afw.image as afwImage 

26import lsst.meas.extensions.piff.piffPsfDeterminer 

27import lsst.utils.tests 

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

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

30 

31TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

32 

33 

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

35 

36 def setUp(self): 

37 # Load sample input from disk 

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

39 self.exposure = afwImage.ExposureF(expPath) 

40 

41 def tearDown(self): 

42 del self.exposure 

43 

44 def testDoSkySources(self): 

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

46 """ 

47 self._checkSkySourceColumnExistence(doSkySources=True) 

48 self._checkSkySourceColumnExistence(doSkySources=False) 

49 

50 def _checkSkySourceColumnExistence(self, doSkySources): 

51 """Implements sky_source column checking. 

52 

53 Parameters 

54 ---------- 

55 doSkySource : `bool` 

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

57 """ 

58 charImConfig = CharacterizeImageConfig() 

59 charImConfig.measurePsf.psfDeterminer = 'piff' 

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

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

62 charImTask = CharacterizeImageTask(config=charImConfig) 

63 charImResults = charImTask.run(self.exposure) 

64 calibConfig = CalibrateConfig() 

65 calibConfig.doAstrometry = False 

66 calibConfig.doPhotoCal = False 

67 calibConfig.doSkySources = doSkySources 

68 calibConfig.doComputeSummaryStats = False 

69 calibTask = CalibrateTask(config=calibConfig) 

70 calibResults = calibTask.run(charImResults.exposure) 

71 if doSkySources: 

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

73 else: 

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

75 

76 

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

78 pass 

79 

80 

81def setup_module(module): 

82 lsst.utils.tests.init() 

83 

84 

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

86 lsst.utils.tests.init() 

87 unittest.main()