Coverage for tests/test_directMatch.py: 34%

54 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2023-03-12 10:15 +0000

1 

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# 

23 

24import os 

25import sys 

26import unittest 

27 

28import numpy as np 

29 

30import lsst.utils.tests 

31import lsst.meas.astrom 

32import lsst.geom 

33 

34from lsst.daf.persistence import Butler 

35from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask 

36 

37RefCatDir = os.path.join(os.path.dirname(__file__), "data", "sdssrefcat") 

38 

39 

40class DirectMatchTestCase(lsst.utils.tests.TestCase): 

41 """Tests for lsst.meas.astrom.DirectMatchTask""" 

42 

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 

51 

52 def tearDown(self): 

53 del self.butler 

54 del self.references 

55 

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) 

61 

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 

67 

68 self.assertIsNotNone(results.matchMeta) 

69 names = results.matchMeta.names() 

70 for key in ("RA", "DEC", "RADIUS", "SMATCHV", "FILTER"): 

71 self.assertIn(key, names) 

72 

73 def testWithoutNoise(self): 

74 """Match the reference catalog against itself""" 

75 self.checkMatching(self.references) 

76 

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) 

87 

88 

89class DirectMatchMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

90 pass 

91 

92 

93def setup_module(module): 

94 lsst.utils.tests.init() 

95 

96 

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()