Coverage for tests/test_joinMatchListWithCatalog.py: 30%

72 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-08-20 02:12 -0700

1# 

2# LSST Data Management System 

3# 

4# Copyright 2008-2015 AURA/LSST. 

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 <https://www.lsstcorp.org/LegalNotices/>. 

22# 

23 

24import os 

25import unittest 

26import logging 

27import glob 

28 

29import lsst.geom 

30from lsst.afw.image import ExposureF 

31from lsst.afw.table import packMatches, SourceCatalog 

32import lsst.utils.tests 

33from lsst.meas.algorithms.testUtils import MockReferenceObjectLoaderFromFiles 

34from lsst.meas.astrom import AstrometryTask 

35 

36 

37class JoinMatchListWithCatalogTestCase(unittest.TestCase): 

38 

39 def setUp(self): 

40 # Load sample input from disk 

41 testDir = os.path.dirname(__file__) 

42 

43 self.srcSet = SourceCatalog.readFits(os.path.join(testDir, "v695833-e0-c000.xy.fits")) 

44 

45 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2048, 4612)) # approximate 

46 # create an exposure with the right metadata; the closest thing we have is 

47 # apparently v695833-e0-c000-a00.sci.fits, which is much too small 

48 smallExposure = ExposureF(os.path.join(testDir, "v695833-e0-c000-a00.sci.fits")) 

49 self.exposure = ExposureF(self.bbox) 

50 self.exposure.setWcs(smallExposure.getWcs()) 

51 self.exposure.setFilter(smallExposure.getFilter()) 

52 # copy the pixels we can, in case the user wants a debug display 

53 mi = self.exposure.getMaskedImage() 

54 mi.assign(smallExposure.getMaskedImage(), smallExposure.getBBox()) 

55 

56 logLevel = logging.INFO 

57 refCatDir = os.path.join(testDir, "data", "sdssrefcat") 

58 filenames = sorted(glob.glob(os.path.join(refCatDir, 'ref_cats', 'cal_ref_cat', '??????.fits'))) 

59 refObjLoader = MockReferenceObjectLoaderFromFiles(filenames, htmLevel=8) 

60 astrometryConfig = AstrometryTask.ConfigClass() 

61 self.astrom = AstrometryTask(config=astrometryConfig, refObjLoader=refObjLoader) 

62 self.astrom.log.setLevel(logLevel) 

63 # Since our sourceSelector is a registry object we have to wait for it to be created 

64 # before setting default values. 

65 self.astrom.sourceSelector.config.minSnr = 0 

66 

67 def tearDown(self): 

68 del self.srcSet 

69 del self.bbox 

70 del self.exposure 

71 del self.astrom 

72 

73 def getAstrometrySolution(self): 

74 return self.astrom.solve(exposure=self.exposure, sourceCat=self.srcSet) 

75 

76 def testJoin(self): 

77 res = self.getAstrometrySolution() 

78 

79 matches = res.matches 

80 matchmeta = res.matchMeta 

81 

82 normalized = packMatches(matches) 

83 normalized.table.setMetadata(matchmeta) 

84 

85 matches2 = self.astrom.refObjLoader.joinMatchListWithCatalog(normalized, self.srcSet) 

86 

87 self.assertEqual(len(matches2), len(matches)) 

88 for i in range(len(matches)): 

89 self.assertEqual(matches2[i].second.table, matches[i].second.table) 

90 self.assertEqual(matches2[i].second.getId(), matches[i].second.getId()) 

91 self.assertEqual(matches2[i].second, matches[i].second) # no deep copying, so we can compare ptrs 

92 self.assertEqual(matches2[i].first.getId(), matches[i].first.getId()) 

93 self.assertEqual(matches2[i].first.getRa().asDegrees(), matches[i].first.getRa().asDegrees()) 

94 self.assertEqual(matches2[i].first.getDec().asDegrees(), matches[i].first.getDec().asDegrees()) 

95 self.assertEqual(matches2[i].first.get("i_flux"), matches[i].first.get("i_flux")) 

96 

97 def testJoinAllFluxes(self): 

98 """Test that we can read all the fluxes from a reference catalog""" 

99 res = self.getAstrometrySolution() 

100 

101 matches = res.matches 

102 matchmeta = res.matchMeta 

103 

104 normalized = packMatches(matches) 

105 normalized.table.setMetadata(matchmeta) 

106 

107 matches2 = self.astrom.refObjLoader.joinMatchListWithCatalog(normalized, self.srcSet) 

108 self.assertGreater(len(matches2), 0) 

109 ref = matches2[0][0] 

110 

111 refSchema = ref.getSchema() 

112 for b in ("u", "g", "r", "i", "z"): 

113 self.assertIn("%s_flux" % (b,), refSchema) 

114 self.assertIn("%s_fluxErr" % (b,), refSchema) 

115 

116 

117class MemoryTester(lsst.utils.tests.MemoryTestCase): 

118 pass 

119 

120 

121def setup_module(module): 

122 lsst.utils.tests.init() 

123 

124 

125if __name__ == "__main__": 125 ↛ 126line 125 didn't jump to line 126, because the condition on line 125 was never true

126 lsst.utils.tests.init() 

127 unittest.main()