Coverage for tests/test_makeWarp.py: 27%
65 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-11 02:44 -0700
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-11 02:44 -0700
1# This file is part of pipe_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/>.
22import unittest
24import numpy as np
26import lsst.utils.tests
27import pytest
29import lsst.afw.image
30from lsst.pipe.tasks.makeWarp import (MakeWarpTask, MakeWarpConfig)
31from lsst.pipe.tasks.coaddBase import makeSkyInfo
32import lsst.skymap as skyMap
33from lsst.afw.detection import GaussianPsf
34import lsst.afw.cameraGeom.testUtils
37class MakeWarpTestCase(lsst.utils.tests.TestCase):
38 def setUp(self):
39 np.random.seed(12345)
41 self.config = MakeWarpConfig()
43 meanCalibration = 1e-4
44 calibrationErr = 1e-5
45 self.exposurePhotoCalib = lsst.afw.image.PhotoCalib(meanCalibration, calibrationErr)
46 # An external photoCalib calibration to return
47 self.externalPhotoCalib = lsst.afw.image.PhotoCalib(1e-6, 1e-8)
49 crpix = lsst.geom.Point2D(0, 0)
50 crval = lsst.geom.SpherePoint(0, 45, lsst.geom.degrees)
51 cdMatrix = lsst.afw.geom.makeCdMatrix(scale=1.0*lsst.geom.arcseconds)
52 self.skyWcs = lsst.afw.geom.makeSkyWcs(crpix, crval, cdMatrix)
53 externalCdMatrix = lsst.afw.geom.makeCdMatrix(scale=0.9*lsst.geom.arcseconds)
54 # An external skyWcs to return
55 self.externalSkyWcs = lsst.afw.geom.makeSkyWcs(crpix, crval, externalCdMatrix)
57 self.exposure = lsst.afw.image.ExposureF(10, 10)
58 self.exposure.maskedImage.image.array = np.random.random((10, 10)).astype(np.float32) * 1000
59 self.exposure.maskedImage.variance.array = np.random.random((10, 10)).astype(np.float32)
60 # mask at least one pixel
61 self.exposure.maskedImage.mask[5, 5] = 3
62 # set the PhotoCalib and Wcs objects of this exposure.
63 self.exposure.setPhotoCalib(lsst.afw.image.PhotoCalib(meanCalibration, calibrationErr))
64 self.exposure.setWcs(self.skyWcs)
65 self.exposure.setPsf(GaussianPsf(5, 5, 2.5))
66 self.exposure.setFilter(lsst.afw.image.FilterLabel(physical="fakeFilter", band="fake"))
68 self.visit = 100
69 self.detector = 5
70 detectorName = f"detector {self.detector}"
71 detector = lsst.afw.cameraGeom.testUtils.DetectorWrapper(name=detectorName, id=self.detector).detector
72 self.exposure.setDetector(detector)
74 simpleMapConfig = skyMap.discreteSkyMap.DiscreteSkyMapConfig()
75 simpleMapConfig.raList = [crval.getRa().asDegrees()]
76 simpleMapConfig.decList = [crval.getDec().asDegrees()]
77 simpleMapConfig.radiusList = [0.1]
79 self.simpleMap = skyMap.DiscreteSkyMap(simpleMapConfig)
80 self.tractId = 0
81 self.patchId = self.simpleMap[0].findPatch(crval).sequential_index
82 self.skyInfo = makeSkyInfo(self.simpleMap, self.tractId, self.patchId)
84 def test_makeWarp(self):
85 """Test basic MakeWarpTask."""
86 makeWarp = MakeWarpTask(config=self.config)
88 result = makeWarp.run(
89 calExpList=[self.exposure],
90 ccdIdList=[self.detector],
91 skyInfo=self.skyInfo,
92 visitId=self.visit,
93 dataIdList=[{'visit': self.visit, 'detector': self.detector}],
94 )
96 warp = result.exposures['direct']
98 # Ensure we got an exposure out
99 self.assertIsInstance(warp, lsst.afw.image.ExposureF)
100 # Ensure the warp has valid pixels
101 self.assertGreater(np.isfinite(warp.image.array.ravel()).sum(), 0)
102 # Ensure the warp has the correct WCS
103 self.assertEqual(warp.getWcs(), self.skyInfo.wcs)
105 def test_makeCoaddTempExp(self):
106 """Test deprecated MakeCoaddTempExp."""
107 from lsst.pipe.tasks.makeCoaddTempExp import (MakeWarpTask, MakeWarpConfig)
109 with pytest.warns(FutureWarning):
110 _ = MakeWarpTask(config=self.config)
112 with pytest.warns(FutureWarning):
113 _ = MakeWarpConfig()
116def setup_module(module):
117 lsst.utils.tests.init()
120class MatchMemoryTestCase(lsst.utils.tests.MemoryTestCase):
121 pass
124if __name__ == "__main__": 124 ↛ 125line 124 didn't jump to line 125, because the condition on line 124 was never true
125 lsst.utils.tests.init()
126 unittest.main()