Coverage for tests/test_directMatch.py: 34%
Shortcuts 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
Shortcuts 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
2#
3# LSST Data Management System
4# Copyright 2008-2016 LSST Corporation.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <http://www.lsstcorp.org/LegalNotices/>.
22#
24import os
25import sys
26import unittest
28import numpy as np
30import lsst.utils.tests
31import lsst.meas.astrom
32import lsst.geom
34from lsst.daf.persistence import Butler
35from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask
37RefCatDir = os.path.join(os.path.dirname(__file__), "data", "sdssrefcat")
40class DirectMatchTestCase(lsst.utils.tests.TestCase):
41 """Tests for lsst.meas.astrom.DirectMatchTask"""
43 def setUp(self):
44 np.random.seed(12345)
45 self.butler = Butler(RefCatDir)
46 refObjLoader = LoadIndexedReferenceObjectsTask(butler=self.butler)
47 center = lsst.geom.SpherePoint(215.5, 53.0, lsst.geom.degrees)
48 radius = 0.5*lsst.geom.degrees
49 self.filter = "r"
50 self.references = refObjLoader.loadSkyCircle(center, radius, self.filter).refCat
52 def tearDown(self):
53 del self.butler
54 del self.references
56 def checkMatching(self, catalog):
57 config = lsst.meas.astrom.DirectMatchConfig()
58 config.refObjLoader.retarget(LoadIndexedReferenceObjectsTask)
59 task = lsst.meas.astrom.DirectMatchTask(config=config, butler=self.butler)
60 results = task.run(catalog, self.filter)
62 self.assertEqual(len(results.matches), len(catalog))
63 for match in results.matches:
64 self.assertEqual(match.first.getId(), match.second.getId())
65 maxDistance = max(match.distance for match in results.matches)
66 self.assertLess(maxDistance, config.matchRadius) # match.distance is in arcsec
68 self.assertIsNotNone(results.matchMeta)
69 names = results.matchMeta.names()
70 for key in ("RA", "DEC", "RADIUS", "SMATCHV", "FILTER"):
71 self.assertIn(key, names)
73 def testWithoutNoise(self):
74 """Match the reference catalog against itself"""
75 self.checkMatching(self.references)
77 def testWithNoise(self):
78 """Match the reference catalog against a noised version of itself"""
79 references = self.references.copy(True)
80 offset = (0.1*lsst.geom.arcseconds).asRadians()
81 num = len(references)
82 ra, dec = references["coord_ra"], references["coord_dec"]
83 cosDec = np.cos(dec.mean())
84 ra += offset/cosDec*np.random.uniform(-1.0, 1.0, num)
85 dec += offset*np.random.uniform(-1.0, 1.0, num)
86 self.checkMatching(references)
89class DirectMatchMemoryTestCase(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()