Coverage for tests/test_Blendedness.py : 35%

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# 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/>.
22from contextlib import contextmanager
23import unittest
25import lsst.geom
26import lsst.daf.base
27import lsst.meas.base
28import lsst.utils.tests
30from lsst.meas.base.tests import AlgorithmTestCase
33@contextmanager
34def onlyLogFatal(log):
35 """For the duration of this context, only log ``FATAL`` errors.
37 This is convenient when testing algorithms under failure conditions: we
38 want to be able to check that they have set appropriate flags without
39 spewing alarming & confusing error messages to the console.
40 """
41 oldLevel = log.getThreshold()
42 log.setThreshold(log.FATAL)
43 try:
44 yield
45 finally:
46 log.setThreshold(oldLevel)
49class BlendednessTestCase(AlgorithmTestCase, lsst.utils.tests.TestCase):
51 def setUp(self):
52 self.center = lsst.geom.Point2D(50.1, 49.8)
53 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(1, 4),
54 lsst.geom.Extent2I(110, 160))
55 self.dataset = lsst.meas.base.tests.TestDataset(self.bbox)
56 with self.dataset.addBlend() as family:
57 family.addChild(instFlux=2E5, centroid=lsst.geom.Point2D(47, 33))
58 family.addChild(instFlux=1.5E5, centroid=lsst.geom.Point2D(53, 31))
60 def tearDown(self):
61 del self.center
62 del self.bbox
63 del self.dataset
65 def testAbsExpectation(self):
66 f = lsst.meas.base.BlendednessAlgorithm.computeAbsExpectation
67 # comparison values computed with Mathematica
68 self.assertFloatsAlmostEqual(f(-1.0, 1.5**2), 0.897767011, rtol=1E-5)
69 self.assertFloatsAlmostEqual(f(0.0, 1.5**2), 1.19682684, rtol=1E-5)
70 self.assertFloatsAlmostEqual(f(1.0, 1.5**2), 1.64102639, rtol=1E-5)
71 self.assertFloatsAlmostEqual(f(-1.0, 0.3**2), 0.0783651228, rtol=1E-5)
72 self.assertFloatsAlmostEqual(f(0.0, 0.3**2), 0.239365368, rtol=1E-5)
73 self.assertFloatsAlmostEqual(f(1.0, 0.3**2), 1.00046288, rtol=1E-5)
75 def testAbsBias(self):
76 f = lsst.meas.base.BlendednessAlgorithm.computeAbsBias
77 # comparison values computed with Mathematica
78 self.assertFloatsAlmostEqual(f(0.0, 1.5**2), 1.19682684, rtol=1E-5)
79 self.assertFloatsAlmostEqual(f(0.5, 1.5**2), 0.762708343, rtol=1E-5)
80 self.assertFloatsAlmostEqual(f(1.0, 1.5**2), 0.453358941, rtol=1E-5)
81 self.assertFloatsAlmostEqual(f(0.0, 0.3**2), 0.239365368, rtol=1E-5)
82 self.assertFloatsAlmostEqual(f(0.5, 0.3**2), 0.011895931, rtol=1E-5)
83 self.assertFloatsAlmostEqual(f(1.0, 0.3**2), 0.0000672467314, rtol=1E-5)
85 def testBlendedness(self):
86 """Test that we measure a positive blendedness for overlapping sources.
87 """
88 task = self.makeSingleFrameMeasurementTask("base_Blendedness")
89 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0)
90 task.run(catalog, exposure)
91 self.assertGreater(catalog[1].get('base_Blendedness_abs'), 0)
92 self.assertGreater(catalog[2].get('base_Blendedness_abs'), 0)
95class TestMemory(lsst.utils.tests.MemoryTestCase):
96 pass
99def setup_module(module):
100 lsst.utils.tests.init()
103if __name__ == "__main__": 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 lsst.utils.tests.init()
105 unittest.main()