Coverage for tests/test_loadref_hsc.py: 18%

119 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-19 06:00 -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.getDeferred(ref) for ref in refs] 

98 

99 refConfig = LoadReferenceObjectsConfig() 

100 refConfig.filterMap = config.filterMap 

101 

102 refObjLoader = ReferenceObjectLoader(dataIds=dataIds, 

103 refCats=refCats, 

104 name=refCatName, 

105 config=refConfig) 

106 

107 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(refObjLoader=refObjLoader, 

108 refCatName=refCatName, 

109 config=config) 

110 

111 ra = 337.656174 

112 dec = 0.823595 

113 rad = 0.1 

114 

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

116 

117 # Check the number of mags and ranges 

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

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

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

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

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

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

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

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

126 self.assertGreater(test.size, 0) 

127 

128 # Check the separations from the center 

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

130 

131 # And load a healpixel 

132 nside = 256 

133 pixel = 387520 

134 

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

136 

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

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

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

140 

141 def test_fgcmLoadReferenceOtherFilters(self): 

142 """ 

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

144 """ 

145 

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

147 

148 config = fgcmcal.FgcmLoadReferenceCatalogConfig() 

149 config.applyColorTerms = True 

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

151 config.colorterms.data = {} 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

166 

167 refCatName = 'ps1_pv3_3pi_20170110' 

168 

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

170 'refcats/gen2']) 

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

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

173 refCats = [butler.getDeferred(ref) for ref in refs] 

174 

175 refConfig = LoadReferenceObjectsConfig() 

176 refConfig.filterMap = config.filterMap 

177 

178 refObjLoader = ReferenceObjectLoader(dataIds=dataIds, 

179 refCats=refCats, 

180 name=refCatName, 

181 config=refConfig) 

182 

183 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(refObjLoader=refObjLoader, 

184 refCatName=refCatName, 

185 config=config) 

186 

187 ra = 337.656174 

188 dec = 0.823595 

189 rad = 0.1 

190 

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

192 

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

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

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

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

197 self.assertGreater(test.size, 0) 

198 

199 

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

201 pass 

202 

203 

204def setup_module(module): 

205 lsst.utils.tests.init() 

206 

207 

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

209 lsst.utils.tests.init() 

210 unittest.main()