Coverage for tests/test_transformMap.py : 25%
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
|
# # LSST Data Management System # Copyright 2014 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. # Tests for lsst.afw.cameraGeom.TransformMap """
"""Wrap a TransformMap transformation as a function(Point2D)->Point2D """
self.transformMap = transformMap self.fromSys = fromSys self.toSys = toSys
return self.transformMap.transform(point, self.fromSys, self.toSys)
"""Wrap a pair of function(Point2D)->Point2D functions as a single function that calls the first function, then the second function on the result """
self.func1 = func1 self.func2 = func2
return self.func2(self.func1(point))
"""Unity function(Point2D)->Point2D """ return point
self.nativeSys = cameraGeom.FOCAL_PLANE self.fieldTransform = afwGeom.makeRadialTransform([0, 0.5, 0.005]) transforms = {cameraGeom.FIELD_ANGLE: self.fieldTransform} self.transformMap = cameraGeom.TransformMap( self.nativeSys, transforms)
self.nativeSys = None self.fieldTransform = None self.transformMap = None
"""Test basic attributes """ for methodName in ("begin", "end", "contains", "size"): self.assertFalse(hasattr(self.transformMap, methodName))
self.assertIn(self.nativeSys, self.transformMap) self.assertIn(cameraGeom.FIELD_ANGLE, self.transformMap) self.assertNotIn(cameraGeom.CameraSys("garbage"), self.transformMap)
self.assertIn(self.nativeSys, self.transformMap) self.assertIn(cameraGeom.FIELD_ANGLE, self.transformMap)
"""Test round-trip through FITS I/O. """ with lsst.utils.tests.getTempFilePath(".fits") as filename: self.transformMap.writeFits(filename) transformMapOut = cameraGeom.TransformMap.readFits(filename) self.assertTransformMapsEqual(self.transformMap, transformMapOut)
"""Test iteration, len and indexing """ self.assertEqual(len(self.transformMap), 2)
systems = list(self.transformMap) self.assertEqual(len(systems), 2)
for cs in systems: self.assertIsInstance(cs, cameraGeom.CameraSys)
"""Test that the contained transforms are the ones expected """ nativeTr = self.transformMap.getTransform(self.nativeSys, self.nativeSys) self.compare2DFunctions(nativeTr.applyForward, unityTransform) self.compare2DFunctions(nativeTr.applyInverse, unityTransform)
fieldTr = self.transformMap.getTransform(self.nativeSys, cameraGeom.FIELD_ANGLE) self.compare2DFunctions(fieldTr.applyForward, self.fieldTransform.applyForward) self.compare2DFunctions(fieldTr.applyInverse, self.fieldTransform.applyInverse)
fieldTrInv = self.transformMap.getTransform(cameraGeom.FIELD_ANGLE, self.nativeSys) self.compare2DFunctions(fieldTrInv.applyForward, self.fieldTransform.applyInverse) self.compare2DFunctions(fieldTrInv.applyInverse, self.fieldTransform.applyForward)
missingCamSys = cameraGeom.CameraSys("missing") with self.assertRaises(lsst.pex.exceptions.Exception): self.transformMap.getTransform(missingCamSys, self.nativeSys) with self.assertRaises(lsst.pex.exceptions.Exception): self.transformMap.getTransform(self.nativeSys, missingCamSys)
"""Test transform method, point version """ for fromSys in self.transformMap: for toSys in self.transformMap: trConvFunc = TransformWrapper( self.transformMap, fromSys, toSys) if fromSys == toSys: self.compare2DFunctions(trConvFunc, unityTransform) funcPair = Composition( self.transformMap .getTransform(self.nativeSys, fromSys).applyInverse, self.transformMap .getTransform(self.nativeSys, toSys).applyForward ) self.compare2DFunctions(trConvFunc, funcPair)
"""Test transform method, list version """ fromList = [] for x in (-1.2, 0.0, 25.3): for y in (-23.4, 0.0, 2.3): fromList.append(lsst.geom.Point2D(x, y))
for fromSys in self.transformMap: for toSys in self.transformMap: toList = self.transformMap.transform(fromList, fromSys, toSys)
self.assertEqual(len(fromList), len(toList)) for fromPoint, toPoint in zip(fromList, toList): predToPoint = self.transformMap.transform( fromPoint, fromSys, toSys) self.assertPairsAlmostEqual(predToPoint, toPoint)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |