Coverage for tests/test_mkl_badness.py: 46%
40 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-22 03:00 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-22 03:00 -0700
1# This file is part of meas_extensions_psfex.
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 lsst.utils import getPackageDir
27from lsst.afw.table import SourceCatalog
28from lsst.afw.image import ExposureF
29from lsst.pipe.base import Task, TaskMetadata
30from lsst.meas.algorithms import MakePsfCandidatesTask, ReserveSourcesTask
31from lsst.meas.extensions.psfex.psfexPsfDeterminer import PsfexPsfDeterminerTask
34CONFIG_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), "config")
36try:
37 DATA_DIR = os.path.join(getPackageDir("afwdata"), "psfex")
38except LookupError:
39 DATA_DIR = None
42@unittest.skipUnless(DATA_DIR is not None, "afwdata is not setup")
43class TestMklBadness(unittest.TestCase):
44 """Test a particular visit/detector combination for which a bad PSF was
45 generated when PSFEx was run with MKL in the environment.
47 See DM-40066 for details.
48 """
50 def setUp(self) -> None:
51 self.stars = SourceCatalog.readFits(os.path.join(DATA_DIR, "stars.fits"))
52 self.exposure = ExposureF(os.path.join(DATA_DIR, "exposure.fits"))
53 makePsfCandidatesConfig = MakePsfCandidatesTask.ConfigClass()
54 makePsfCandidatesConfig.load(os.path.join(CONFIG_DIR, "make_psf_candidates.py"))
55 self.makePsfCandidates = MakePsfCandidatesTask(config=makePsfCandidatesConfig)
56 reserveSourcesConfig = ReserveSourcesTask.ConfigClass()
57 reserveSourcesConfig.load(os.path.join(CONFIG_DIR, "reserve_sources.py"))
58 # ResourceSourceTask.__init__ insists on adding a new column to the
59 # catalog, but this catalog already has that column; hack it.
60 self.reserve = ReserveSourcesTask.__new__(ReserveSourcesTask)
61 Task.__init__(self.reserve, config=reserveSourcesConfig)
62 self.reserve.columnName = "calib_psf"
63 self.reserve.key = self.stars.schema.find("calib_psf_reserved").key
64 psfDeterminerConfig = PsfexPsfDeterminerTask.ConfigClass()
65 psfDeterminerConfig.load(os.path.join(CONFIG_DIR, "psf_determiner.py"))
66 self.psfDeterminer = PsfexPsfDeterminerTask(config=psfDeterminerConfig, schema=self.stars.schema)
67 self.metadata = TaskMetadata()
69 def test_mkl_badness(self) -> None:
70 selectionResult = self.makePsfCandidates.run(self.stars, exposure=self.exposure)
71 reserveResult = self.reserve.run(selectionResult.goodStarCat, expId=3581242)
72 psfDeterminerList = [
73 cand
74 for cand, use in zip(selectionResult.psfCandidates, reserveResult.use)
75 if use
76 ]
77 self.psfDeterminer.determinePsf(
78 self.exposure, psfDeterminerList, self.metadata,
79 )
80 self.assertEqual(self.metadata.getScalar("numAvailStars"), 84)
81 self.assertEqual(self.metadata.getScalar("numGoodStars"), 77)
84if __name__ == "__main__": 84 ↛ 85line 84 didn't jump to line 85, because the condition on line 84 was never true
85 unittest.main()