Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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 healpy as hp 

31import esutil 

32 

33import lsst.utils 

34import lsst.pipe.tasks 

35import lsst.daf.persistence as dafPersist 

36 

37import lsst.fgcmcal as fgcmcal 

38 

39 

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

41 @classmethod 

42 def setUpClass(cls): 

43 try: 

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

45 except LookupError: 

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

47 try: 

48 lsst.utils.getPackageDir('obs_subaru') 

49 except LookupError: 

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

51 

52 def setUp(self): 

53 self.inputDir = os.path.join(self.dataDir, 'hsc') 

54 

55 lsst.log.setLevel("HscMapper", lsst.log.FATAL) 

56 

57 def test_fgcmLoadReference(self): 

58 """ 

59 Test loading of the fgcm reference catalogs. 

60 """ 

61 

62 filterList = ['r', 'i'] 

63 

64 config = fgcmcal.FgcmLoadReferenceCatalogConfig() 

65 config.applyColorTerms = True 

66 config.refObjLoader.ref_dataset_name = 'ps1_pv3_3pi_20170110' 

67 config.refFilterMap = {'r': 'r', 'i': 'i'} 

68 config.colorterms.data = {} 

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

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

71 config.colorterms.data['ps1*'].data['r'] = lsst.pipe.tasks.colorterms.Colorterm() 

72 config.colorterms.data['ps1*'].data['r'].primary = 'r' 

73 config.colorterms.data['ps1*'].data['r'].secondary = 'i' 

74 config.colorterms.data['ps1*'].data['r'].c0 = -0.000144 

75 config.colorterms.data['ps1*'].data['r'].c1 = 0.001369 

76 config.colorterms.data['ps1*'].data['r'].c2 = -0.008380 

77 config.colorterms.data['ps1*'].data['i'] = lsst.pipe.tasks.colorterms.Colorterm() 

78 config.colorterms.data['ps1*'].data['i'].primary = 'i' 

79 config.colorterms.data['ps1*'].data['i'].secondary = 'z' 

80 config.colorterms.data['ps1*'].data['i'].c0 = 0.000643 

81 config.colorterms.data['ps1*'].data['i'].c1 = -0.130078 

82 config.colorterms.data['ps1*'].data['i'].c2 = -0.006855 

83 

84 butler = dafPersist.Butler(self.inputDir) 

85 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(butler=butler, config=config) 

86 

87 ra = 337.656174 

88 dec = 0.823595 

89 rad = 0.1 

90 

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

92 

93 # Check the number of mags and ranges 

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

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

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

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

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

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

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

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

102 self.assertGreater(test.size, 0) 

103 

104 # Check the separations from the center 

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

106 

107 # And load a healpixel 

108 nside = 256 

109 pixel = 387520 

110 

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

112 

113 ipring = hp.ang2pix(nside, np.radians(90.0 - refCat['dec']), np.radians(refCat['ra'])) 

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

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

116 

117 def test_fgcmLoadReferenceOtherFilters(self): 

118 """ 

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

120 """ 

121 

122 filterList = ['r2', 'i2'] 

123 

124 config = fgcmcal.FgcmLoadReferenceCatalogConfig() 

125 config.applyColorTerms = True 

126 config.refObjLoader.ref_dataset_name = 'ps1_pv3_3pi_20170110' 

127 config.refFilterMap = {'r2': 'r', 'i2': 'i'} 

128 config.colorterms.data = {} 

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

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

131 config.colorterms.data['ps1*'].data['r2'] = lsst.pipe.tasks.colorterms.Colorterm() 

132 config.colorterms.data['ps1*'].data['r2'].primary = 'r' 

133 config.colorterms.data['ps1*'].data['r2'].secondary = 'i' 

134 config.colorterms.data['ps1*'].data['r2'].c0 = -0.000032 

135 config.colorterms.data['ps1*'].data['r2'].c1 = -0.002866 

136 config.colorterms.data['ps1*'].data['r2'].c2 = -0.012638 

137 config.colorterms.data['ps1*'].data['i2'] = lsst.pipe.tasks.colorterms.Colorterm() 

138 config.colorterms.data['ps1*'].data['i2'].primary = 'i' 

139 config.colorterms.data['ps1*'].data['i2'].secondary = 'z' 

140 config.colorterms.data['ps1*'].data['i2'].c0 = 0.001625 

141 config.colorterms.data['ps1*'].data['i2'].c1 = -0.200406 

142 config.colorterms.data['ps1*'].data['i2'].c2 = -0.013666 

143 

144 butler = dafPersist.Butler(self.inputDir) 

145 loadCat = fgcmcal.FgcmLoadReferenceCatalogTask(butler=butler, config=config) 

146 

147 ra = 337.656174 

148 dec = 0.823595 

149 rad = 0.1 

150 

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

152 

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

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

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

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

157 self.assertGreater(test.size, 0) 

158 

159 

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

161 pass 

162 

163 

164def setup_module(module): 

165 lsst.utils.tests.init() 

166 

167 

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

169 lsst.utils.tests.init() 

170 unittest.main()