Coverage for tests/test_loadref_hsc.py: 20%

119 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-24 02:49 -0700

1# See COPYRIGHT file at the top of the source tree. 

2# 

3# This file is part of fgcmcal. 

4# 

5# Developed for the LSST Data Management System. 

6# This product includes software developed by the LSST Project 

7# (https://www.lsst.org). 

8# See the COPYRIGHT file at the top-level directory of this distribution 

9# for details of code ownership. 

10# 

11# This program is free software: you can redistribute it and/or modify 

12# it under the terms of the GNU General Public License as published by 

13# the Free Software Foundation, either version 3 of the License, or 

14# (at your option) any later version. 

15# 

16# This program is distributed in the hope that it will be useful, 

17# but WITHOUT ANY WARRANTY; without even the implied warranty of 

18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19# GNU General Public License for more details. 

20# 

21# You should have received a copy of the GNU General Public License 

22# along with this program. If not, see <https://www.gnu.org/licenses/>. 

23"""Test the fgcmcal fgcmLoadReferenceCatalog code with testdata_jointcal/hsc. 

24 

25""" 

26 

27import unittest 

28import os 

29import numpy as np 

30import hpgeom as hpg 

31import esutil 

32import tempfile 

33 

34import lsst.utils 

35import lsst.pipe.tasks 

36from lsst.meas.algorithms import ReferenceObjectLoader, LoadReferenceObjectsConfig 

37 

38import lsst.fgcmcal as fgcmcal 

39 

40import fgcmcalTestBase 

41 

42ROOT = os.path.abspath(os.path.dirname(__file__)) 

43 

44 

45class FgcmLoadReferenceTestHSC(fgcmcalTestBase.FgcmcalTestBase, lsst.utils.tests.TestCase): 

46 @classmethod 

47 def setUpClass(cls): 

48 try: 

49 cls.dataDir = lsst.utils.getPackageDir('testdata_jointcal') 

50 except LookupError: 

51 raise unittest.SkipTest("testdata_jointcal not setup") 

52 try: 

53 lsst.utils.getPackageDir('obs_subaru') 

54 except LookupError: 

55 raise unittest.SkipTest("obs_subaru not setup") 

56 

57 lsst.daf.butler.cli.cliLog.CliLog.initLog(longlog=False) 

58 

59 cls.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-") 

60 

61 cls._importRepository('lsst.obs.subaru.HyperSuprimeCam', 

62 os.path.join(cls.dataDir, 'hsc/repo'), 

63 os.path.join(cls.dataDir, 'hsc', 'exports.yaml')) 

64 

65 def test_fgcmLoadReference(self): 

66 """ 

67 Test loading of the fgcm reference catalogs. 

68 """ 

69 

70 filterList = ['HSC-R', 'HSC-I'] 

71 

72 config = fgcmcal.FgcmLoadReferenceCatalogConfig() 

73 config.applyColorTerms = True 

74 config.filterMap = {'HSC-R': 'r', 'HSC-I': 'i'} 

75 config.colorterms.data = {} 

76 config.colorterms.data['ps1*'] = lsst.pipe.tasks.colorterms.ColortermDict() 

77 config.colorterms.data['ps1*'].data = {} 

78 config.colorterms.data['ps1*'].data['HSC-R'] = lsst.pipe.tasks.colorterms.Colorterm() 

79 config.colorterms.data['ps1*'].data['HSC-R'].primary = 'r' 

80 config.colorterms.data['ps1*'].data['HSC-R'].secondary = 'i' 

81 config.colorterms.data['ps1*'].data['HSC-R'].c0 = -0.000144 

82 config.colorterms.data['ps1*'].data['HSC-R'].c1 = 0.001369 

83 config.colorterms.data['ps1*'].data['HSC-R'].c2 = -0.008380 

84 config.colorterms.data['ps1*'].data['HSC-I'] = lsst.pipe.tasks.colorterms.Colorterm() 

85 config.colorterms.data['ps1*'].data['HSC-I'].primary = 'i' 

86 config.colorterms.data['ps1*'].data['HSC-I'].secondary = 'z' 

87 config.colorterms.data['ps1*'].data['HSC-I'].c0 = 0.000643 

88 config.colorterms.data['ps1*'].data['HSC-I'].c1 = -0.130078 

89 config.colorterms.data['ps1*'].data['HSC-I'].c2 = -0.006855 

90 

91 refCatName = 'ps1_pv3_3pi_20170110' 

92 

93 butler = lsst.daf.butler.Butler(self.repo, instrument='HSC', collections=['HSC/testdata', 

94 'refcats/gen2']) 

95 refs = set(butler.registry.queryDatasets(refCatName)) 

96 dataIds = [butler.registry.expandDataId(ref.dataId) for ref in refs] 

97 refCats = [butler.getDirectDeferred(ref) for ref in refs] 

98 

99 refConfig = LoadReferenceObjectsConfig() 

100 refConfig.filterMap = config.filterMap 

101 

102 refObjLoader = ReferenceObjectLoader(dataIds=dataIds, refCats=refCats, config=refConfig) 

103 

104 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(refObjLoader=refObjLoader, 

105 refCatName=refCatName, 

106 config=config) 

