Coverage for tests/test_Blendedness.py: 38%

47 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-24 02: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.geom 

25import lsst.daf.base 

26import lsst.meas.base 

27import lsst.utils.tests 

28 

29from lsst.meas.base.tests import AlgorithmTestCase 

30 

31 

32class BlendednessTestCase(AlgorithmTestCase, lsst.utils.tests.TestCase): 

33 

34 def setUp(self): 

35 self.center = lsst.geom.Point2D(50.1, 49.8) 

36 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(1, 4), 

37 lsst.geom.Extent2I(110, 160)) 

38 self.dataset = lsst.meas.base.tests.TestDataset(self.bbox) 

39 with self.dataset.addBlend() as family: 

40 family.addChild(instFlux=2E5, centroid=lsst.geom.Point2D(47, 33)) 

41 family.addChild(instFlux=1.5E5, centroid=lsst.geom.Point2D(53, 31)) 

42 

43 def tearDown(self): 

44 del self.center 

45 del self.bbox 

46 del self.dataset 

47 

48 def testAbsExpectation(self): 

49 f = lsst.meas.base.BlendednessAlgorithm.computeAbsExpectation 

50 # comparison values computed with Mathematica 

51 self.assertFloatsAlmostEqual(f(-1.0, 1.5**2), 0.897767011, rtol=1E-5) 

52 self.assertFloatsAlmostEqual(f(0.0, 1.5**2), 1.19682684, rtol=1E-5) 

53 self.assertFloatsAlmostEqual(f(1.0, 1.5**2), 1.64102639, rtol=1E-5) 

54 self.assertFloatsAlmostEqual(f(-1.0, 0.3**2), 0.0783651228, rtol=1E-5) 

55 self.assertFloatsAlmostEqual(f(0.0, 0.3**2), 0.239365368, rtol=1E-5) 

56 self.assertFloatsAlmostEqual(f(1.0, 0.3**2), 1.00046288, rtol=1E-5) 

57 

58 def testAbsBias(self): 

59 f = lsst.meas.base.BlendednessAlgorithm.computeAbsBias 

60 # comparison values computed with Mathematica 

61 self.assertFloatsAlmostEqual(f(0.0, 1.5**2), 1.19682684, rtol=1E-5) 

62 self.assertFloatsAlmostEqual(f(0.5, 1.5**2), 0.762708343, rtol=1E-5) 

63 self.assertFloatsAlmostEqual(f(1.0, 1.5**2), 0.453358941, rtol=1E-5) 

64 self.assertFloatsAlmostEqual(f(0.0, 0.3**2), 0.239365368, rtol=1E-5) 

65 self.assertFloatsAlmostEqual(f(0.5, 0.3**2), 0.011895931, rtol=1E-5) 

66 self.assertFloatsAlmostEqual(f(1.0, 0.3**2), 0.0000672467314, rtol=1E-5) 

67 

68 def testBlendedness(self): 

69 """Test that we measure a positive blendedness for overlapping sources. 

70 """ 

71 task = self.makeSingleFrameMeasurementTask("base_Blendedness") 

72 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0) 

73 task.run(catalog, exposure) 

74 self.assertGreater(catalog[1].get('base_Blendedness_abs'), 0) 

75 self.assertGreater(catalog[2].get('base_Blendedness_abs'), 0) 

76 

77 

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

79 pass 

80 

81 

82def setup_module(module): 

83 lsst.utils.tests.init() 

84 

85 

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

87 lsst.utils.tests.init() 

88 unittest.main()