Coverage for tests/test_fgcmcal_hsc.py: 22%
127 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-01 12:18 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-01 12:18 +0000
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.
25Run test suite on fgcmcal using Gen3 HSC data from testdata_jointcal.
26"""
27import unittest
28import os
29import tempfile
30import numpy as np
32# Ensure that matplotlib doesn't try to open a display during testing.
33import matplotlib
34matplotlib.use("Agg")
36import lsst.utils # noqa: E402
37import lsst.pipe.tasks # noqa: E402
38import lsst.daf.butler # noqa: E402
40import fgcmcalTestBase # noqa: E402
43ROOT = os.path.abspath(os.path.dirname(__file__))
45I0STD = [0.08294534, 0.07877351, 0.06464688]
46I10STD = [-0.000091981, -0.00061516, -0.00063434]
47I0RECON = [0.07322179342588758, 0.0689530429, 0.05600673]
48I10RECON = [-4.490243571049125, -7.01786443508, 3.62738180611]
51class FgcmcalTestHSC(fgcmcalTestBase.FgcmcalTestBase, lsst.utils.tests.TestCase):
52 @classmethod
53 def setUpClass(cls):
54 try:
55 cls.dataDir = lsst.utils.getPackageDir('testdata_jointcal')
56 except LookupError:
57 raise unittest.SkipTest("testdata_jointcal not setup")
58 try:
59 lsst.utils.getPackageDir('obs_subaru')
60 except LookupError:
61 raise unittest.SkipTest("obs_subaru not setup")
63 lsst.daf.butler.cli.cliLog.CliLog.initLog(longlog=False)
65 cls.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-")
67 cls._importRepository('lsst.obs.subaru.HyperSuprimeCam',
68 os.path.join(cls.dataDir, 'hsc/repo'),
69 os.path.join(cls.dataDir, 'hsc', 'exports.yaml'))
71 def test_fgcmcalPipelineBuildFromTable(self):
72 """Test running the full pipeline, using older association code.
74 This test uses the FgcmBuildStarsFromTableTask instead of the new
75 FgcmBuildFromIsolatedStarsTask.
76 """
77 # Set numpy seed for stability
78 np.random.seed(seed=1000)
80 instName = 'HSC'
81 testName = 'testfgcmcalpipe'
83 nBand = 3
84 i0Std = np.array(I0STD)
85 i10Std = np.array(I10STD)
86 i0Recon = np.array(I0RECON)
87 i10Recon = np.array(I10RECON)
89 self._testFgcmMakeLut(instName, testName,
90 nBand, i0Std, i0Recon, i10Std, i10Recon)
92 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
94 nStar = 305
95 nObs = 3789
97 self._testFgcmBuildStarsTable(instName, testName,
98 "physical_filter IN ('HSC-G', 'HSC-R', 'HSC-I')",
99 visits, nStar, nObs)
101 nZp = 1120
102 nGoodZp = 27
103 nOkZp = 27
104 nBadZp = 1093
105 nStdStars = 235
106 nPlots = 47
108 # We need an extra config file to turn off parquet format.
109 extraConfigFile = os.path.join(self.testDir, "turn_off_parquet.py")
110 with open(extraConfigFile, "w") as f:
111 f.write("config.useParquetCatalogFormat = False\n")
113 self._testFgcmFitCycle(instName, testName,
114 0, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True,
115 extraConfig=extraConfigFile)
116 self._testFgcmFitCycle(instName, testName,
117 1, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True,
118 extraConfig=extraConfigFile)
120 # We need to create an extra config file to turn on "sub-ccd gray" for testing.
121 # We also want to exercise the code path setting useExposureReferenceOffset = False.
122 extraConfigFile = os.path.join(self.testDir, "cycle03_patch_config.py")
123 with open(extraConfigFile, "w") as f:
124 f.write("config.useParquetCatalogFormat = False\n")
125 f.write("config.isFinalCycle = True\n")
126 f.write("config.ccdGraySubCcdDict = {'g': True, 'r': True, 'i': True}\n")
127 f.write("config.useExposureReferenceOffset = False")
129 self._testFgcmFitCycle(instName, testName,
130 2, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots,
131 extraConfig=extraConfigFile)
133 def test_fgcmcalPipeline(self):
134 """Test running the full pipeline, using new isolated star association code.
136 This test uses the FgcmBuildFromIsolatedStarsTask instead of the old
137 FgcmBuildStarsFromTableTask.
138 """
139 # Set numpy seed for stability
140 np.random.seed(seed=1000)
142 instName = 'HSC'
143 testName = 'testfgcmcalpipe'
145 nBand = 3
146 i0Std = np.array(I0STD)
147 i10Std = np.array(I10STD)
148 i0Recon = np.array(I0RECON)
149 i10Recon = np.array(I10RECON)
151 self._testFgcmMakeLut(instName, testName,
152 nBand, i0Std, i0Recon, i10Std, i10Recon)
154 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
156 nStar = 295
157 nObs = 1808
159 self._testFgcmBuildFromIsolatedStars(
160 instName,
161 testName,
162 "physical_filter IN ('HSC-G', 'HSC-R', 'HSC-I')",
163 visits,
164 nStar,
165 nObs,
166 )
168 nZp = 1120
169 nGoodZp = 27
170 nOkZp = 27
171 nBadZp = 1093
172 nStdStars = 227
173 nPlots = 47
175 self._testFgcmFitCycle(instName, testName,
176 0, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
177 self._testFgcmFitCycle(instName, testName,
178 1, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
180 # We need to create an extra config file to turn on "sub-ccd gray" for testing.
181 # We also want to exercise the code path setting useExposureReferenceOffset = False.
182 extraConfigFile = os.path.join(self.testDir, "cycle03_patch_config.py")
183 with open(extraConfigFile, "w") as f:
184 f.write("config.isFinalCycle = True\n")
185 f.write("config.ccdGraySubCcdDict = {'g': True, 'r': True, 'i': True}\n")
186 f.write("config.useExposureReferenceOffset = False")
188 self._testFgcmFitCycle(instName, testName,
189 2, nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots,
190 extraConfig=extraConfigFile)
192 zpOffsets = np.array([-0.001339632086455822,
193 0.005496968515217304])
195 self._testFgcmOutputProducts(instName, testName,
196 zpOffsets, 36236, 87, 'i', 1)
198 def test_fgcmcalMultipleFitPipeline(self):
199 # Set numpy seed for stability
200 np.random.seed(seed=1000)
202 instName = 'HSC'
203 testName = 'testfgcmcalmultiple'
205 nBand = 3
206 i0Std = np.array(I0STD)
207 i10Std = np.array(I10STD)
208 i0Recon = np.array(I0RECON)
209 i10Recon = np.array(I10RECON)
211 self._testFgcmMakeLut(instName, testName,
212 nBand, i0Std, i0Recon, i10Std, i10Recon)
214 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
216 # These are slightly different from above due to the configuration change
217 # mid-way in the separate fits.
218 zpOffsets = np.array([-0.0022663213312625885,
219 0.004101278726011515])
221 self._testFgcmMultiFit(instName, testName,
222 "physical_filter IN ('HSC-G', 'HSC-R', 'HSC-I')",
223 visits, zpOffsets)
225 def test_fgcmcalTractPipeline(self):
226 # Set numpy seed for stability
227 np.random.seed(seed=1000)
229 instName = 'HSC'
230 testName = 'testfgcmcaltract'
232 nBand = 3
233 i0Std = np.array(I0STD)
234 i10Std = np.array(I10STD)
235 i0Recon = np.array(I0RECON)
236 i10Recon = np.array(I10RECON)
238 self._testFgcmMakeLut(instName, testName,
239 nBand, i0Std, i0Recon, i10Std, i10Recon)
241 rawRepeatability = np.array([0.0,
242 0.005631336514834158,
243 0.004095912225403857])
244 filterNCalibMap = {'HSC-R': 12,
245 'HSC-I': 15}
247 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
248 tract = 9697
250 self._testFgcmCalibrateTract(instName, testName,
251 visits, tract, 'hsc_rings_v1',
252 rawRepeatability, filterNCalibMap)
255class TestMemory(lsst.utils.tests.MemoryTestCase):
256 pass
259def setup_module(module):
260 lsst.utils.tests.init()
263if __name__ == "__main__": 263 ↛ 264line 263 didn't jump to line 264, because the condition on line 263 was never true
264 lsst.utils.tests.init()
265 unittest.main()