Coverage for tests/test_quickFrameMeasurement.py: 42%

60 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-19 05:40 -0700

1# 

2# LSST Data Management System 

3# Copyright 2008-2017 AURA/LSST. 

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

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.quickFrameMeasurement import QuickFrameMeasurementTask, QuickFrameMeasurementTaskConfig 

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": (2496, 1105), 

41 "postISRCCD_2020021800027-KPNO_406_828nm~EMPTY-det000.fits.fz": (1550, 1423), 

42 "postISRCCD_2020021800224-EMPTY~EMPTY-det000.fits.fz": (1866, 2274), 

43 } 

44 truthValuesDispersed = { 

45 "postISRCCD_2020021700249-EMPTY~ronchi90lpmm-det000.fits.fz": (2531, 2286), 

46 "postISRCCD_2020031500119-EMPTY~ronchi90lpmm-det000.fits.fz": (2112, 2183), 

47 } 

48 

49 TOLERANCE = 5 # 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 = QuickFrameMeasurementTaskConfig() 

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

55 

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

57 self.dispersedConfig = QuickFrameMeasurementTaskConfig() 

58 self.dispersedTask = QuickFrameMeasurementTask(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.brightestObjCentroid 

72 

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

74 distCoM = np.linalg.norm(np.asarray(result.brightestObjCentroidCofM) - np.asarray(trueCentroid)) 

75 

76 self.assertLess(dist, self.TOLERANCE) 

77 self.assertLess(distCoM, self.TOLERANCE) 

78 

79 # offset size shouldn't really matter, just make it >> PSF, and make 

80 # sure the value isn't off-chip or right by the edge for any of the 

81 # test images 

82 offset = 250 

83 wrongCentroid = (foundCentroid[0]+offset, foundCentroid[1]+offset) 

84 with self.assertRaises(ValueError): 

85 task.checkResult(exp, wrongCentroid, -1, self.directConfig.centroidPixelPercentile) 

86 

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

88 def testDispersedCentroiding(self): 

89 task = self.dispersedTask 

90 filenames = self.truthValuesDispersed.keys() 

91 

92 for filename in filenames: 

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

94 trueCentroid = self.truthValuesDispersed[filename] 

95 

96 exp = afwImage.ExposureF(fullName) 

97 result = task.run(exp) 

98 foundCentroid = result.brightestObjCentroid 

99 

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

101 self.assertLess(dist, self.TOLERANCE) 

102 

103 # this doesn't matter much as CoM centroid is for donuts 

104 # and we don't intend to do dispersed donuts, but good to catch 

105 # big regressions. Can be removed later if needed 

106 distCoM = np.linalg.norm(np.asarray(result.brightestObjCentroidCofM) - np.asarray(trueCentroid)) 

107 self.assertLess(distCoM, self.TOLERANCE) 

108 

109 

110def setup_module(module): 

111 lsst.utils.tests.init() 

112 

113 

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

115 pass 

116 

117 

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

119 lsst.utils.tests.init() 

120 unittest.main()