Coverage for tests/test_directMatch.py: 34%

53 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-23 03:24 -0800

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 

27import glob 

28 

29import numpy as np 

30 

31import lsst.utils.tests 

32import lsst.meas.astrom 

33import lsst.geom 

34 

35from lsst.meas.algorithms.testUtils import MockReferenceObjectLoaderFromFiles 

36 

37 

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

39 

40 

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

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

43 

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 

52 

53 def tearDown(self): 

54 del self.refObjLoader 

55 del self.references 

56 

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) 

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