Coverage for tests/test_InputUtilities.py: 31%

46 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-03 03:00 -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 

28import testLib # noqa: F401 need this for SillyCentroid 

29 

30 

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

32 

33 def testFlagAliases(self): 

34 """Test flag aliases are created correctly. 

35 

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

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

38 `SafeCentroidExtractor` and `SafeShapeExtractor`). 

39 """ 

40 config = self.makeSingleFrameMeasurementConfig("base_GaussianFlux", 

41 ["base_SdssCentroid", "base_SdssShape"]) 

42 config.slots.centroid = "base_SdssCentroid" 

43 config.slots.shape = "base_SdssShape" 

44 task = self.makeSingleFrameMeasurementTask(config=config) 

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

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

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

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

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

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

51 # recursive expansion). 

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

53 "base_SdssCentroid_flag") 

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

55 "base_SdssShape_flag") 

56 

57 def testCentroidFlagAliases(self): 

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

59 """ 

60 config = self.makeSingleFrameMeasurementConfig("testLib_SillyCentroid", ["base_SdssCentroid"]) 

61 config.slots.centroid = "base_SdssCentroid" 

62 config.slots.shape = None 

63 config.slots.psfShape = None 

64 task = self.makeSingleFrameMeasurementTask(config=config) 

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

66 self.assertEqual(task.schema.find("testLib_SillyCentroid_flag_badInitialCentroid").key, 

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

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

69 self.assertEqual(task.schema.getAliasMap().get("testLib_SillyCentroid_flag_badInitialCentroid"), 

70 "base_SdssCentroid_flag") 

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

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

73 

74 def testUnmetCentroidDependency(self): 

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

76 

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

78 requires a centroid without the centroid slot set. 

79 """ 

80 config = self.makeSingleFrameMeasurementConfig("base_GaussianFlux", 

81 ["base_SdssCentroid", "base_SdssShape"]) 

82 config.slots.centroid = None 

83 config.slots.shape = "base_SdssShape" 

84 config.slots.psfShape = "base_SdssShape_psf" 

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

86 self.makeSingleFrameMeasurementTask(config=config) 

87 

88 def testUnmetShapeDependency(self): 

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

90 

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

92 requires a shape without the shape slot set. 

93 """ 

94 config = self.makeSingleFrameMeasurementConfig("base_GaussianFlux", 

95 ["base_SdssCentroid", "base_SdssShape"]) 

96 config.slots.centroid = "base_SdssCentroid" 

97 config.slots.shape = None 

98 config.slots.psfShape = None 

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

100 self.makeSingleFrameMeasurementTask(config=config) 

101 

102 

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

104 pass 

105 

106 

107def setup_module(module): 

108 lsst.utils.tests.init() 

109 

110 

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

112 lsst.utils.tests.init() 

113 unittest.main()