Coverage for tests/test_addDistortionModel.py : 37%

Hot-keys 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#
2# LSST Data Management System
3# Copyright 2018 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
22import unittest
24import lsst.utils.tests
25import lsst.geom
26import lsst.afw.geom as afwGeom
27from lsst.afw.image import ExposureF, ExposureInfo, PhotoCalib, VisitInfo
28from lsst.afw.geom.wcsUtils import makeDistortedTanWcs
29from lsst.afw.cameraGeom import FIELD_ANGLE, FOCAL_PLANE, PIXELS
30from lsst.afw.cameraGeom.testUtils import DetectorWrapper, CameraWrapper
31from lsst.afw.geom.utils import wcsAlmostEqualOverBBox
32from lsst.ip.isr import IsrTask
33import lsst.ip.isr.isrFunctions as isrFunctions
36class AddDistortionModelTestCase(lsst.utils.tests.TestCase):
37 """Test IsrTask.addDistortionModel.
39 DEPRECATED: to be removed with addDistortionModel
40 """
42 def setUp(self):
43 self.camera = CameraWrapper().camera
44 self.detector = DetectorWrapper().detector
45 self.crpix = lsst.geom.Point2D(50, 100)
46 self.crval = lsst.geom.SpherePoint(36, 71, lsst.geom.degrees)
47 scale = 1.0*lsst.geom.arcseconds
48 self.cdMatrix = afwGeom.makeCdMatrix(scale=scale)
49 self.wcs = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=self.cdMatrix)
50 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-10, 10), lsst.geom.Extent2I(1000, 1022))
51 self.exposure = ExposureF(self.bbox)
53 # set the few items of ExposureInfo needed by IsrTask.run
54 # when only adding a distortion model
55 exposureInfo = ExposureInfo(photoCalib=PhotoCalib(1.0),
56 detector=self.detector,
57 visitInfo=VisitInfo(exposureTime=1.0),
58 wcs=self.wcs)
60 self.exposure.setInfo(exposureInfo)
62 def tearDown(self):
63 self.detector = None
64 self.exposure = None
66 def testAddDistortionMethod(self):
67 """Call IsrTask.addDistortionModel directly"""
68 isrFunctions.addDistortionModel(self.exposure, self.camera)
69 self.assertFalse(wcsAlmostEqualOverBBox(self.wcs, self.exposure.getWcs(), self.bbox))
71 desiredWcs = self.makeDesiredDistortedWcs()
72 self.assertWcsAlmostEqualOverBBox(desiredWcs, self.exposure.getWcs(), self.bbox)
74 def makeMinimalIsrConfig(self):
75 """Return an IsrConfig with all boolean flags disabled"""
76 isrConfig = IsrTask.ConfigClass()
77 for name in isrConfig:
78 if name.startswith("do"):
79 setattr(isrConfig, name, False)
80 return isrConfig
82 def makeDesiredDistortedWcs(self):
83 """Make the expected distorted WCS"""
84 pixelToFocalPlane = self.detector.getTransform(PIXELS, FOCAL_PLANE)
85 focalPlaneToFieldAngle = self.camera.getTransformMap().getTransform(FOCAL_PLANE, FIELD_ANGLE)
86 return makeDistortedTanWcs(self.wcs, pixelToFocalPlane, focalPlaneToFieldAngle)
88 def testRunWithoutAddDistortionModel(self):
89 """Test IsrTask.run with config.doAddDistortionModel false"""
90 isrConfig = self.makeMinimalIsrConfig()
91 isrTask = IsrTask(config=isrConfig)
93 # the camera argument is not needed
94 exposure = isrTask.run(ccdExposure=self.exposure).exposure
95 self.assertEqual(self.wcs, exposure.getWcs())
97 # and the camera argument is ignored if provided
98 exposure2 = isrTask.run(ccdExposure=self.exposure, camera=self.camera).exposure
99 self.assertEqual(self.wcs, exposure2.getWcs())
102class MemoryTester(lsst.utils.tests.MemoryTestCase):
103 pass
106def setup_module(module):
107 lsst.utils.tests.init()
110if __name__ == "__main__": 110 ↛ 111line 110 didn't jump to line 111, because the condition on line 110 was never true
111 lsst.utils.tests.init()
112 unittest.main()