Coverage for tests/test_ticket-2871.py: 29%
54 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-15 09:11 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-15 09:11 +0000
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
25import lsst.utils.tests
26import lsst.afw.detection as afwDetection
27import lsst.afw.image as afwImage
28import lsst.geom as geom
29import lsst.afw.geom as afwGeom
30import lsst.afw.table as afwTable
31import lsst.meas.algorithms as algorithms
34class DeblendTestCase(unittest.TestCase):
35 """A test case for deblending
36 """
38 def checkDeblender(self):
39 try:
40 import lsst.meas.deblender # noqa F401
41 except ImportError as e:
42 self.skipTest("Cannot import lsst.meas.deblender: %s" % e)
44 def testFailures(self):
45 """Test deblender failure flagging (#2871)
47 We create a good source which is expected to pass and a bad source
48 which is expected to fail because its footprint goes off the image.
49 This latter case may not happen in practise, but it is useful for
50 checking the plumbing of the deblender.
51 """
52 import lsst.meas.deblender as measDeb
54 self.checkDeblender()
55 xGood, yGood = 57, 86
56 # Required to be in image so we can evaluate the PSF; will put neighbour just outside
57 xBad, yBad = 0, 0
58 flux = 100.0
59 dims = geom.Extent2I(128, 128)
61 mi = afwImage.MaskedImageF(dims)
62 mi.getVariance().set(1.0)
63 image = mi.getImage()
64 image.set(0)
65 image[xGood, yGood, afwImage.LOCAL] = flux
67 exposure = afwImage.makeExposure(mi)
68 psf = algorithms.DoubleGaussianPsf(21, 21, 3.)
69 exposure.setPsf(psf)
71 schema = afwTable.SourceTable.makeMinimalSchema()
73 config = measDeb.SourceDeblendConfig()
74 config.catchFailures = True
75 task = measDeb.SourceDeblendTask(schema, config=config)
77 catalog = afwTable.SourceCatalog(schema)
79 def makeSource(x, y, offset=-2, size=3.0):
80 """Make a source in the catalog
82 Two peaks are created: one at the specified
83 position, and one offset in x,y.
84 The footprint is of the nominated size.
85 """
86 src = catalog.addNew()
87 spans = afwGeom.SpanSet.fromShape(int(size), offset=(x, y))
88 foot = afwDetection.Footprint(spans)
89 foot.addPeak(x, y, flux)
90 foot.addPeak(x + offset, y + offset, flux)
91 src.setFootprint(foot)
92 return src
94 good = makeSource(xGood, yGood)
95 bad = makeSource(xBad, yBad)
97 task.run(exposure, catalog)
99 self.assertFalse(good.get('deblend_failed'))
100 self.assertTrue(bad.get('deblend_failed'))
103class TestMemory(lsst.utils.tests.MemoryTestCase):
104 pass
107def setup_module(module):
108 lsst.utils.tests.init()
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()