Coverage for tests/test_fgcmcal_hsc.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 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")
54 try:
55 lsst.utils.getPackageDir('obs_subaru')
56 except LookupError:
57 raise unittest.SkipTest("obs_subaru not setup")
59 def setUp(self):
60 inputDir = os.path.join(self.dataDir, 'hsc')
62 self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestFgcm-")
64 self.setUp_base(inputDir=inputDir, testDir=self.testDir)
66 lsst.log.setLevel("HscMapper", lsst.log.FATAL)
68 def test_fgcmcalTasks(self):
69 # Set numpy seed for stability
70 np.random.seed(seed=1000)
72 visitDataRefName = 'visit'
73 ccdDataRefName = 'ccd'
75 # First test making the LUT
76 self.config = fgcmcal.FgcmMakeLutConfig()
77 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
78 self.configfiles = [testConfigFile]
80 self.otherArgs = []
82 nBand = 3
83 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
84 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
85 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
86 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
88 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
90 # Build the stars, adding in the reference stars
91 self.config = fgcmcal.FgcmBuildStarsConfig()
92 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsHsc.py')
93 self.configfiles = [testConfigFile]
94 self.otherArgs = []
96 visits = [903334, 903336, 903338, 903342, 903344, 903346,
97 903986, 903988, 903990, 904010, 904014]
99 nStar = 472
100 nObs = 5431
102 self._testFgcmBuildStars(visits, nStar, nObs)
104 # Perform the fit cycle
105 self.config = fgcmcal.FgcmFitCycleConfig()
106 testConfigFile = os.path.join(ROOT, 'config', 'fgcmFitCycleHsc.py')
107 self.config.load(testConfigFile)
108 self.configfiles = [testConfigFile]
109 self.otherArgs = []
111 nZp = 1232
112 nGoodZp = 26
113 nOkZp = 26
114 nBadZp = 1206
115 nStdStars = 382
116 nPlots = 42
118 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
120 # Test the second fit cycle -- need to copy to unfreeze config
121 newConfig = copy.copy(self.config)
122 newConfig.update(cycleNumber=1)
123 self.config = newConfig
125 newConfigFile = os.path.join(self.testDir,
126 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
127 newConfig.save(newConfigFile)
128 self.configfiles.append(newConfigFile)
130 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
132 # Test the "final" fit cycle
133 newConfig = copy.copy(self.config)
134 newConfig.update(cycleNumber=2,
135 ccdGraySubCcdDict={'g': True, 'r': True, 'i': True},
136 isFinalCycle=True)
137 self.config = newConfig
139 newConfigFile = os.path.join(self.testDir,
140 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
141 newConfig.save(newConfigFile)
142 self.configfiles.append(newConfigFile)
144 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots)
146 # Output the products
148 self.config = fgcmcal.FgcmOutputProductsConfig()
149 testConfigFile = os.path.join(ROOT, 'config', 'fgcmOutputProductsHsc.py')
150 self.configfiles = [testConfigFile]
151 self.otherArgs = []
153 filterMapping = {'r': 'HSC-R', 'i': 'HSC-I'}
154 zpOffsets = np.array([-0.001374409999698, -0.0015618705656])
156 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName,
157 filterMapping, zpOffsets,
158 904014, 12, 'i', 1)
160 def test_fgcmcalTract(self):
161 # Set numpy seed for stability
162 np.random.seed(seed=1000)
164 # First need to make the LUT
165 self.config = fgcmcal.FgcmMakeLutConfig()
166 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
167 self.configfiles = [testConfigFile]
168 self.otherArgs = []
170 nBand = 3
171 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
172 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
173 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
174 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
176 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
178 self.config = fgcmcal.FgcmCalibrateTractConfig()
179 testConfigFile = os.path.join(ROOT, 'config', 'fgcmCalibrateTractHsc.py')
180 self.configfiles = [testConfigFile]
181 self.otherArgs = []
183 rawRepeatability = np.array([0.0, 0.00691888829016613, 0.00443888382172])
184 filterNCalibMap = {'HSC-R': 17,
185 'HSC-I': 16}
187 visits = [903334, 903336, 903338, 903342, 903344, 903346,
188 903986, 903988, 903990, 904010, 904014]
189 tract = 0
191 self._testFgcmCalibrateTract(visits, tract,
192 rawRepeatability, filterNCalibMap)
195class TestMemory(lsst.utils.tests.MemoryTestCase):
196 pass
199def setup_module(module):
200 lsst.utils.tests.init()
203if __name__ == "__main__": 203 ↛ 204line 203 didn't jump to line 204, because the condition on line 203 was never true
204 lsst.utils.tests.init()
205 unittest.main()