Coverage for tests/test_ccdImage.py : 33%

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 jointcal.
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/>.
22"""Test creation and use of the CcdImage class."""
23import unittest
25import lsst.utils.tests
26from lsst.jointcal import testUtils
28import lsst.geom
29import lsst.jointcal
32class CcdImageTestCase(lsst.utils.tests.TestCase):
33 def setUp(self):
34 self.nStars1 = 4
35 self.nStars2 = 100
36 struct = testUtils.createTwoFakeCcdImages(num1=self.nStars1, num2=self.nStars2)
37 self.ccdImage1 = struct.ccdImageList[0]
38 self.ccdImage2 = struct.ccdImageList[1]
39 self.bbox = struct.bbox
41 self.associations = lsst.jointcal.Associations(struct.ccdImageList)
43 def checkCountStars(self, ccdImage, nStars):
44 """Check that ccdImage.countStars() is correct under various conditions.
46 Parameters
47 ----------
48 ccdImage : `lsst.jointcal.CcdImage`
49 The ccdImage to test.
50 nStars : `int`
51 Number of stars in ccdImage's catalog.
53 Notes
54 -----
55 Does not test the case where some ``measuredStars`` are not ``valid``,
56 as there is no interface for modifying that the python level. To test
57 that would require creating a `Fitter` and a fake outlier list and
58 calling ``removeMeasOutliers`` and/or ``removeRefOutliers``, which
59 cannot be easily made part of the python API.
60 """
61 # By default there are no stars because catalogForFit is uninitialized.
62 measStars, refStars = ccdImage.countStars()
63 self.assertEqual(measStars, 0)
64 self.assertEqual(refStars, 0)
66 # With no associations, the catalog should have exactly as many valid
67 # measuredStars as were created.
68 ccdImage.resetCatalogForFit()
69 measStars, refStars = ccdImage.countStars()
70 self.assertEqual(measStars, nStars)
71 self.assertEqual(refStars, 0)
73 # Cross match catalogs: there will still be no refcat matches.
74 matchCut = 3.0 * lsst.geom.arcseconds
75 # There should be no fittedStars until we associate the catalogs.
76 self.assertEqual(self.associations.fittedStarListSize(), 0)
77 self.associations.computeCommonTangentPoint()
78 self.associations.associateCatalogs(matchCut)
79 # Confirm that every measuredStar (in both ccdImages) got a fittedStar associated to it.
80 self.assertEqual(self.associations.fittedStarListSize(), self.nStars1 + self.nStars2)
81 # measuredStars and refStars should be unchanged after association.
82 self.assertEqual(measStars, nStars)
83 self.assertEqual(refStars, 0)
85 # Make a fake reference catalog; will match the catalog one-to-one.
86 skyWcs = ccdImage.getReadWcs().getSkyWcs()
87 self.refCat = testUtils.createFakeCatalog(nStars, self.bbox, "refFlux", skyWcs=skyWcs, refCat=True)
88 # associate the reference stars
89 self.associations.collectRefStars(self.refCat, matchCut, 'refFlux_instFlux', 0.1)
90 measStars, refStars = ccdImage.countStars()
91 self.assertEqual(measStars, nStars)
92 self.assertEqual(refStars, nStars)
94 def testCcdImage1(self):
95 self.checkCountStars(self.ccdImage1, self.nStars1)
97 def testCcdImage2(self):
98 self.checkCountStars(self.ccdImage2, self.nStars2)
101class MemoryTester(lsst.utils.tests.MemoryTestCase):
102 pass
105def setup_module(module):
106 lsst.utils.tests.init()
109if __name__ == "__main__": 109 ↛ 110line 109 didn't jump to line 110, because the condition on line 109 was never true
110 lsst.utils.tests.init()
111 unittest.main()