Coverage for tests/test_fgcmcal_hsc_gen2.py : 20%

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.
25Run test suite on fgcmcal using Gen2 HSC data from testdata_jointcal.
26"""
27import unittest
28import os
29import copy
30import tempfile
31import numpy as np
33import matplotlib
34matplotlib.use("Agg")
36import lsst.utils # noqa: E402
37import lsst.pipe.tasks # noqa: E402
39import fgcmcalTestBaseGen2 # noqa: E402
41import lsst.fgcmcal as fgcmcal # noqa: E402
43ROOT = os.path.abspath(os.path.dirname(__file__))
46class FgcmcalTestHSCGen2(fgcmcalTestBaseGen2.FgcmcalTestBaseGen2, lsst.utils.tests.TestCase):
47 @classmethod
48 def setUpClass(cls):
49 try:
50 cls.dataDir = lsst.utils.getPackageDir('testdata_jointcal')
51 except LookupError:
52 raise unittest.SkipTest("testdata_jointcal not setup")
53 try:
54 lsst.utils.getPackageDir('obs_subaru')
55 except LookupError:
56 raise unittest.SkipTest("obs_subaru not setup")
58 def setUp(self):
59 inputDir = os.path.join(self.dataDir, 'hsc')
61 self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-")
63 self.setUp_base(inputDir=inputDir, testDir=self.testDir)
65 lsst.log.setLevel("HscMapper", lsst.log.FATAL)
67 def test_fgcmcalTasks(self):
68 # Set numpy seed for stability
69 np.random.seed(seed=1000)
71 visitDataRefName = 'visit'
72 ccdDataRefName = 'ccd'
74 # First test making the LUT
75 self.config = fgcmcal.FgcmMakeLutConfig()
76 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
77 self.configfiles = [testConfigFile]
79 self.otherArgs = []
81 nBand = 3
82 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
83 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
84 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
85 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
87 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
89 # Build the stars, adding in the reference stars
90 self.config = fgcmcal.FgcmBuildStarsTableConfig()
91 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsTableHsc.py')
92 self.configfiles = [testConfigFile]
93 self.otherArgs = []
95 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
97 nStar = 305
98 nObs = 3789
100 self._testFgcmBuildStarsTable(visits, nStar, nObs)
102 self.config = fgcmcal.FgcmBuildStarsConfig()
103 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsHsc.py')
104 self.configfiles = [testConfigFile]
105 self.otherArgs = []
107 self._testFgcmBuildStarsAndCompare(visits)
109 # Perform the fit cycle
110 self.config = fgcmcal.FgcmFitCycleConfig()
111 testConfigFile = os.path.join(ROOT, 'config', 'fgcmFitCycleHsc.py')
112 self.config.load(testConfigFile)
113 self.configfiles = [testConfigFile]
114 self.otherArgs = []
116 nZp = 1120
117 nGoodZp = 27
118 nOkZp = 27
119 nBadZp = 1093
120 nStdStars = 237
121 nPlots = 35
123 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
125 # Test the second fit cycle -- need to copy to unfreeze config
126 newConfig = copy.copy(self.config)
127 newConfig.update(cycleNumber=1)
128 newConfig.connections.update(cycleNumber='1',
129 previousCycleNumber='0')
130 self.config = newConfig
132 newConfigFile = os.path.join(self.testDir,
133 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
134 newConfig.save(newConfigFile)
135 self.configfiles.append(newConfigFile)
137 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
139 # Test the "final" fit cycle
140 newConfig = copy.copy(self.config)
141 newConfig.update(cycleNumber=2,
142 ccdGraySubCcdDict={'g': True, 'r': True, 'i': True},
143 isFinalCycle=True)
144 newConfig.connections.update(cycleNumber='2',
145 previousCycleNumber='1')
146 self.config = newConfig
148 newConfigFile = os.path.join(self.testDir,
149 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
150 newConfig.save(newConfigFile)
151 self.configfiles.append(newConfigFile)
153 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots)
155 # Output the products
157 self.config = fgcmcal.FgcmOutputProductsConfig()
158 testConfigFile = os.path.join(ROOT, 'config', 'fgcmOutputProductsHsc.py')
159 self.configfiles = [testConfigFile]
160 self.otherArgs = []
162 zpOffsets = np.array([0.0010470541892573237, 0.005398149602115154])
164 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName,
165 zpOffsets,
166 36236, 87, 'HSC-I', 1)
168 def test_fgcmcalTract(self):
169 # Set numpy seed for stability
170 np.random.seed(seed=1000)
172 # First need to make the LUT
173 self.config = fgcmcal.FgcmMakeLutConfig()
174 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
175 self.configfiles = [testConfigFile]
176 self.otherArgs = []
178 nBand = 3
179 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
180 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
181 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
182 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
184 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
186 self.config = fgcmcal.FgcmCalibrateTractTableConfig()
187 testConfigFile = os.path.join(ROOT, 'config', 'fgcmCalibrateTractTableHsc.py')
188 self.configfiles = [testConfigFile]
189 self.otherArgs = []
191 rawRepeatability = np.array([0.0, 0.008282480993703009, 0.006739350255884648])
192 filterNCalibMap = {'HSC-R': 14,
193 'HSC-I': 15}
195 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
196 tract = 9697
198 self._testFgcmCalibrateTract(visits, tract,
199 rawRepeatability, filterNCalibMap)
202class TestMemory(lsst.utils.tests.MemoryTestCase):
203 pass
206def setup_module(module):
207 lsst.utils.tests.init()
210if __name__ == "__main__": 210 ↛ 211line 210 didn't jump to line 211, because the condition on line 210 was never true
211 lsst.utils.tests.init()
212 unittest.main()