Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# 

2# LSST Data Management System 

3# 

4# Copyright 2008-2016 AURA/LSST. 

5# 

6# This product includes software developed by the 

7# LSST Project (http://www.lsst.org/). 

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 LSST License Statement and 

20# the GNU General Public License along with this program. If not, 

21# see <https://www.lsstcorp.org/LegalNotices/>. 

22# 

23import unittest 

24import uuid 

25 

26import lsst.utils.tests 

27import lsst.afw.table as afwTable 

28import lsst.meas.extensions.photometryKron as photKron 

29from lsst.daf.base import PropertyList 

30 

31 

32def getTableDelimeter(schema): 

33 """ 

34 Return the character(s) used as delimeters within the given schema. 

35 

36 Should be "_" in the current afw.table implementation. This functionality 

37 is not otherwise exposed to Python. 

38 """ 

39 a, b = str(uuid.uuid1()), str(uuid.uuid1()) 

40 return schema.join(a, b).replace(a, '').replace(b, '') 

41 

42 

43class KronFlagHandlerTestCase(unittest.TestCase): 

44 """Test the FlagHandler used for Kron photometry""" 

45 

46 def testFlagDefinitions(self): 

47 """ 

48 Check flag order. 

49 

50 Flags must be added to the flag handler in the same order that they 

51 are defined in the algorithm. 

52 """ 

53 control = photKron.KronFluxControl() 

54 name = "kronTest" 

55 schema = afwTable.SourceTable.makeMinimalSchema() 

56 algMeta = PropertyList() 

57 

58 # Add the output fields -- including flags -- to the schema. 

59 photKron.KronFluxAlgorithm(control, name, schema, algMeta) 

60 

61 # Fetch a list of all flag fields, in the order that they were added 

62 # to the schema (and hence the order they were added to the FlagHandler) 

63 flagFieldNames = schema.extract("%s_flag*" % (name,), ordered=True).keys() 

64 # Iterate over each flag field, checking that they were enumerated in 

65 # the algorithm in the same order as in the FlagHandler. 

66 for i, flagFieldName in enumerate(flagFieldNames): 

67 if flagFieldName == "%s_flag" % (name,): 

68 # The generic "failure" flag is written into the schema as $name_flag. 

69 self.assertEqual(i, photKron.KronFluxAlgorithm.FAILURE.number) 

70 else: 

71 # Other flags are referenced by name. We assert that the 

72 # enumeration name (e.g. BAD_RADIUS) is an upper-case version 

73 # of the schema field name (e.g. flag_bad_radius), with the 

74 # "flag_" prefix stripped. 

75 flagName = flagFieldName.split(getTableDelimeter(schema), 2)[-1] 

76 self.assertEqual(i, getattr(photKron.KronFluxAlgorithm, flagName.upper()).number) 

77 

78 # Check that the number of enumerated flags matches the number of flag 

79 # fields in the schema. 

80 self.assertEqual(len(photKron.KronFluxAlgorithm.getFlagDefinitions()), len(flagFieldNames)) 

81 

82 

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

84 pass 

85 

86 

87def setup_module(module): 

88 lsst.utils.tests.init() 

89 

90 

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

92 lsst.utils.tests.init() 

93 unittest.main()