Coverage for tests/test_ccdImage.py: 38%
49 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-26 12:38 +0000
« prev ^ index » next coverage.py v6.4, created at 2022-05-26 12:38 +0000
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
30import lsst.obs.base
33class CcdImageTestCase(lsst.utils.tests.TestCase):
34 def setUp(self):
35 self.nStars1 = 4
36 self.nStars2 = 100
37 # Ensure that the filter list is reset for each test so that we avoid
38 # confusion or contamination each time we create a cfht camera below.
39 lsst.obs.base.FilterDefinitionCollection.reset()
40 struct = testUtils.createTwoFakeCcdImages(num1=self.nStars1, num2=self.nStars2)
41 self.ccdImage1 = struct.ccdImageList[0]
42 self.ccdImage2 = struct.ccdImageList[1]
43 self.bbox = struct.bbox
45 self.associations = lsst.jointcal.Associations(struct.ccdImageList)
47 def checkCountStars(self, ccdImage, nStars):
48 """Check that ccdImage.countStars() is correct under various conditions.
50 Parameters
51 ----------
52 ccdImage : `lsst.jointcal.CcdImage`
53 The ccdImage to test.
54 nStars : `int`
55 Number of stars in ccdImage's catalog.
57 Notes
58 -----
59 Does not test the case where some ``measuredStars`` are not ``valid``,
60 as there is no interface for modifying that the python level. To test
61 that would require creating a `Fitter` and a fake outlier list and
62 calling ``removeMeasOutliers`` and/or ``removeRefOutliers``, which
63 cannot be easily made part of the python API.
64 """
65 # By default there are no stars because catalogForFit is uninitialized.
66 measStars, refStars = ccdImage.countStars()
67 self.assertEqual(measStars, 0)
68 self.assertEqual(refStars, 0)
70 # With no associations, the catalog should have exactly as many valid
71 # measuredStars as were created.
72 ccdImage.resetCatalogForFit()
73 measStars, refStars = ccdImage.countStars()
74 self.assertEqual(measStars, nStars)
75 self.assertEqual(refStars, 0)
77 # Cross match catalogs: there will still be no refcat matches.
78 matchCut = 3.0 * lsst.geom.arcseconds
79 # There should be no fittedStars until we associate the catalogs.
80 self.assertEqual(self.associations.fittedStarListSize(), 0)
81 self.associations.computeCommonTangentPoint()
82 self.associations.associateCatalogs(matchCut)
83 # Confirm that every measuredStar (in both ccdImages) got a fittedStar associated to it.
84 self.assertEqual(self.associations.fittedStarListSize(), self.nStars1 + self.nStars2)
85 # measuredStars and refStars should be unchanged after association.
86 self.assertEqual(measStars, nStars)
87 self.assertEqual(refStars, 0)
89 # Make a fake reference catalog; will match the catalog one-to-one.
90 skyWcs = ccdImage.getReadWcs().getSkyWcs()
91 self.refCat = testUtils.createFakeCatalog(nStars, self.bbox, "refFlux", skyWcs=skyWcs, refCat=True)
92 # associate the reference stars
93 self.associations.collectRefStars(self.refCat, matchCut, 'refFlux_instFlux', 0.1)
94 measStars, refStars = ccdImage.countStars()
95 self.assertEqual(measStars, nStars)
96 self.assertEqual(refStars, nStars)
98 def testCcdImage1(self):
99 self.checkCountStars(self.ccdImage1, self.nStars1)
101 def testCcdImage2(self):
102 self.checkCountStars(self.ccdImage2, self.nStars2)
105class MemoryTester(lsst.utils.tests.MemoryTestCase):
106 pass
109def setup_module(module):
110 lsst.utils.tests.init()
113if __name__ == "__main__": 113 ↛ 114line 113 didn't jump to line 114, because the condition on line 113 was never true
114 lsst.utils.tests.init()
115 unittest.main()