Coverage for tests/test_fgcmcal_hsc.py : 19%

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.FgcmBuildStarsTableConfig()
92 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsTableHsc.py')
93 self.configfiles = [testConfigFile]
94 self.otherArgs = []
96 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
98 nStar = 305
99 nObs = 3789
101 self._testFgcmBuildStarsTable(visits, nStar, nObs)
103 self.config = fgcmcal.FgcmBuildStarsConfig()
104 testConfigFile = os.path.join(ROOT, 'config', 'fgcmBuildStarsHsc.py')
105 self.configfiles = [testConfigFile]
106 self.otherArgs = []
108 self._testFgcmBuildStarsAndCompare(visits)
110 # Perform the fit cycle
111 self.config = fgcmcal.FgcmFitCycleConfig()
112 testConfigFile = os.path.join(ROOT, 'config', 'fgcmFitCycleHsc.py')
113 self.config.load(testConfigFile)
114 self.configfiles = [testConfigFile]
115 self.otherArgs = []
117 nZp = 1120
118 nGoodZp = 27
119 nOkZp = 27
120 nBadZp = 1093
121 nStdStars = 237
122 nPlots = 35
124 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
126 # Test the second fit cycle -- need to copy to unfreeze config
127 newConfig = copy.copy(self.config)
128 newConfig.update(cycleNumber=1)
129 self.config = newConfig
131 newConfigFile = os.path.join(self.testDir,
132 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
133 newConfig.save(newConfigFile)
134 self.configfiles.append(newConfigFile)
136 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots, skipChecks=True)
138 # Test the "final" fit cycle
139 newConfig = copy.copy(self.config)
140 newConfig.update(cycleNumber=2,
141 ccdGraySubCcdDict={'g': True, 'r': True, 'i': True},
142 isFinalCycle=True)
143 self.config = newConfig
145 newConfigFile = os.path.join(self.testDir,
146 f'fgcmFitCycle_cycle{newConfig.cycleNumber}.py')
147 newConfig.save(newConfigFile)
148 self.configfiles.append(newConfigFile)
150 self._testFgcmFitCycle(nZp, nGoodZp, nOkZp, nBadZp, nStdStars, nPlots)
152 # Output the products
154 self.config = fgcmcal.FgcmOutputProductsConfig()
155 testConfigFile = os.path.join(ROOT, 'config', 'fgcmOutputProductsHsc.py')
156 self.configfiles = [testConfigFile]
157 self.otherArgs = []
159 filterMapping = {'r': 'HSC-R', 'i': 'HSC-I'}
160 zpOffsets = np.array([0.0010470541892573237, 0.005398149602115154])
162 self._testFgcmOutputProducts(visitDataRefName, ccdDataRefName,
163 filterMapping, zpOffsets,
164 36236, 87, 'i', 1)
166 def test_fgcmcalTract(self):
167 # Set numpy seed for stability
168 np.random.seed(seed=1000)
170 # First need to make the LUT
171 self.config = fgcmcal.FgcmMakeLutConfig()
172 testConfigFile = os.path.join(ROOT, 'config', 'fgcmMakeLutHsc.py')
173 self.configfiles = [testConfigFile]
174 self.otherArgs = []
176 nBand = 3
177 i0Std = np.array([0.08294534, 0.07877351, 0.06464688])
178 i10Std = np.array([-0.000091981, -0.00061516, -0.00063434])
179 i0Recon = np.array([0.07322632, 0.0689530429, 0.05600673])
180 i10Recon = np.array([-5.89816122, -7.01847144, 3.62675740])
182 self._testFgcmMakeLut(nBand, i0Std, i0Recon, i10Std, i10Recon)
184 self.config = fgcmcal.FgcmCalibrateTractTableConfig()
185 testConfigFile = os.path.join(ROOT, 'config', 'fgcmCalibrateTractTableHsc.py')
186 self.configfiles = [testConfigFile]
187 self.otherArgs = []
189 rawRepeatability = np.array([0.0, 0.008282480993703009, 0.006739350255884648])
190 filterNCalibMap = {'HSC-R': 14,
191 'HSC-I': 15}
193 visits = [34648, 34690, 34714, 34674, 34670, 36140, 35892, 36192, 36260, 36236]
194 tract = 9697
196 self._testFgcmCalibrateTract(visits, tract,
197 rawRepeatability, filterNCalibMap)
200class TestMemory(lsst.utils.tests.MemoryTestCase):
201 pass
204def setup_module(module):
205 lsst.utils.tests.init()
208if __name__ == "__main__": 208 ↛ 209line 208 didn't jump to line 209, because the condition on line 208 was never true
209 lsst.utils.tests.init()
210 unittest.main()