107 

108 ra = 337.656174 

109 dec = 0.823595 

110 rad = 0.1 

111 

112 refCat = loadCat.getFgcmReferenceStarsSkyCircle(ra, dec, rad, filterList) 

113 

114 # Check the number of mags and ranges 

115 self.assertEqual(len(filterList), refCat['refMag'].shape[1]) 

116 self.assertEqual(len(filterList), refCat['refMagErr'].shape[1]) 

117 self.assertLess(np.max(refCat['refMag'][:, 0]), 99.1) 

118 self.assertLess(np.max(refCat['refMag'][:, 1]), 99.1) 

119 self.assertLess(np.max(refCat['refMagErr'][:, 0]), 99.1) 

120 self.assertLess(np.max(refCat['refMagErr'][:, 1]), 99.1) 

121 test, = np.where((refCat['refMag'][:, 0] < 30.0) 

122 & (refCat['refMag'][:, 1] < 30.0)) 

123 self.assertGreater(test.size, 0) 

124 

125 # Check the separations from the center 

126 self.assertLess(np.max(esutil.coords.sphdist(ra, dec, refCat['ra'], refCat['dec'])), rad) 

127 

128 # And load a healpixel 

129 nside = 256 

130 pixel = 387520 

131 

132 refCat = loadCat.getFgcmReferenceStarsHealpix(nside, pixel, filterList) 

133 

134 ipring = hpg.angle_to_pixel(nside, refCat['ra'], refCat['dec'], nest=False) 

135 self.assertEqual(pixel, np.max(ipring)) 

136 self.assertEqual(pixel, np.min(ipring)) 

137 

138 def test_fgcmLoadReferenceOtherFilters(self): 

139 """ 

140 Test loading of the fgcm reference catalogs using unmatched filter names. 

141 """ 

142 

143 filterList = ['HSC-R2', 'HSC-I2'] 

144 

145 config = fgcmcal.FgcmLoadReferenceCatalogConfig() 

146 config.applyColorTerms = True 

147 config.filterMap = {'HSC-R2': 'r', 'HSC-I2': 'i'} 

148 config.colorterms.data = {} 

149 config.colorterms.data['ps1*'] = lsst.pipe.tasks.colorterms.ColortermDict() 

150 config.colorterms.data['ps1*'].data = {} 

151 config.colorterms.data['ps1*'].data['HSC-R2'] = lsst.pipe.tasks.colorterms.Colorterm() 

152 config.colorterms.data['ps1*'].data['HSC-R2'].primary = 'r' 

153 config.colorterms.data['ps1*'].data['HSC-R2'].secondary = 'i' 

154 config.colorterms.data['ps1*'].data['HSC-R2'].c0 = -0.000032 

155 config.colorterms.data['ps1*'].data['HSC-R2'].c1 = -0.002866 

156 config.colorterms.data['ps1*'].data['HSC-R2'].c2 = -0.012638 

157 config.colorterms.data['ps1*'].data['HSC-I2'] = lsst.pipe.tasks.colorterms.Colorterm() 

158 config.colorterms.data['ps1*'].data['HSC-I2'].primary = 'i' 

159 config.colorterms.data['ps1*'].data['HSC-I2'].secondary = 'z' 

160 config.colorterms.data['ps1*'].data['HSC-I2'].c0 = 0.001625 

161 config.colorterms.data['ps1*'].data['HSC-I2'].c1 = -0.200406 

162 config.colorterms.data['ps1*'].data['HSC-I2'].c2 = -0.013666 

163 

164 refCatName = 'ps1_pv3_3pi_20170110' 

165 

166 butler = lsst.daf.butler.Butler(self.repo, instrument='HSC', collections=['HSC/testdata', 

167 'refcats/gen2']) 

168 refs = set(butler.registry.queryDatasets(refCatName)) 

169 dataIds = [butler.registry.expandDataId(ref.dataId) for ref in refs] 

170 refCats = [butler.getDirectDeferred(ref) for ref in refs] 

171 

172 refConfig = LoadReferenceObjectsConfig() 

173 refConfig.filterMap = config.filterMap 

174 

175 refObjLoader = ReferenceObjectLoader(dataIds=dataIds, refCats=refCats, config=refConfig) 

176 

177 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(refObjLoader=refObjLoader, 

178 refCatName=refCatName, 

179 config=config) 

180 

181 ra = 337.656174 

182 dec = 0.823595 

183 rad = 0.1 

184 

185 refCat = loadCat.getFgcmReferenceStarsSkyCircle(ra, dec, rad, filterList) 

186 

187 self.assertEqual(len(filterList), refCat['refMag'].shape[1]) 

188 self.assertEqual(len(filterList), refCat['refMagErr'].shape[1]) 

189 test, = np.where((refCat['refMag'][:, 0] < 30.0) 

190 & (refCat['refMag'][:, 1] < 30.0)) 

191 self.assertGreater(test.size, 0) 

192 

193 

194class TestMemory(lsst.utils.tests.MemoryTestCase): 

195 pass 

196 

197 

198def setup_module(module): 

199 lsst.utils.tests.init() 

200 

201 

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

203 lsst.utils.tests.init() 

204 unittest.main()