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 code with testdata_jointcal/hsc. 

24 

25Run test suite on fgcmcal using Gen2 HSC data from testdata_jointcal. 

26""" 

27import unittest 

28import os 

29import copy 

30import tempfile 

31import numpy as np 

32 

33import matplotlib 

34matplotlib.use("Agg") 

35 

36import lsst.utils # noqa: E402 

37import lsst.pipe.tasks # noqa: E402 

38 

39import fgcmcalTestBaseGen2 # noqa: E402 

40 

41import lsst.fgcmcal as fgcmcal # noqa: E402 

42 

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

44 

45 

46class FgcmcalTestHSCGen2(fgcmcalTestBaseGen2.FgcmcalTestBaseGen2, lsst.utils.tests.TestCase): 

47 @classmethod 

48 def setUpClass(cls): 

49 try: 

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

51 except LookupError: 

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

53 try: 

54 lsst.utils.getPackageDir('obs_subaru') 

55 except LookupError: 

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

57 

58 def setUp(self): 

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

60 

61 self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-") 

62 

63 self.setUp_base(inputDir=inputDir, testDir=self.testDir) 

64 

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

66 

67 def test_fgcmcalTasks(self): 

68 # Set numpy seed for stability 

69 np.random.seed(seed=1000) 

70 

71 visitDataRefName = 'visit' 

72 ccdDataRefName = 'ccd' 

73 

74 # First test making the LUT 

75 self.config = fgcmcal.FgcmMakeLutConfig() 

76 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py') 

77 self.configfiles = [testConfigFile] 

78 

79 self.otherArgs = [] 

80 

81 nBand = 3 

82 i0Std = np.array([0.08294534, 0.07877351, 0.06464688]) 

83 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434]) 

84 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673]) 

85 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740]) 

86 

87 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon) 

88 

89 # Build the stars, adding in the reference stars 

90 self.config = fgcmcal.FgcmBuildStarsTableConfig() 

91 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsTableHsc.py') 

92 self.configfiles = [testConfigFile] 

93 self.otherArgs = [] 

94 

95 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236] 

96 

97 nStar = 305 

98 nObs = 3789 

99 

100 self._testFgcmBuildStarsTable(visits, nStar, nObs) 

101 

102 self.config = fgcmcal.FgcmBuildStarsConfig() 

103 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsHsc.py') 

104 self.configfiles = [testConfigFile] 

105 self.otherArgs = [] 

106 

107 self._testFgcmBuildStarsAndCompare(visits) 

108 

109 # Perform the fit cycle 

110 self.config = fgcmcal.FgcmFitCycleConfig() 

111 testConfigFile = os.path.join(ROOT, 'config', 'fgcmFitCycleHsc.py') 

112 self.config.load(testConfigFile) 

113 self.configfiles = [testConfigFile] 

114 self.otherArgs = [] 

115 

116 nZp = 1120 

117 nGoodZp = 27 

118 nOkZp = 27 

119 nBadZp = 1093 

120 nStdStars = 237 

121 nPlots = 35 

122 

123 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True) 

124 

125 # Test the second fit cycle -- need to copy to unfreeze config 

126 newConfig = copy.copy(self.config) 

127 newConfig.update(cycleNumber=1) 

128 newConfig.connections.update(cycleNumber='1', 

129 previousCycleNumber='0') 

130 self.config = newConfig 

131 

132 newConfigFile = os.path.join(self.testDir, 

133 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py') 

134 newConfig.save(newConfigFile) 

135 self.configfiles.append(newConfigFile) 

136 

137 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True) 

138 

139 # Test the "final" fit cycle 

140 newConfig = copy.copy(self.config) 

141 newConfig.update(cycleNumber=2, 

142 ccdGraySubCcdDict={'g': True, 'r': True, 'i': True}, 

143 isFinalCycle=True) 

144 newConfig.connections.update(cycleNumber='2', 

145 previousCycleNumber='1') 

146 self.config = newConfig 

147 

148 newConfigFile = os.path.join(self.testDir, 

149 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py') 

150 newConfig.save(newConfigFile) 

151 self.configfiles.append(newConfigFile) 

152 

153 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots) 

154 

155 # Output the products 

156 

157 self.config = fgcmcal.FgcmOutputProductsConfig() 

158 testConfigFile = os.path.join(ROOT, 'config', 'fgcmOutputProductsHsc.py') 

159 self.configfiles = [testConfigFile] 

160 self.otherArgs = [] 

161 

162 filterMapping = {'r': 'HSC-R', 'i': 'HSC-I'} 

163 zpOffsets = np.array([0.0010470541892573237, 0.005398149602115154]) 

164 

165 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName, 

166 filterMapping, zpOffsets, 

167 36236, 87, 'i', 1) 

168 

169 def test_fgcmcalTract(self): 

170 # Set numpy seed for stability 

171 np.random.seed(seed=1000) 

172 

173 # First need to make the LUT 

174 self.config = fgcmcal.FgcmMakeLutConfig() 

175 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py') 

176 self.configfiles = [testConfigFile] 

177 self.otherArgs = [] 

178 

179 nBand = 3 

180 i0Std = np.array([0.08294534, 0.07877351, 0.06464688]) 

181 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434]) 

182 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673]) 

183 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740]) 

184 

185 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon) 

186 

187 self.config = fgcmcal.FgcmCalibrateTractTableConfig() 

188 testConfigFile = os.path.join(ROOT, 'config', 'fgcmCalibrateTractTableHsc.py') 

189 self.configfiles = [testConfigFile] 

190 self.otherArgs = [] 

191 

192 rawRepeatability = np.array([0.0, 0.008282480993703009, 0.006739350255884648]) 

193 filterNCalibMap = {'HSC-R': 14, 

194 'HSC-I': 15} 

195 

196 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236] 

197 tract = 9697 

198 

199 self._testFgcmCalibrateTract(visits, tract, 

200 rawRepeatability, filterNCalibMap) 

201 

202 

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

204 pass 

205 

206 

207def setup_module(module): 

208 lsst.utils.tests.init() 

209 

210 

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

212 lsst.utils.tests.init() 

213 unittest.main()