Coverage for tests/test_sourceMatch.py : 68%
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
|
# # LSST Data Management System # Copyright 2008-2016 AURA/LSST. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <https://www.lsstcorp.org/LegalNotices/>. #
Tests for matching SourceSets
Run with: python SourceMatch.py or python >>> import SourceMatch; SourceMatch.run() """
"""A test case for matching SourceSets """
(10 + 0.001*i) * lsst.geom.degrees) (10 + 0.001*i) * lsst.geom.degrees)
# Give slight offsets for Coord testing of matches to/from catalog in checkMatchToFromCatalog() # Chosen such that the maximum offset (nobj*1E-7 deg = 0.36 arcsec) is within the maximum # distance (1 arcsec) in afwTable.matchRaDec. (10 + 0.0010001*i) * lsst.geom.degrees) (10 + 0.0010001*i) * lsst.geom.degrees)
self.ss1, self.ss2, 1.0*lsst.geom.arcseconds, mc)
s0 = mat[0][0] s1 = mat[0][1] print(s0.getRa(), s1.getRa(), s0.getId(), s1.getId())
float('nan') * lsst.geom.radians)
float('nan') * lsst.geom.radians)
0.0 * lsst.geom.radians) 0.0 * lsst.geom.radians)
float('nan') * lsst.geom.radians) float('nan') * lsst.geom.radians)
def testPhotometricCalib(self): """Test matching the CFHT catalogue (as generated using LSST code) to the SDSS catalogue """
band = 2 # SDSS r
# Read SDSS catalogue with open(os.path.join(afwdataDir, "CFHT", "D2", "sdss.dat"), "r") as ifd:
sdss = afwTable.SourceCatalog(self.table) sdssSecondary = afwTable.SourceCatalog(self.table)
PRIMARY, SECONDARY = 1, 2 # values of mode
id = 0 for line in ifd.readlines(): if re.search(r"^\s*#", line): continue
fields = line.split() objId = int(fields[0]) fields[1] mode = int(fields[2]) ra, dec = [float(f) for f in fields[3:5]] psfMags = [float(f) for f in fields[5:]]
if mode == PRIMARY: s = sdss.addNew() elif SECONDARY: s = sdssSecondary.addNew()
s.setId(objId) s.setRa(ra * lsst.geom.degrees) s.setDec(dec * lsst.geom.degrees) s.set(self.table.getPsfFluxKey(), psfMags[band])
del ifd
# Read catalalogue built from the template image # Read SDSS catalogue with open(os.path.join(afwdataDir, "CFHT", "D2", "template.dat"), "r") as ifd:
template = afwTable.SourceCatalog(self.table)
id = 0 for line in ifd.readlines(): if re.search(r"^\s*#", line): continue
fields = line.split() id, flags = [int(f) for f in fields[0:2]] ra, dec = [float(f) for f in fields[2:4]] flux = [float(f) for f in fields[4:]]
if flags & 0x1: # EDGE continue
s = template.addNew() s.setId(id) id += 1 s.set(afwTable.SourceTable.getCoordKey().getRa(), ra * lsst.geom.degrees) s.set(afwTable.SourceTable.getCoordKey().getDec(), dec * lsst.geom.degrees) s.set(self.table.getPsfFluxKey(), flux[0])
del ifd
# Actually do the match mc = afwTable.MatchControl() mc.findOnlyClosest = False
matches = afwTable.matchRaDec( sdss, template, 1.0*lsst.geom.arcseconds, mc)
self.assertEqual(len(matches), 901)
if False: for mat in matches: s0 = mat[0] s1 = mat[1] d = mat[2] print(s0.getRa(), s0.getDec(), s1.getRa(), s1.getDec(), s0.getPsfFlux(), s1.getPsfFlux())
# Actually do the match for s in sdssSecondary: sdss.append(s)
mc = afwTable.MatchControl() mc.symmetricMatch = False matches = afwTable.matchRaDec(sdss, 1.0*lsst.geom.arcseconds, mc) nmiss = 1 # one object doesn't match self.assertEqual(len(matches), len(sdssSecondary) - nmiss)
# Find the one that didn't match if False: matchIds = set() for s0, s1, d in matches: matchIds.add(s0.getId()) matchIds.add(s1.getId())
for s in sdssSecondary: if s.getId() not in matchIds: print("RHL", s.getId())
matches = afwTable.matchRaDec(sdss, 1.0*lsst.geom.arcseconds) self.assertEqual(len(matches), 2*(len(sdssSecondary) - nmiss))
if False: for mat in matches: s0 = mat[0] s1 = mat[1] mat[2] print(s0.getId(), s1.getId(), s0.getRa(), s0.getDec(), end=' ') print(s1.getRa(), s1.getDec(), s0.getPsfFlux(), s1.getPsfFlux())
""" Chech that matchRaDec works as expected when using the includeMismatches option """ (10 + 0.0001*i) * lsst.geom.degrees) (10.005 + 0.0001*i) * lsst.geom.degrees) (10 + 0.0001*i) * lsst.geom.degrees) (10.005 + 0.0001*i) * lsst.geom.degrees)
cat1, cat2, 1.0*lsst.geom.arcseconds, mc) cat1, cat2, 1.0*lsst.geom.arcseconds, mc)
else: catMatches, cat2, 1.0*lsst.geom.arcseconds, mc) catMismatches, cat2, 1.0*lsst.geom.arcseconds, mc)
"""Check the conversion of matches to and from a catalog
Test the functions in lsst.afw.table.catalogMatches.py Note that the return types and schemas of these functions do not necessarily match those of the catalogs passed to them, so value entries are compared as opposed to comparing the attributes as a whole. """ matches, matchMeta)
(catM["ref_coord_ra"], catM["ref_coord_dec"])) (catM["src_coord_ra"], catM["src_coord_dec"]))
"""Compare floating point values, allowing for NAN """ self.assertTrue(value1 == value2 or (np.isnan(value1) and np.isnan(value2)))
"""Test for precision of the calculated distance
Check that the distance produced by matchRaDec is the same as the distance produced from calculating the separation between the matched coordinates.
Based on DM-13891. """
src1.getCoord().offset(rng.uniform(high=360)*lsst.geom.degrees, rng.uniform(high=radius.asArcseconds())*lsst.geom.arcseconds))
for mm in matches])
lsst.utils.tests.init() unittest.main() |