Coverage for tests / test_make_psf_matched_warp.py: 50%
54 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 09:22 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 09:22 +0000
1# This file is part of drp_tasks.
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/>.
22from __future__ import annotations
24import copy
25import unittest
27import numpy as np
28from test_make_direct_warp import MakeWarpTestCase
30import lsst.afw.cameraGeom.testUtils
31import lsst.afw.image
32import lsst.pipe.base
33import lsst.utils.tests
34from lsst.drp.tasks.make_direct_warp import MakeDirectWarpTask, WarpDetectorInputs
35from lsst.drp.tasks.make_psf_matched_warp import MakePsfMatchedWarpTask
36from lsst.ip.diffim import (
37 ModelPsfMatchConfig,
38 ModelPsfMatchTask,
39 WarpedPsfTransformTooBigError,
40)
41from lsst.pipe.base import InMemoryDatasetHandle
44class MockPsfMatchConfig(ModelPsfMatchConfig):
45 pass
48class MockPsfMatchTask(ModelPsfMatchTask):
49 ConfigClass = MockPsfMatchConfig
51 def __init__(*args, **kwargs):
52 pass
54 def run(self, *args, **kwargs):
55 raise WarpedPsfTransformTooBigError("Mock error")
58class MakePsfMatchedWarpTestCase(MakeWarpTestCase):
59 def _make_warp(self):
60 dataRef = InMemoryDatasetHandle(self.exposure.clone(), dataId=self.dataId)
61 makeWarpConfig = copy.copy(self.config)
63 makeWarp = MakeDirectWarpTask(config=makeWarpConfig)
64 warp_detector_inputs = {
65 dataRef.dataId.detector.id: WarpDetectorInputs(exposure_or_handle=dataRef, data_id=dataRef.dataId)
66 }
67 result = makeWarp.run(warp_detector_inputs, sky_info=self.skyInfo, visit_summary=None)
69 return result.warp
71 def test_makeWarp(self):
72 """Test basic MakePsfMatchedWarpTask
74 This constructs a direct_warp using `MakeDirectWarpTask` and then
75 runs `MakePsfMatchedWarpTask` on it.
76 """
77 warp = self._make_warp()
78 config = MakePsfMatchedWarpTask.ConfigClass()
79 makePsfMatchedWarp = MakePsfMatchedWarpTask(config=config)
80 result = makePsfMatchedWarp.run(
81 warp,
82 bbox=self.skyInfo.bbox,
83 )
85 psf_matched_warp = result.psf_matched_warp
86 # Ensure we got an exposure out
87 self.assertIsInstance(psf_matched_warp, lsst.afw.image.ExposureF)
88 # Check that the PSF is not None.
89 psf = psf_matched_warp.getPsf()
90 assert psf is not None
91 # Ensure the warp has valid pixels
92 self.assertGreater(np.isfinite(psf_matched_warp.image.array.ravel()).sum(), 0)
94 def test_annotated_partial_outputs(self):
95 """Test that a failed PSF match generates an annotated error"""
96 warp = self._make_warp()
97 config = MakePsfMatchedWarpTask.ConfigClass()
98 makePsfMatchedWarp = MakePsfMatchedWarpTask(config=config)
99 mockConfig = MockPsfMatchConfig()
100 makePsfMatchedWarp.psfMatch = MockPsfMatchTask(config=mockConfig)
102 with self.assertRaises(lsst.pipe.base.AnnotatedPartialOutputsError):
103 makePsfMatchedWarp.run(
104 warp,
105 bbox=self.skyInfo.bbox,
106 )
109def setup_module(module):
110 lsst.utils.tests.init()
113class MatchMemoryTestCase(lsst.utils.tests.MemoryTestCase):
114 pass
117if __name__ == "__main__": 117 ↛ 118line 117 didn't jump to line 118 because the condition on line 117 was never true
118 lsst.utils.tests.init()
119 unittest.main()