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 = [903334, 903336, 903338, 903342, 903344, 903346, 

97 903986, 903988, 903990, 904010, 904014] 

98 

99 nStar = 472 

100 nObs = 5431 

101 

102 self._testFgcmBuildStars(visits, nStar, nObs) 

103 

104 # Perform the fit cycle 

105 self.config = fgcmcal.FgcmFitCycleConfig() 

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

107 self.config.load(testConfigFile) 

108 self.configfiles = [testConfigFile] 

109 self.otherArgs = [] 

110 

111 nZp = 1232 

112 nGoodZp = 26 

113 nOkZp = 26 

114 nBadZp = 1206 

115 nStdStars = 382 

116 nPlots = 42 

117 

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

119 

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

121 newConfig = copy.copy(self.config) 

122 newConfig.update(cycleNumber=1) 

123 self.config = newConfig 

124 

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

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

127 newConfig.save(newConfigFile) 

128 self.configfiles.append(newConfigFile) 

129 

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

131 

132 # Test the "final" fit cycle 

133 newConfig = copy.copy(self.config) 

134 newConfig.update(cycleNumber=2, 

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

136 isFinalCycle=True) 

137 self.config = newConfig 

138 

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

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

141 newConfig.save(newConfigFile) 

142 self.configfiles.append(newConfigFile) 

143 

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

145 

146 # Output the products 

147 

148 self.config = fgcmcal.FgcmOutputProductsConfig() 

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

150 self.configfiles = [testConfigFile] 

151 self.otherArgs = [] 

152 

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

154 zpOffsets = np.array([-0.001374409999698, -0.0015618705656]) 

155 

156 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName, 

157 filterMapping, zpOffsets, 

158 904014, 12, 'i', 1) 

159 

160 def test_fgcmcalTract(self): 

161 # Set numpy seed for stability 

162 np.random.seed(seed=1000) 

163 

164 # First need to make the LUT 

165 self.config = fgcmcal.FgcmMakeLutConfig() 

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

167 self.configfiles = [testConfigFile] 

168 self.otherArgs = [] 

169 

170 nBand = 3 

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

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

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

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

175 

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

177 

178 self.config = fgcmcal.FgcmCalibrateTractConfig() 

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

180 self.configfiles = [testConfigFile] 

181 self.otherArgs = [] 

182 

183 rawRepeatability = np.array([0.0, 0.00691888829016613, 0.00443888382172]) 

184 filterNCalibMap = {'HSC-R': 17, 

185 'HSC-I': 16} 

186 

187 visits = [903334, 903336, 903338, 903342, 903344, 903346, 

188 903986, 903988, 903990, 904010, 904014] 

189 tract = 0 

190 

191 self._testFgcmCalibrateTract(visits, tract, 

192 rawRepeatability, filterNCalibMap) 

193 

194 

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

196 pass 

197 

198 

199def setup_module(module): 

200 lsst.utils.tests.init() 

201 

202 

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

204 lsst.utils.tests.init() 

205 unittest.main()