Coverage for tests/test_negative.py : 86%

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_algorithms.
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/>.
22import unittest
24import lsst.geom
25import lsst.afw.table as afwTable
26import lsst.daf.base as dafBase
27from lsst.meas.algorithms import SourceDetectionTask
28from lsst.meas.base import SingleFrameMeasurementTask as SourceMeasurementTask
29from lsst.meas.algorithms.testUtils import plantSources
30import lsst.utils.tests
32try:
33 display
34except NameError:
35 display = False
36else:
37 import lsst.afw.display as afwDisplay
38 afwDisplay.setDefaultMaskTransparency(75)
41class NegativeMeasurementTestCase(lsst.utils.tests.TestCase):
42 """A test case for negative objects.
43 """
45 def testBasics(self):
46 bbox = lsst.geom.Box2I(lsst.geom.Point2I(256, 100), lsst.geom.Extent2I(128, 127))
47 minCounts = 2000
48 maxCounts = 20000
49 starSigma = 1.5
50 numX = 4
51 numY = 4
52 coordList = self.makeCoordList(
53 bbox=bbox,
54 numX=numX,
55 numY=numY,
56 minCounts=minCounts,
57 maxCounts=maxCounts,
58 sigma=starSigma,
59 )
60 kwid = 11
61 sky = 2000
62 addPoissonNoise = True
63 exposure = plantSources(bbox=bbox, kwid=kwid, sky=sky, coordList=coordList,
64 addPoissonNoise=addPoissonNoise)
66 if display: 66 ↛ 67line 66 didn't jump to line 67, because the condition on line 66 was never true
67 disp = afwDisplay.Display(frame=1)
68 disp.mtv(exposure, title=self._testMethodName + ": image with -ve sources")
70 schema = afwTable.SourceTable.makeMinimalSchema()
71 config = SourceDetectionTask.ConfigClass()
72 config.reEstimateBackground = False
73 config.thresholdPolarity = 'both'
74 detection = SourceDetectionTask(config=config, schema=schema)
75 algMetadata = dafBase.PropertyList()
76 measurement = SourceMeasurementTask(schema=schema, algMetadata=algMetadata)
78 table = afwTable.SourceTable.make(schema)
79 detections = detection.run(table, exposure)
80 sources = detections.sources
81 fpSets = detections.fpSets
83 self.assertEqual(len(sources), numX*numY)
84 self.assertEqual(fpSets.numPos, numX*numY/2)
85 self.assertEqual(fpSets.numNeg, numX*numY/2)
87 measurement.run(sources, exposure)
89 nGoodCent = 0
90 nGoodShape = 0
91 for s in sources:
92 cent = s.getCentroid()
93 shape = s.getShape()
95 if cent[0] == cent[0] and cent[1] == cent[1]: 95 ↛ 98line 95 didn't jump to line 98, because the condition on line 95 was never false
96 nGoodCent += 1
98 if (shape.getIxx() == shape.getIxx() 98 ↛ 103line 98 didn't jump to line 103, because the condition on line 98 was never false
99 and shape.getIyy() == shape.getIyy()
100 and shape.getIxy() == shape.getIxy()):
101 nGoodShape += 1
103 if display: 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true
104 xy = cent[0], cent[1]
105 disp.dot('+', *xy)
106 disp.dot(shape, *xy, ctype=afwDisplay.RED)
108 self.assertEqual(nGoodCent, numX*numY)
109 self.assertEqual(nGoodShape, numX*numY)
111 def makeCoordList(self, bbox, numX, numY, minCounts, maxCounts, sigma):
112 """Make a coordList for makeExposure.
113 """
114 dX = bbox.getWidth()/float(numX)
115 dY = bbox.getHeight()/float(numY)
116 minX = bbox.getMinX() + (dX/2.0)
117 minY = bbox.getMinY() + (dY/2.0)
118 dCounts = (maxCounts - minCounts)/(numX*numY/2 - 1)
120 coordList = []
121 counts = minCounts
122 for i in range(numX):
123 x = minX + (dX*i)
124 for j in range(numY):
125 y = minY + (dY*j)
126 if j%2 == 0:
127 coordList.append([x, y, counts, sigma])
128 else:
129 coordList.append([x, y, -counts, sigma])
130 counts += dCounts
131 return coordList
134class TestMemory(lsst.utils.tests.MemoryTestCase):
135 pass
138def setup_module(module):
139 lsst.utils.tests.init()
142if __name__ == "__main__": 142 ↛ 143line 142 didn't jump to line 143, because the condition on line 142 was never true
143 lsst.utils.tests.init()
144 unittest.main()