Coverage for tests/test_fgcmcal_hsc.py: 27%

91 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-06-10 01:54 -0700

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 

37import lsst.daf.butler # noqa: E402 

38 

39import fgcmcalTestBase # noqa: E402 

40 

41 

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

43 

44 

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

46 @classmethod 

47 def setUpClass(cls): 

48 try: 

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

50 except LookupError: 

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

52 try: 

53 lsst.utils.getPackageDir('obs_subaru') 

54 except LookupError: 

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

56 

57 lsst.daf.butler.cli.cliLog.CliLog.initLog(longlog=False) 

58 

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

60 

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

62 os.path.join(cls.dataDir, 'hsc/repo'), 

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

64 

65 def test_fgcmcalPipeline(self): 

66 # Set numpy seed for stability 

67 np.random.seed(seed=1000) 

68 

69 instName = 'HSC' 

70 testName = 'testfgcmcalpipe' 

71 

72 nBand = 3 

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

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

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

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

77 

78 self._testFgcmMakeLut(instName, testName, 

79 nBand, i0Std, i0Recon, i10Std, i10Recon) 

80 

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

82 

83 nStar = 305 

84 nObs = 3789 

85 

86 self._testFgcmBuildStarsTable(instName, testName, 

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

88 visits, nStar, nObs) 

89 

90 nZp = 1120 

91 nGoodZp = 27 

92 nOkZp = 27 

93 nBadZp = 1093 

94 nStdStars = 235 

95 nPlots = 48 

96 

97 self._testFgcmFitCycle(instName, testName, 

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

99 self._testFgcmFitCycle(instName, testName, 

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

101 

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

103 # We also want to exercise the code path setting useExposureReferenceOffset = False. 

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

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

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

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

108 f.write("config.useExposureReferenceOffset = False") 

109 

110 self._testFgcmFitCycle(instName, testName, 

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

112 extraConfig=extraConfigFile) 

113 

114 zpOffsets = np.array([-0.0008051003096625209, 

115 0.0072303167544305325]) 

116 

117 self._testFgcmOutputProducts(instName, testName, 

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

119 

120 def test_fgcmcalMultipleFitPipeline(self): 

121 # Set numpy seed for stability 

122 np.random.seed(seed=1000) 

123 

124 instName = 'HSC' 

125 testName = 'testfgcmcalmultiple' 

126 

127 nBand = 3 

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

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

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

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

132 

133 self._testFgcmMakeLut(instName, testName, 

134 nBand, i0Std, i0Recon, i10Std, i10Recon) 

135 

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

137 

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

139 # mid-way in the separate fits. 

140 zpOffsets = np.array([-0.0006988655077293515, 

141 0.004102597013115883]) 

142 

143 self._testFgcmMultiFit(instName, testName, 

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

145 visits, zpOffsets) 

146 

147 def test_fgcmcalTractPipeline(self): 

148 # Set numpy seed for stability 

149 np.random.seed(seed=1000) 

150 

151 instName = 'HSC' 

152 testName = 'testfgcmcaltract' 

153 

154 nBand = 3 

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

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

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

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

159 

160 self._testFgcmMakeLut(instName, testName, 

161 nBand, i0Std, i0Recon, i10Std, i10Recon) 

162 

163 rawRepeatability = np.array([0.0, 

164 0.0025195920941720683, 

165 0.004095912225403857]) 

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

167 'HSC-I': 15} 

168 

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

170 tract = 9697 

171 

172 self._testFgcmCalibrateTract(instName, testName, 

173 visits, tract, 'hsc_rings_v1', 

174 rawRepeatability, filterNCalibMap) 

175 

176 

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

178 pass 

179 

180 

181def setup_module(module): 

182 lsst.utils.tests.init() 

183 

184 

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

186 lsst.utils.tests.init() 

187 unittest.main()