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 HSC data from testdata_jointcal. 

26""" 

27 

28import matplotlib 

29matplotlib.use("Agg") # noqa E402 

30 

31import unittest 

32import os 

33import copy 

34import tempfile 

35import numpy as np 

36 

37import lsst.utils 

38import lsst.pipe.tasks 

39 

40import fgcmcalTestBase 

41 

42import lsst.fgcmcal as fgcmcal 

43 

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

45 

46 

47class FgcmcalTestHSC(fgcmcalTestBase.FgcmcalTestBase, lsst.utils.tests.TestCase): 

48 @classmethod 

49 def setUpClass(cls): 

50 try: 

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

52 except LookupError: 

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

54 try: 

55 lsst.utils.getPackageDir('obs_subaru') 

56 except LookupError: 

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

58 

59 def setUp(self): 

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

61 

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

63 

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

65 

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

67 

68 def test_fgcmcalTasks(self): 

69 # Set numpy seed for stability 

70 np.random.seed(seed=1000) 

71 

72 visitDataRefName = 'visit' 

73 ccdDataRefName = 'ccd' 

74 

75 # First test making the LUT 

76 self.config = fgcmcal.FgcmMakeLutConfig() 

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

78 self.configfiles = [testConfigFile] 

79 

80 self.otherArgs = [] 

81 

82 nBand = 3 

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

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

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

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

87 

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

89 

90 # Build the stars, adding in the reference stars 

91 self.config = fgcmcal.FgcmBuildStarsConfig() 

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

93 self.configfiles = [testConfigFile] 

94 self.otherArgs = [] 

95 

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

97 

98 nStar = 304 

99 nObs = 3799 

100 

101 self._testFgcmBuildStars(visits, nStar, nObs) 

102 

103 # Perform the fit cycle 

104 self.config = fgcmcal.FgcmFitCycleConfig() 

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

106 self.config.load(testConfigFile) 

107 self.configfiles = [testConfigFile] 

108 self.otherArgs = [] 

109 

110 nZp = 1120 

111 nGoodZp = 27 

112 nOkZp = 27 

113 nBadZp = 1093 

114 nStdStars = 256 

115 nPlots = 40 

116 

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

118 

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

120 newConfig = copy.copy(self.config) 

121 newConfig.update(cycleNumber=1) 

122 self.config = newConfig 

123 

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

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

126 newConfig.save(newConfigFile) 

127 self.configfiles.append(newConfigFile) 

128 

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

130 

131 # Test the "final" fit cycle 

132 newConfig = copy.copy(self.config) 

133 newConfig.update(cycleNumber=2, 

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

135 isFinalCycle=True) 

136 self.config = newConfig 

137 

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

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

140 newConfig.save(newConfigFile) 

141 self.configfiles.append(newConfigFile) 

142 

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

144 

145 # Output the products 

146 

147 self.config = fgcmcal.FgcmOutputProductsConfig() 

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

149 self.configfiles = [testConfigFile] 

150 self.otherArgs = [] 

151 

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

153 zpOffsets = np.array([0.0012975315330550075, 0.006424360908567905]) 

154 

155 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName, 

156 filterMapping, zpOffsets, 

157 36236, 87, 'i', 1) 

158 

159 def test_fgcmcalTract(self): 

160 # Set numpy seed for stability 

161 np.random.seed(seed=1000) 

162 

163 # First need to make the LUT 

164 self.config = fgcmcal.FgcmMakeLutConfig() 

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

166 self.configfiles = [testConfigFile] 

167 self.otherArgs = [] 

168 

169 nBand = 3 

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

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

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

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

174 

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

176 

177 self.config = fgcmcal.FgcmCalibrateTractConfig() 

178 testConfigFile = os.path.join(ROOT, 'config', 'fgcmCalibrateTractHsc.py') 

179 self.configfiles = [testConfigFile] 

180 self.otherArgs = [] 

181 

182 rawRepeatability = np.array([0.0, 0.012838834334716097, 0.008774119602231331]) 

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

184 'HSC-I': 15} 

185 

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

187 tract = 0 

188 

189 self._testFgcmCalibrateTract(visits, tract, 

190 rawRepeatability, filterNCalibMap) 

191 

192 

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

194 pass 

195 

196 

197def setup_module(module): 

198 lsst.utils.tests.init() 

199 

200 

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

202 lsst.utils.tests.init() 

203 unittest.main()