Coverage for tests/test_jointcal_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# This file is part of jointcal.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import unittest
23import os
25from astropy import units as u
27import lsst.geom
28import lsst.pex.config
29import lsst.utils
30import lsst.pex.exceptions
32import jointcalTestBase
35# for MemoryTestCase
36def setup_module(module):
37 lsst.utils.tests.init()
40class JointcalTestHSC(jointcalTestBase.JointcalTestBase, lsst.utils.tests.TestCase):
42 @classmethod
43 def setUpClass(cls):
44 try:
45 cls.data_dir = lsst.utils.getPackageDir('testdata_jointcal')
46 except LookupError:
47 raise unittest.SkipTest("testdata_jointcal not setup")
48 try:
49 lsst.utils.getPackageDir('obs_subaru')
50 except LookupError:
51 raise unittest.SkipTest("obs_subaru not setup")
53 def setUp(self):
54 # See Readme for an explanation of this empirical value.
55 self.dist_rms_absolute = 53e-3*u.arcsecond
57 do_plot = False
59 # center of the hsc validation_data catalog
60 center = lsst.geom.SpherePoint(320.367492, 0.3131554, lsst.geom.degrees)
61 radius = 5*lsst.geom.degrees
63 input_dir = os.path.join(self.data_dir, 'hsc')
64 all_visits = [903334, 903336, 903338, 903342, 903344, 903346, 903986, 903988, 903990, 904010, 904014]
66 self.setUp_base(center, radius,
67 input_dir=input_dir,
68 all_visits=all_visits,
69 do_plot=do_plot)
71 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'), 'tests/config/hsc-config.py')
72 self.configfiles.append(test_config)
74 def test_jointcalTask_2_visits_simple(self):
75 self.config = lsst.jointcal.jointcal.JointcalConfig()
76 self.config.astrometryModel = "simple"
77 self.config.photometryModel = "simpleFlux"
79 # See Readme for an explanation of these empirical values.
80 dist_rms_relative = 17e-3*u.arcsecond
81 pa1 = 0.024
82 metrics = {'collected_astrometry_refStars': 2948,
83 'collected_photometry_refStars': 2948,
84 'selected_astrometry_refStars': 657,
85 'selected_photometry_refStars': 657,
86 'associated_astrometry_fittedStars': 1151,
87 'associated_photometry_fittedStars': 1151,
88 'selected_astrometry_fittedStars': 851,
89 'selected_photometry_fittedStars': 851,
90 'selected_astrometry_ccdImages': 6,
91 'selected_photometry_ccdImages': 6,
92 'astrometry_final_chi2': 819.07,
93 'astrometry_final_ndof': 2134,
94 'photometry_final_chi2': 1811.45,
95 'photometry_final_ndof': 1072
96 }
97 self._testJointcalTask(2, dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics)
99 def test_jointcalTask_11_visits_simple_astrometry_no_photometry(self):
100 """Test 11 visits with different filters.
101 Testing photometry doesn't make sense for this currently.
102 """
104 self.config = lsst.jointcal.jointcal.JointcalConfig()
105 self.config.astrometryModel = "simple"
106 self.config.doPhotometry = False
107 self.jointcalStatistics.do_photometry = False
109 # See Readme for an explanation of these empirical values.
110 dist_rms_relative = 17e-3*u.arcsecond
111 pa1 = None # pa1 = 0.134
112 metrics = {'collected_astrometry_refStars': 4926,
113 'selected_astrometry_refStars': 1346,
114 'associated_astrometry_fittedStars': 2908,
115 'selected_astrometry_fittedStars': 2276,
116 'selected_astrometry_ccdImages': 33,
117 'astrometry_final_chi2': 8207.62,
118 'astrometry_final_ndof': 14856,
119 }
120 self._testJointcalTask(11, dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics)
122 def setup_jointcalTask_2_visits_simplePhotometry(self):
123 """Set default values for the constrainedAstrometry tests, and make
124 the differences between each test and the defaults more obvious.
125 """
126 self.config = lsst.jointcal.jointcal.JointcalConfig()
127 self.config.photometryModel = "simpleFlux"
128 self.config.doAstrometry = False
129 self.jointcalStatistics.do_astrometry = False
131 # See Readme for an explanation of these empirical values.
132 pa1 = 0.024
133 metrics = {'collected_photometry_refStars': 2948,
134 'selected_photometry_refStars': 657,
135 'associated_photometry_fittedStars': 1151,
136 'selected_photometry_fittedStars': 851,
137 'selected_photometry_ccdImages': 6,
138 'photometry_final_chi2': 1811.45,
139 'photometry_final_ndof': 1072
140 }
141 return pa1, metrics
143 def test_jointcalTask_2_visits_simpleFlux(self):
144 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry()
145 self._testJointcalTask(2, None, None, pa1, metrics=metrics)
147 def test_jointcalTask_2_visits_simpleMagnitude(self):
148 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry()
149 self.config.photometryModel = "simpleMagnitude"
150 metrics['photometry_final_chi2'] = 1845.67
151 metrics['photometry_final_ndof'] = 1074
153 self._testJointcalTask(2, None, None, pa1, metrics=metrics)
155 def test_jointcalTask_2_visits_simpleMagnitude_colorterms(self):
156 """Test that colorterms are applied and change the fit."""
157 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry()
158 self.config.photometryModel = "simpleMagnitude"
159 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'),
160 'tests/config/hsc-colorterms-config.py')
161 self.configfiles.append(test_config)
163 # Final chi2 should be different, but I don't have an a-priori reason
164 # to expect it to be larger or smaller.
165 metrics['photometry_final_chi2'] = 1966.67
167 self._testJointcalTask(2, None, None, pa1, metrics=metrics)
169 def test_jointcalTask_2_visits_simpleMagnitude_colorterms_no_library(self):
170 """Fail Config validation if the color term library isn't defined."""
171 pa1, metrics = self.setup_jointcalTask_2_visits_simplePhotometry()
172 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'),
173 'tests/config/hsc-colorterms_no_library-config.py')
174 self.configfiles.append(test_config)
176 with self.assertRaises(lsst.pex.config.FieldValidationError):
177 self._testJointcalTask(2, None, None, pa1)
179 def testJointcalTask_2_visits_simple_astrometry_no_photometry(self):
180 """Test turning off fitting photometry."""
181 # See Readme for an explanation of these empirical values.
182 dist_rms_relative = 17e-3*u.arcsecond
183 metrics = {'collected_astrometry_refStars': 2948,
184 'selected_astrometry_refStars': 657,
185 'associated_astrometry_fittedStars': 1151,
186 'selected_astrometry_fittedStars': 851,
187 'selected_astrometry_ccdImages': 6,
188 'astrometry_final_chi2': 819.07,
189 'astrometry_final_ndof': 2134,
190 }
192 self.config = lsst.jointcal.jointcal.JointcalConfig()
193 self.config.astrometryModel = "simple"
194 self.config.doPhotometry = False
195 self.jointcalStatistics.do_photometry = False
197 data_refs = self._testJointcalTask(2, dist_rms_relative, self.dist_rms_absolute,
198 None, metrics=metrics)
200 for data_ref in data_refs:
201 with self.assertRaises(lsst.daf.persistence.butlerExceptions.NoResults):
202 data_ref.get('jointcal_photoCalib')
204 def test_jointcalTask_2_visits_simple_astrometry_gaia_refcat(self):
205 self.config = lsst.jointcal.jointcal.JointcalConfig()
206 self.config.astrometryModel = "simple"
207 self.config.photometryModel = "simpleFlux"
208 # use the a.net refcat for photometry, gaia for astrometry
209 test_config = os.path.join(lsst.utils.getPackageDir('jointcal'), 'tests/config/hsc-gaia-config.py')
210 self.configfiles.append(test_config)
211 dist_rms_relative = 17e-3*u.arcsecond
213 # See Readme for an explanation of these empirical values.
214 # NOTE: PA1 is slightly different here, because the number of SDSS
215 # cross-matches within 0.1" goes down after we apply the GAIA-fit WCS.
216 pa1 = 0.02405
217 metrics = {'collected_astrometry_refStars': 1425,
218 'collected_photometry_refStars': 2948,
219 'selected_astrometry_refStars': 271,
220 'selected_photometry_refStars': 657,
221 'associated_astrometry_fittedStars': 1151,
222 'associated_photometry_fittedStars': 1151,
223 'selected_astrometry_fittedStars': 645,
224 'selected_photometry_fittedStars': 851,
225 'selected_astrometry_ccdImages': 6,
226 'selected_photometry_ccdImages': 6,
227 'astrometry_final_chi2': 435.01995,
228 'astrometry_final_ndof': 1412,
229 'photometry_final_chi2': 1811.45,
230 'photometry_final_ndof': 1072
231 }
232 # NOTE: The astrometry/photometry tests are computed using the a.net SDSS refcat,
233 # so the absolute astrometry RMS will be larger (because GAIA is better, so
234 # comparing against SDSS will look "worse").
235 dist_rms_absolute = 56e-3*u.arcsecond
236 self._testJointcalTask(2, dist_rms_relative, dist_rms_absolute, pa1, metrics=metrics)
238 def test_jointcalTask_2_visits_simple_astrometry_no_photometry_match_cut_10(self):
239 """A larger matching radius will result in more associated fittedStars.
240 """
241 self.config = lsst.jointcal.jointcal.JointcalConfig()
242 self.config.astrometryModel = "simple"
243 self.config.matchCut = 10.0 # TODO: once DM-6885 is fixed, we need to put `*lsst.geom.arcseconds`
244 self.config.doPhotometry = False
245 self.jointcalStatistics.do_photometry = False
247 # See Readme for an explanation of these empirical values.
248 dist_rms_relative = 17e-3*u.arcsecond
249 metrics = {'collected_astrometry_refStars': 2948,
250 'selected_astrometry_refStars': 693,
251 'associated_astrometry_fittedStars': 1151,
252 'selected_astrometry_fittedStars': 876,
253 'selected_astrometry_ccdImages': 6,
254 'astrometry_final_chi2': 818.46,
255 'astrometry_final_ndof': 2132,
256 }
257 pa1 = None
258 self._testJointcalTask(2, dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics)
260 def test_jointcalTask_3_visits_simple_astrometry_no_photometry(self):
261 """3 visit, default config to compare with min_measurements_3 test."""
262 self.config = lsst.jointcal.jointcal.JointcalConfig()
263 self.config.astrometryModel = "simple"
264 self.config.minMeasurements = 2
265 self.config.doPhotometry = False
266 self.jointcalStatistics.do_photometry = False
268 # See Readme for an explanation of these empirical values.
269 dist_rms_relative = 17e-3*u.arcsecond
270 metrics = {'collected_astrometry_refStars': 2948,
271 'selected_astrometry_refStars': 695,
272 'associated_astrometry_fittedStars': 1270,
273 'selected_astrometry_fittedStars': 1011,
274 'selected_astrometry_ccdImages': 8,
275 'astrometry_final_chi2': 1357.59,
276 'astrometry_final_ndof': 3302,
277 }
278 pa1 = None
279 self._testJointcalTask(3, dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics)
281 def test_jointcalTask_3_visits_simple_astrometry_no_photometry_min_measurements_3(self):
282 """Raising min_measurements to 3 will reduce the number of selected
283 fitted stars (and thus the chisq and Ndof), but should not change the
284 other values."""
285 self.config = lsst.jointcal.jointcal.JointcalConfig()
286 self.config.minMeasurements = 3
287 self.config.astrometryModel = "simple"
288 self.config.doPhotometry = False
289 self.jointcalStatistics.do_photometry = False
291 # See Readme for an explanation of these empirical values.
292 dist_rms_relative = 17e-3*u.arcsecond
293 metrics = {'collected_astrometry_refStars': 2948,
294 'selected_astrometry_refStars': 695,
295 'associated_astrometry_fittedStars': 1270,
296 'selected_astrometry_fittedStars': 808,
297 'selected_astrometry_ccdImages': 8,
298 'astrometry_final_chi2': 1210.05,
299 'astrometry_final_ndof': 2906,
300 }
301 pa1 = None
302 self._testJointcalTask(3, dist_rms_relative, self.dist_rms_absolute, pa1, metrics=metrics)
305class MemoryTester(lsst.utils.tests.MemoryTestCase):
306 pass
309if __name__ == "__main__": 309 ↛ 310line 309 didn't jump to line 310, because the condition on line 309 was never true
310 lsst.utils.tests.init()
311 unittest.main()