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

26""" 

27import unittest 

28import os 

29import tempfile 

30import numpy as np 

31 

32import matplotlib 

33matplotlib.use("Agg") 

34 

35import lsst.utils # noqa: E402 

36import lsst.pipe.tasks # noqa: E402 

37 

38import fgcmcalTestBase # noqa: E402 

39 

40 

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

42 

43 

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

45 @classmethod 

46 def setUpClass(cls): 

47 try: 

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

49 except LookupError: 

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

51 try: 

52 lsst.utils.getPackageDir('obs_subaru') 

53 except LookupError: 

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

55 

56 cls.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-") 

57 

58 cls._importRepository('lsst.obs.subaru.HyperSuprimeCam', 

59 os.path.join(cls.dataDir, 'hsc'), 

60 os.path.join(cls.dataDir, 'hsc', 'exports.yaml')) 

61 

62 def test_fgcmcalPipeline(self): 

63 # Set numpy seed for stability 

64 np.random.seed(seed=1000) 

65 

66 instName = 'HSC' 

67 testName = 'testfgcmcalpipe' 

68 

69 nBand = 3 

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

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

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

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

74 

75 self._testFgcmMakeLut(instName, testName, 

76 nBand, i0Std, i0Recon, i10Std, i10Recon) 

77 

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

79 

80 nStar = 305 

81 nObs = 3789 

82 

83 self._testFgcmBuildStarsTable(instName, testName, 

84 "physical_filter IN ('HSC-G', 'HSC-R', 'HSC-I')", 

85 visits, nStar, nObs) 

86 

87 nZp = 1120 

88 nGoodZp = 27 

89 nOkZp = 27 

90 nBadZp = 1093 

91 nStdStars = 235 

92 nPlots = 35 

93 

94 self._testFgcmFitCycle(instName, testName, 

95 0, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True) 

96 self._testFgcmFitCycle(instName, testName, 

97 1, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True) 

98 

99 # We need to create an extra config file to turn on "sub-ccd gray" for testing. 

100 extraConfigFile = os.path.join(self.testDir, "cycle03_patch_config.py") 

101 with open(extraConfigFile, "w") as f: 

102 f.write("config.isFinalCycle = True\n") 

103 f.write("config.ccdGraySubCcdDict = {'g': True, 'r': True, 'i': True}\n") 

104 

105 self._testFgcmFitCycle(instName, testName, 

106 2, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, 

107 extraConfig=extraConfigFile) 

108 

109 zpOffsets = np.array([-0.0008161436999216676, 

110 0.006149172317236662]) 

111 

112 self._testFgcmOutputProducts(instName, testName, 

113 zpOffsets, 36236, 87, 'i', 1) 

114 

115 def test_fgcmcalMultipleFitPipeline(self): 

116 # Set numpy seed for stability 

117 np.random.seed(seed=1000) 

118 

119 instName = 'HSC' 

120 testName = 'testfgcmcalmultiple' 

121 

122 nBand = 3 

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

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

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

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

127 

128 self._testFgcmMakeLut(instName, testName, 

129 nBand, i0Std, i0Recon, i10Std, i10Recon) 

130 

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

132 

133 # These are slightly different from above due to the configuration change 

134 # mid-way in the separate fits. 

135 zpOffsets = np.array([-0.0007102462113834918, 

136 0.005907602142542601]) 

137 

138 self._testFgcmMultiFit(instName, testName, 

139 "physical_filter IN ('HSC-G', 'HSC-R', 'HSC-I')", 

140 visits, zpOffsets) 

141 

142 def test_fgcmcalTractPipeline(self): 

143 # Set numpy seed for stability 

144 np.random.seed(seed=1000) 

145 

146 instName = 'HSC' 

147 testName = 'testfgcmcaltract' 

148 

149 nBand = 3 

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

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

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

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

154 

155 self._testFgcmMakeLut(instName, testName, 

156 nBand, i0Std, i0Recon, i10Std, i10Recon) 

157 

158 rawRepeatability = np.array([0.0, 

159 0.004436014222072738, 

160 0.00451764656339253]) 

161 filterNCalibMap = {'HSC-R': 12, 

162 'HSC-I': 15} 

163 

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

165 tract = 9697 

166 

167 self._testFgcmCalibrateTract(instName, testName, 

168 visits, tract, 'hsc_rings_v1', 

169 rawRepeatability, filterNCalibMap) 

170 

171 

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

173 pass 

174 

175 

176def setup_module(module): 

177 lsst.utils.tests.init() 

178 

179 

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

181 lsst.utils.tests.init() 

182 unittest.main()