Skip to content

Commit

Permalink
Add test for denormalizeMatches alias propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenam committed Oct 4, 2018
1 parent 602ad75 commit fb67193
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/test_denormalizeMatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lsst.afw.geom
import lsst.afw.table

from lsst.geom import degrees
from lsst.meas.astrom import denormalizeMatches


Expand All @@ -35,7 +36,9 @@ def checkDenormalizeMatches(self, refType, srcType, MatchClass, num=10):
"""Check that denormalizeMatches works
We create reference and source catalogs, generate matches,
run denormalizeMatches and verify that the results are as expected.
run denormalizeMatches and verify that the results are as
expected (this includes checking that alias maps from the
input catalogs are propagated to the "match" catalog).
Parameters
----------
Expand All @@ -53,17 +56,27 @@ def checkDenormalizeMatches(self, refType, srcType, MatchClass, num=10):
ref.set("id", ii)

srcSchema = getattr(lsst.afw.table, srcType + "Table").makeMinimalSchema()
aliasDict = dict(srcIdAlias="id", srcCoordAlias="coord")
for k, v in aliasDict.items(): # Add some aliases to srcSchema's aliasMap
srcSchema.getAliasMap().set(k, v)

srcCat = getattr(lsst.afw.table, srcType + "Catalog")(srcSchema)
for ii in range(2*num, num, -1):
src = srcCat.addNew()
src.set("id", ii)
src.set("coord_ra", 100.0*degrees) # Arbitrary numbers to avoid NANs for checking dereference
src.set("coord_dec", 1.0*degrees)

matches = [MatchClass(ref, src, ref.get("id")) for ref, src in zip(refCat, srcCat)]
catalog = denormalizeMatches(matches)
for row, ref, src in zip(catalog, refCat, srcCat):
self.assertEqual(row.get("ref_id"), ref.get("id"))
self.assertEqual(row.get("src_id"), src.get("id"))
self.assertEqual(row.get("distance"), ref.get("id"))
self.assertEqual(row.get("src_srcIdAlias"), row.get("src_id")) # intra-catalog check
self.assertEqual(row.get("src_srcIdAlias"), src.get("id")) # inter-catalog check
self.assertEqual(row.get("src_srcCoordAlias_ra"), src.get("coord_ra")) # inter-catalog check
self.assertEqual(row.get("src_srcCoordAlias_dec"), src.get("coord_dec")) # inter-catalog check

def testDenormalizeMatches(self):
"""Test denormalizeMatches for various types"""
Expand Down

0 comments on commit fb67193

Please sign in to comment.