Coverage for tests/test_diaCatalogSourceSelector.py: 25%
79 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-27 09:43 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-27 09:43 +0000
1#
2# LSST Data Management System
3# Copyright 2008-2016 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
24import numpy as np
26import lsst.utils.tests
27import lsst.afw.table as afwTable
28import lsst.afw.image as afwImage
29import lsst.geom as geom
30from lsst.meas.algorithms import LoadReferenceObjectsTask, getRefFluxField
31import lsst.ip.diffim as ipDiffim
34class DiaCatalogSourceSelectorTest(lsst.utils.tests.TestCase):
36 def setUp(self):
37 schema = afwTable.SourceTable.makeMinimalSchema()
38 schema.addField("test_instFlux", type=float)
39 schema.addField("test_instFluxErr", type=float)
40 self.sourceSelector = ipDiffim.DiaCatalogSourceSelectorTask()
41 for flag in self.sourceSelector.config.badFlags:
42 schema.addField(flag, type="Flag")
43 table = afwTable.SourceTable.make(schema)
44 table.definePsfFlux("test")
45 self.srcCat = afwTable.SourceCatalog(table)
46 self.exposure = afwImage.ExposureF()
48 def tearDown(self):
49 del self.sourceSelector
50 del self.exposure
51 del self.srcCat
53 def makeRefCatalog(self):
54 schema = LoadReferenceObjectsTask.makeMinimalSchema(filterNameList=["g", "r"],
55 addIsPhotometric=True,
56 addIsResolved=True)
57 catalog = afwTable.SimpleCatalog(schema)
58 return catalog
60 def makeMatches(self, refCat, srcCat, nSrc):
61 for i in range(nSrc):
63 refSrc = refCat.addNew()
64 srcSrc = srcCat.addNew()
66 raDeg, decDeg = np.random.randn(2)
67 coord = geom.SpherePoint(raDeg, decDeg, geom.degrees)
69 refSrc.set("g_flux", 10**(-0.4*18))
70 refSrc.set("r_flux", 10**(-0.4*18))
71 refSrc.set("resolved", False)
72 refSrc.set("photometric", True)
73 refSrc.setCoord(coord)
75 srcSrc.setCoord(coord)
76 srcSrc.set("slot_PsfFlux_instFlux", 10.)
77 srcSrc.set("slot_PsfFlux_instFluxErr", 1.)
78 for flag in self.sourceSelector.config.badFlags:
79 srcSrc.set(flag, False)
81 mc = afwTable.MatchControl()
82 mc.symmetricMatch = False
83 mat = afwTable.matchRaDec(refCat, srcCat, 1.0 * geom.arcseconds, mc)
84 self.assertEqual(len(mat), nSrc)
85 return mat
87 def testCuts(self):
88 nSrc = 5
90 refCat = self.makeRefCatalog()
92 matches = self.makeMatches(refCat, self.srcCat, nSrc)
93 sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat
94 self.assertEqual(len(sources), nSrc)
96 # Set one of the source flags to be bad
97 matches[0].second.set(self.sourceSelector.config.badFlags[0], True)
98 sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat
99 self.assertEqual(len(sources), nSrc-1)
101 # Set one of the ref flags to be bad
102 matches[1].first.set("photometric", False)
103 sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat
104 self.assertEqual(len(sources), nSrc-2)
106 # Set one of the colors to be bad
107 grMin = self.sourceSelector.config.grMin
108 rFluxField = getRefFluxField(refCat.schema, "r")
109 gFluxField = getRefFluxField(refCat.schema, "g")
110 gFlux = 10**(-0.4 * (grMin - 0.1)) * matches[2].first.get(rFluxField)
111 matches[2].first.set(gFluxField, gFlux)
112 sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat
113 self.assertEqual(len(sources), nSrc-3)
115 # Set one of the types to be bad
116 if self.sourceSelector.config.selectStar and not self.sourceSelector.config.selectGalaxy:
117 matches[3].first.set("resolved", True)
118 sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat
119 self.assertEqual(len(sources), nSrc-4)
122class TestMemory(lsst.utils.tests.MemoryTestCase):
123 pass
126def setup_module(module):
127 lsst.utils.tests.init()
130if __name__ == "__main__": 130 ↛ 131line 130 didn't jump to line 131, because the condition on line 130 was never true
131 lsst.utils.tests.init()
132 unittest.main()