Coverage for tests/test_directMatch.py: 34%
53 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-11 03:04 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-11 03:04 -0800
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
27import glob
29import numpy as np
31import lsst.utils.tests
32import lsst.meas.astrom
33import lsst.geom
35from lsst.meas.algorithms.testUtils import MockReferenceObjectLoaderFromFiles
38RefCatDir = os.path.join(os.path.dirname(__file__), "data", "sdssrefcat")
41class DirectMatchTestCase(lsst.utils.tests.TestCase):
42 """Tests for lsst.meas.astrom.DirectMatchTask"""
44 def setUp(self):
45 np.random.seed(12345)
46 filenames = sorted(glob.glob(os.path.join(RefCatDir, 'ref_cats', 'cal_ref_cat', '??????.fits')))
47 self.refObjLoader = MockReferenceObjectLoaderFromFiles(filenames, htmLevel=8)
48 center = lsst.geom.SpherePoint(215.5, 53.0, lsst.geom.degrees)
49 radius = 0.5*lsst.geom.degrees
50 self.filter = "r"
51 self.references = self.refObjLoader.loadSkyCircle(center, radius, self.filter).refCat
53 def tearDown(self):
54 del self.refObjLoader
55 del self.references
57 def checkMatching(self, catalog):
58 config = lsst.meas.astrom.DirectMatchConfig()
59 task = lsst.meas.astrom.DirectMatchTask(config=config, refObjLoader=self.refObjLoader)
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()