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