Coverage for tests/test_fgcmcal_hsc.py : 21%

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 HSC data from testdata_jointcal.
26"""
28import matplotlib
29matplotlib.use("Agg") # noqa E402
31import unittest
32import os
33import copy
34import tempfile
35import numpy as np
37import lsst.utils
38import lsst.pipe.tasks
40import fgcmcalTestBase
42import lsst.fgcmcal as fgcmcal
44ROOT = os.path.abspath(os.path.dirname(__file__))
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")
55 def setUp(self):
56 inputDir = os.path.join(self.dataDir, 'hsc')
58 self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-")
60 self.setUp_base(inputDir=inputDir, testDir=self.testDir)
62 lsst.log.setLevel("HscMapper", lsst.log.FATAL)
64 def test_fgcmcalTasks(self):
65 # Set numpy seed for stability
66 np.random.seed(seed=1000)
68 visitDataRefName = 'visit'
69 ccdDataRefName = 'ccd'
71 # First test making the LUT
72 self.config = fgcmcal.FgcmMakeLutConfig()
73 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
74 self.configfiles = [testConfigFile]
76 self.otherArgs = []
78 nBand = 3
79 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
80 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
81 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
82 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
84 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
86 # Build the stars, adding in the reference stars
87 self.config = fgcmcal.FgcmBuildStarsConfig()
88 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsHsc.py')
89 self.configfiles = [testConfigFile]
90 self.otherArgs = []
92 visits = [903334, 903336, 903338, 903342, 903344, 903346,
93 903986, 903988, 903990, 904010, 904014]
95 nStar = 472
96 nObs = 5431
98 self._testFgcmBuildStars(visits, nStar, nObs)
100 # Perform the fit cycle
101 self.config = fgcmcal.FgcmFitCycleConfig()
102 testConfigFile = os.path.join(ROOT, 'config', 'fgcmFitCycleHsc.py')
103 self.config.load(testConfigFile)
104 self.configfiles = [testConfigFile]
105 self.otherArgs = []
107 nZp = 1232
108 nGoodZp = 26
109 nOkZp = 26
110 nBadZp = 1206
111 nStdStars = 382
112 nPlots = 42
114 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
116 # Test the second fit cycle -- need to copy to unfreeze config
117 newConfig = copy.copy(self.config)
118 newConfig.update(cycleNumber=1)
119 self.config = newConfig
121 newConfigFile = os.path.join(self.testDir,
122 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
123 newConfig.save(newConfigFile)
124 self.configfiles.append(newConfigFile)
126 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
128 # Test the "final" fit cycle
129 newConfig = copy.copy(self.config)
130 newConfig.update(cycleNumber=2,
131 ccdGraySubCcdDict={'g': True, 'r': True, 'i': True},
132 isFinalCycle=True)
133 self.config = newConfig
135 newConfigFile = os.path.join(self.testDir,
136 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
137 newConfig.save(newConfigFile)
138 self.configfiles.append(newConfigFile)
140 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots)
142 # Output the products
144 self.config = fgcmcal.FgcmOutputProductsConfig()
145 testConfigFile = os.path.join(ROOT, 'config', 'fgcmOutputProductsHsc.py')
146 self.configfiles = [testConfigFile]
147 self.otherArgs = []
149 filterMapping = {'r': 'HSC-R', 'i': 'HSC-I'}
150 zpOffsets = np.array([-0.001374409999698, -0.0015618705656])
152 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName,
153 filterMapping, zpOffsets,
154 904014, 12, 'i', 1)
156 def test_fgcmcalTract(self):
157 # Set numpy seed for stability
158 np.random.seed(seed=1000)
160 # First need to make the LUT
161 self.config = fgcmcal.FgcmMakeLutConfig()
162 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
163 self.configfiles = [testConfigFile]
164 self.otherArgs = []
166 nBand = 3
167 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
168 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
169 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
170 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
172 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
174 self.config = fgcmcal.FgcmCalibrateTractConfig()
175 testConfigFile = os.path.join(ROOT, 'config', 'fgcmCalibrateTractHsc.py')
176 self.configfiles = [testConfigFile]
177 self.otherArgs = []
179 rawRepeatability = np.array([0.0, 0.00691888829016613, 0.00443888382172])
180 filterNCalibMap = {'HSC-R': 17,
181 'HSC-I': 16}
183 visits = [903334, 903336, 903338, 903342, 903344, 903346,
184 903986, 903988, 903990, 904010, 904014]
185 tract = 0
187 self._testFgcmCalibrateTract(visits, tract,
188 rawRepeatability, filterNCalibMap)
191class TestMemory(lsst.utils.tests.MemoryTestCase):
192 pass
195def setup_module(module):
196 lsst.utils.tests.init()
199if __name__ == "__main__": 199 ↛ 200line 199 didn't jump to line 200, because the condition on line 199 was never true
200 lsst.utils.tests.init()
201 unittest.main()