Coverage for tests / test_peekExposureTask.py: 45%

52 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-15 00:08 +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 

23 

24import unittest 

25import numpy as np 

26 

27import lsst.afw.image as afwImage 

28import lsst.utils 

29import lsst.utils.tests 

30from lsst.pipe.tasks.peekExposure import PeekExposureTask, PeekExposureTaskConfig 

31 

32 

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

34 try: 

35 afwDataDir = lsst.utils.getPackageDir('afwdata') 

36 except Exception: 

37 afwDataDir = None 

38 

39 truthValuesDirect = { 

40 "postISRCCD_2020021800073-KPNO_406_828nm~EMPTY-det000.fits.fz": (2497.5, 1105.5), 

41 "postISRCCD_2020021800027-KPNO_406_828nm~EMPTY-det000.fits.fz": (1545.5, 1421.5), 

42 "postISRCCD_2020021800224-EMPTY~EMPTY-det000.fits.fz": (1865.5, 2269.5), 

43 } 

44 truthValuesDispersed = { 

45 "postISRCCD_2020021700249-EMPTY~ronchi90lpmm-det000.fits.fz": (2528.5, 2288.5), 

46 "postISRCCD_2020031500119-EMPTY~ronchi90lpmm-det000.fits.fz": (2117, 2182), 

47 } 

48 

49 TOLERANCE = 2 # number of pixels total distance it's acceptable to miss by 

50 

51 @unittest.skipUnless(afwDataDir, "afwdata not available") 

52 def setUp(self): 

53 self.directConfig = PeekExposureTaskConfig() 

54 self.directTask = PeekExposureTask(config=self.directConfig) 

55 

56 # support for handling dispersed images seperately in future via config 

57 self.dispersedConfig = PeekExposureTaskConfig() 

58 self.dispersedTask = PeekExposureTask(config=self.dispersedConfig) 

59 

60 @unittest.skipUnless(afwDataDir, "afwdata not available") 

61 def testDirectCentroiding(self): 

62 task = self.directTask 

63 filenames = self.truthValuesDirect.keys() 

64 

65 for filename in filenames: 

66 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", filename) 

67 trueCentroid = self.truthValuesDirect[filename] 

68 

69 exp = afwImage.ExposureF(fullName) 

70 result = task.run(exp) 

71 foundCentroid = result.brightestCentroid 

72 

73 dist = np.linalg.norm(np.asarray(foundCentroid) - np.asarray(trueCentroid)) 

74 

75 self.assertLess(dist, self.TOLERANCE) 

76 

77 @unittest.skipUnless(afwDataDir, "afwdata not available") 

78 def testDispersedCentroiding(self): 

79 task = self.dispersedTask 

80 filenames = self.truthValuesDispersed.keys() 

81 

82 for filename in filenames: 

83 fullName = os.path.join(self.afwDataDir, "LATISS/postISRCCD", filename) 

84 trueCentroid = self.truthValuesDispersed[filename] 

85 

86 exp = afwImage.ExposureF(fullName) 

87 result = task.run(exp) 

88 foundCentroid = result.brightestCentroid 

89 

90 dist = np.linalg.norm(np.asarray(foundCentroid) - np.asarray(trueCentroid)) 

91 self.assertLess(dist, self.TOLERANCE) 

92 

93 

94def setup_module(module): 

95 lsst.utils.tests.init() 

96 

97 

98class MemoryTestCase(lsst.utils.tests.MemoryTestCase): 

99 pass 

100 

101 

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

103 lsst.utils.tests.init() 

104 unittest.main()