Coverage for tests/test_InputUtilities.py: 29%

45 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-06 03:06 -0700

1# This file is part of meas_base. 

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 unittest 

23 

24import lsst.afw.geom 

25import lsst.meas.base.tests 

26import lsst.pex.exceptions 

27import lsst.utils.tests 

28 

29 

30class InputUtilitiesTestCase(lsst.meas.base.tests.AlgorithmTestCase, lsst.utils.tests.TestCase): 

31 

32 def testFlagAliases(self): 

33 """Test flag aliases are created correctly. 

34 

35 In particular, we should get flag aliases to the slot centroid and 

36 shape algorithms when we initialize `GaussianFlux` (which uses both 

37 `SafeCentroidExtractor` and `SafeShapeExtractor`). 

38 """ 

39 config = self.makeSingleFrameMeasurementConfig("base_GaussianFlux", 

40 ["base_SdssCentroid", "base_SdssShape"]) 

41 config.slots.centroid = "base_SdssCentroid" 

42 config.slots.shape = "base_SdssShape" 

43 task = self.makeSingleFrameMeasurementTask(config=config) 

44 # Test that the aliases resolve to the correct field. 

45 self.assertEqual(task.schema.find("base_GaussianFlux_flag_badCentroid").key, 

46 task.schema.find("base_SdssCentroid_flag").key) 

47 self.assertEqual(task.schema.find("base_GaussianFlux_flag_badShape").key, 

48 task.schema.find("base_SdssShape_flag").key) 

49 # Test that the aliases are direct links (i.e. they do not require 

50 # recursive expansion). 

51 self.assertEqual(task.schema.getAliasMap().get("base_GaussianFlux_flag_badCentroid"), 

52 "base_SdssCentroid_flag") 

53 self.assertEqual(task.schema.getAliasMap().get("base_GaussianFlux_flag_badShape"), 

54 "base_SdssShape_flag") 

55 

56 def testCentroidFlagAliases(self): 

57 """Test aliases are correct when using multiple centroid algorithms. 

58 """ 

59 config = self.makeSingleFrameMeasurementConfig("base_NaiveCentroid", ["base_SdssCentroid"]) 

60 config.slots.centroid = "base_SdssCentroid" 

61 config.slots.shape = None 

62 config.slots.psfShape = None 

63 task = self.makeSingleFrameMeasurementTask(config=config) 

64 # Test that the alias resolves to the correct field. 

65 self.assertEqual(task.schema.find("base_NaiveCentroid_flag_badInitialCentroid").key, 

66 task.schema.find("base_SdssCentroid_flag").key) 

67 # Test that the alias is a direct links (i.e. it do not require recursive expansion). 

68 self.assertEqual(task.schema.getAliasMap().get("base_NaiveCentroid_flag_badInitialCentroid"), 

69 "base_SdssCentroid_flag") 

70 # Test that there is no circular alias for the slot centroider itself. 

71 self.assertRaises(LookupError, task.schema.find, "base_SdssCentroid_flag_badInitialCentroid") 

72 

73 def testUnmetCentroidDependency(self): 

74 """Test that an unmet centroid dependency raises. 

75 

76 We should throw a `LogicError` when initializing an algorithm that 

77 requires a centroid without the centroid slot set. 

78 """ 

79 config = self.makeSingleFrameMeasurementConfig("base_GaussianFlux", 

80 ["base_SdssCentroid", "base_SdssShape"]) 

81 config.slots.centroid = None 

82 config.slots.shape = "base_SdssShape" 

83 config.slots.psfShape = "base_SdssShape_psf" 

84 with self.assertRaises(lsst.pex.exceptions.LogicError): 

85 self.makeSingleFrameMeasurementTask(config=config) 

86 

87 def testUnmetShapeDependency(self): 

88 """Test that an unmet shape dependency raises. 

89 

90 Test that we throw a `LogicError` when initializing an algorithm that 

91 requires a shape without the shape slot set. 

92 """ 

93 config = self.makeSingleFrameMeasurementConfig("base_GaussianFlux", 

94 ["base_SdssCentroid", "base_SdssShape"]) 

95 config.slots.centroid = "base_SdssCentroid" 

96 config.slots.shape = None 

97 config.slots.psfShape = None 

98 with self.assertRaises(lsst.pex.exceptions.LogicError): 

99 self.makeSingleFrameMeasurementTask(config=config) 

100 

101 

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

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

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

111 lsst.utils.tests.init() 

112 unittest.main()