Coverage for tests/test_functorKeys.py: 28%

60 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-15 03:00 -0700

1# 

2# LSST Data Management System 

3# Copyright 2008-2017 LSST Corporation. 

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

21# 

22import unittest 

23 

24import numpy as np 

25 

26import lsst.utils.tests 

27import lsst.afw.geom.ellipses 

28import lsst.shapelet.tests 

29import lsst.afw.image 

30import lsst.afw.table 

31 

32 

33class FunctorKeyTestCase(lsst.shapelet.tests.ShapeletTestCase): 

34 

35 def setUp(self): 

36 np.random.seed(500) 

37 

38 def testComputeOrder(self): 

39 invalidSizes = list(range(1, lsst.shapelet.computeSize(10))) 

40 for order in range(10): 

41 size = lsst.shapelet.computeSize(order) 

42 self.assertEqual(order, lsst.shapelet.computeOrder(size)) 

43 invalidSizes.remove(size) 

44 for size in invalidSizes: 

45 self.assertRaises(lsst.pex.exceptions.InvalidParameterError, lsst.shapelet.computeOrder, size) 

46 

47 def testShapeletFunctionKey(self): 

48 schema = lsst.afw.table.Schema() 

49 order = 4 

50 k0 = lsst.shapelet.ShapeletFunctionKey.addFields(schema, "s", "shapelet function", 

51 "pixel", "count", order) 

52 k1 = lsst.shapelet.ShapeletFunctionKey(k0.getEllipse(), k0.getCoefficients()) 

53 k2 = lsst.shapelet.ShapeletFunctionKey(schema["s"]) 

54 self.assertEqual(k0, k1) 

55 self.assertEqual(k1, k2) 

56 self.assertTrue(k0.isValid()) 

57 self.assertEqual(k0.getEllipse(), lsst.afw.table.EllipseKey(schema["s"])) 

58 self.assertEqual(k0.getCoefficients(), lsst.afw.table.ArrayDKey(schema["s"])) 

59 table = lsst.afw.table.BaseTable.make(schema) 

60 record = table.makeRecord() 

61 s0 = self.makeRandomShapeletFunction(order=order) 

62 record.set(k0, s0) 

63 s1 = record.get(k0) 

64 self.compareShapeletFunctions(s0, s1) 

65 self.assertRaises(lsst.pex.exceptions.InvalidParameterError, record.set, k0, 

66 self.makeRandomShapeletFunction(order=3)) 

67 

68 def testMultiShapeletFunctionKey(self): 

69 schema = lsst.afw.table.Schema() 

70 msf0 = self.makeRandomMultiShapeletFunction(nComponents=3) 

71 orders = [s.getOrder() for s in msf0.getComponents()] 

72 k0 = lsst.shapelet.MultiShapeletFunctionKey.addFields(schema, "s", "shapelet function", 

73 "pixel", "count", orders) 

74 k1 = lsst.shapelet.MultiShapeletFunctionKey([k0[i] for i in range(len(orders))]) 

75 k2 = lsst.shapelet.MultiShapeletFunctionKey(schema["s"]) 

76 self.assertEqual(k0, k1) 

77 self.assertEqual(k1, k2) 

78 self.assertTrue(k0.isValid()) 

79 table = lsst.afw.table.BaseTable.make(schema) 

80 record = table.makeRecord() 

81 record.set(k0, msf0) 

82 msf1 = record.get(k0) 

83 self.compareMultiShapeletFunctions(msf0, msf1) 

84 self.assertRaises(lsst.pex.exceptions.InvalidParameterError, record.set, k0, 

85 self.makeRandomMultiShapeletFunction(nComponents=4)) 

86 self.assertRaises(lsst.pex.exceptions.NotFoundError, 

87 lsst.shapelet.MultiShapeletFunctionKey, 

88 schema["a"]) 

89 

90 

91class MemoryTester(lsst.utils.tests.MemoryTestCase): 

92 pass 

93 

94 

95def setup_module(module): 

96 lsst.utils.tests.init() 

97 

98 

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

100 lsst.utils.tests.init() 

101 unittest.main()