Coverage for tests/test_jointcal_cfht_minimal.py: 36%
Shortcuts 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
Shortcuts 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/>.
22"""Test with a minimal catalog extracted from cfht."""
23import unittest
24import os
26import lsst.geom
27import lsst.utils
28import lsst.pex.exceptions
30import jointcalTestBase
31import lsst.jointcal.testUtils
34# for MemoryTestCase
35def setup_module(module):
36 lsst.utils.tests.init()
39@unittest.skipUnless(lsst.jointcal.testUtils.canRunTests(), "obs_cfht not available to use cfht_minimal.")
40class JointcalTestCFHTMinimal(jointcalTestBase.JointcalTestBase, lsst.utils.tests.TestCase):
41 """
42 Test with a stripped down CFHT dataset containing 3 stars, so by-hand
43 calculation of metrics is possible.
45 See `notebooks/cfht_minimal_direct_calculation.ipynb` for numpy-based
46 computations of chi2, etc. using this dataset.
47 """
48 @classmethod
49 def setUpClass(cls):
50 cls.data_dir = os.path.join(lsst.utils.getPackageDir('jointcal'), 'tests/data')
52 def setUp(self):
53 do_plot = False
55 # center of the cfht validation_data catalog
56 center = lsst.geom.SpherePoint(214.884832, 52.6622199, lsst.geom.degrees)
57 radius = 3*lsst.geom.degrees
59 input_dir = os.path.join(self.data_dir, 'cfht_minimal')
60 all_visits = [849375, 850587]
62 where = "instrument='MegaPrime' and tract=0 and skymap='discrete'" # and detector=12"
63 inputCollections = ["singleFrame", "skymaps"]
64 refcats = {"sdss_dr9_fink_v5b": os.path.join(input_dir, "sdss-dr9-fink-v5b.ecsv")}
66 self.setUp_base(center, radius,
67 input_dir=input_dir,
68 all_visits=all_visits,
69 do_plot=do_plot,
70 inputCollections=inputCollections,
71 refcats=refcats,
72 where=where,
73 refcatPath=input_dir,
74 log_level="debug")
75 test_config = os.path.join(os.path.dirname(__file__), 'config/cfht_minimal-config.py')
76 self.configfiles.append(test_config)
78 def test_jointcalTask_2_visits_photometry(self):
79 configOptions = {"doAstrometry": False, "photometryModel": "simpleFlux",
80 "writeInitMatrix": True}
82 # NOTE: ndof==1 from 4 fit parameters (2 model, 2 fittedStar), and
83 # 5 degrees-of-freedom (3 star measurements, with 2 reference stars).
84 # This chi2 is exact, from calculations in cfht_minimal_direct_calculation.ipynb
85 metrics = {'photometry_collected_refStars': 346,
86 'photometry_prepared_refStars': 2,
87 'photometry_matched_fittedStars': 2,
88 'photometry_prepared_fittedStars': 2,
89 'photometry_prepared_ccdImages': 2,
90 'photometry_final_chi2': 2.336915,
91 'photometry_final_ndof': 1
92 }
94 repo = self._runGen3Jointcal("lsst.obs.cfht.MegaPrime", "MegaPrime",
95 configOptions=configOptions, metrics=metrics)
97 # Check that the Hessian/gradient files were written.
98 self.assertTrue(os.path.exists("photometry_preinit-0_r.MP9601-mat.txt"))
99 os.remove("photometry_preinit-0_r.MP9601-mat.txt")
100 self.assertTrue(os.path.exists("photometry_preinit-0_r.MP9601-grad.txt"))
101 os.remove("photometry_preinit-0_r.MP9601-grad.txt")
102 self.assertTrue(os.path.exists("photometry_postinit-0_r.MP9601-mat.txt"))
103 os.remove("photometry_postinit-0_r.MP9601-mat.txt")
104 self.assertTrue(os.path.exists("photometry_postinit-0_r.MP9601-grad.txt"))
105 os.remove("photometry_postinit-0_r.MP9601-grad.txt")
107 # Check that the config was persisted, and that it matches the settings above
108 config = lsst.jointcal.jointcal.JointcalConfig()
109 for key, value in configOptions.items():
110 setattr(config, key, value)
111 butler = lsst.daf.butler.Butler(repo, collections=['MegaPrime/tests/all'])
112 output_config = butler.get('jointcal_config')
113 self.assertEqual(output_config.photometryModel, config.photometryModel)
114 self.assertEqual(output_config.doAstrometry, config.doAstrometry)
115 self.assertEqual(output_config.writeInitMatrix, config.writeInitMatrix)
117 def test_jointcalTask_2_visits_photometry_magnitude(self):
118 self.config = lsst.jointcal.jointcal.JointcalConfig()
119 configOptions = {"doAstrometry": False, "photometryModel": "simpleMagnitude"}
121 # NOTE: ndof==1 from 4 fit parameters (2 model, 2 fittedStar), and
122 # 5 degrees-of-freedom (3 star measurements, with 2 reference stars).
123 metrics = {'photometry_collected_refStars': 346,
124 'photometry_prepared_refStars': 2,
125 'photometry_matched_fittedStars': 2,
126 'photometry_prepared_fittedStars': 2,
127 'photometry_prepared_ccdImages': 2,
128 'photometry_final_chi2': 2.23008,
129 'photometry_final_ndof': 1
130 }
132 self._runGen3Jointcal("lsst.obs.cfht.MegaPrime", "MegaPrime",
133 configOptions=configOptions, metrics=metrics)
135 def test_jointcalTask_fails_raise(self):
136 """Raise an exception if there is no data to process."""
137 self.configfiles.append(os.path.join(self.path, 'config/minSnr.py'))
138 with self.assertRaisesRegex(RuntimeError, "No data to process"):
139 self._runGen3Jointcal("lsst.obs.cfht.MegaPrime", "MegaPrime")
142class MemoryTester(lsst.utils.tests.MemoryTestCase):
143 pass
146if __name__ == "__main__": 146 ↛ 147line 146 didn't jump to line 147, because the condition on line 146 was never true
147 lsst.utils.tests.init()
148 unittest.main()