Coverage for tests/test_denormalizeMatches.py: 23%
42 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-09 02:31 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-09 02:31 -0700
1# This file is part of meas_astrom.
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 sys
23import unittest
25import lsst.afw.table
27from lsst.geom import degrees
28from lsst.meas.astrom import denormalizeMatches
31class DenormalizeMatchesTestCase(unittest.TestCase):
32 """Test the behaviour of the denormalizedMatches function"""
34 def checkDenormalizeMatches(self, refType, srcType, MatchClass, num=10):
35 """Check that denormalizeMatches works
37 We create reference and source catalogs, generate matches,
38 run denormalizeMatches and verify that the results are as
39 expected (this includes checking that alias maps from the
40 input catalogs are propagated to the "match" catalog).
42 Parameters
43 ----------
44 refType : `str`
45 Type of reference catalog/table; "Simple" or "Source".
46 srcType : `str`
47 Type of source catalog/table; "Simple" or "Source".
48 MatchClass : `type`
49 Class for match; should be suitable for the refType and srcType.
50 """
51 refSchema = getattr(lsst.afw.table, refType + "Table").makeMinimalSchema()
52 refCat = getattr(lsst.afw.table, refType + "Catalog")(refSchema)
53 for ii in range(num):
54 ref = refCat.addNew()
55 ref.set("id", ii)
57 srcSchema = getattr(lsst.afw.table, srcType + "Table").makeMinimalSchema()
58 aliasDict = dict(srcIdAlias="id", srcCoordAlias="coord")
59 for k, v in aliasDict.items(): # Add some aliases to srcSchema's aliasMap
60 srcSchema.getAliasMap().set(k, v)
62 srcCat = getattr(lsst.afw.table, srcType + "Catalog")(srcSchema)
63 for ii in range(2*num, num, -1):
64 src = srcCat.addNew()
65 src.set("id", ii)
66 src.set("coord_ra", 100.0*degrees) # Arbitrary numbers to avoid NANs for checking dereference
67 src.set("coord_dec", 1.0*degrees)
69 matches = [MatchClass(ref, src, ref.get("id")) for ref, src in zip(refCat, srcCat)]
70 catalog = denormalizeMatches(matches)
71 for row, ref, src in zip(catalog, refCat, srcCat):
72 self.assertEqual(row.get("ref_id"), ref.get("id"))
73 self.assertEqual(row.get("src_id"), src.get("id"))
74 self.assertEqual(row.get("distance"), ref.get("id"))
75 self.assertEqual(row.get("src_srcIdAlias"), row.get("src_id")) # intra-catalog check
76 self.assertEqual(row.get("src_srcIdAlias"), src.get("id")) # inter-catalog check
77 self.assertEqual(row.get("src_srcCoordAlias_ra"), src.get("coord_ra")) # inter-catalog check
78 self.assertEqual(row.get("src_srcCoordAlias_dec"), src.get("coord_dec")) # inter-catalog check
80 def testDenormalizeMatches(self):
81 """Test denormalizeMatches for various types"""
82 for args in (("Simple", "Simple", lsst.afw.table.SimpleMatch),
83 ("Simple", "Source", lsst.afw.table.ReferenceMatch),
84 ("Source", "Source", lsst.afw.table.SourceMatch),
85 ):
86 self.checkDenormalizeMatches(*args)
89class MemoryTester(lsst.utils.tests.MemoryTestCase):
90 pass
93def setup_module(module):
94 lsst.utils.tests.init()
97if __name__ == "__main__": 97 ↛ 98line 97 didn't jump to line 98, because the condition on line 97 was never true
98 setup_module(sys.modules[__name__])
99 unittest.main()