22 from __future__
import absolute_import, division, print_function
24 __all__ = [
"BoxGrid",
"makeSipIwcToPixel",
"makeSipPixelToIwc"]
26 from builtins
import range
27 from builtins
import object
36 from numpy.testing
import assert_allclose, assert_array_equal
37 from astshim.test import makeForwardPolyMap, makeTwoWayPolyMap
40 from .box
import Box2I, Box2D
48 """Divide a box into nx by ny sub-boxes that tile the region 50 The sub-boxes will be of the same type as `box` and will exactly tile `box`; 51 they will also all be the same size, to the extent possible (some variation 52 is inevitable for integer boxes that cannot be evenly divided. 56 box : `lsst.afw.geom.Box2I` or `lsst.afw.geom.Box2D` 57 the box to subdivide; the boxes in the grid will be of the same type 58 numColRow : pair of `int` 59 number of columns and rows 63 if len(numColRow) != 2:
65 "numColRow=%r; must be a sequence of two integers" % (numColRow,))
66 self.
_numColRow = tuple(int(val)
for val
in numColRow)
68 if isinstance(box, Box2I):
70 elif isinstance(box, Box2D):
73 raise RuntimeError(
"Unknown class %s of box %s" % (type(box), box))
77 minPoint = box.getMin()
79 dtype = np.array(minPoint).dtype
81 self.
_divList = [np.linspace(start=box.getMin()[i],
85 dtype=dtype)
for i
in range(2)]
92 """Return the box at the specified x,y index 96 indXY : pair of `ints` 97 the x,y index to return 101 subBox : `lsst.afw.geom.Box2I` or `lsst.afw.geom.Box2D` 109 return self.shape[0]*self.shape[1]
112 """Return an iterator over all boxes, where column varies most quickly 120 """Information about a FrameSet 124 frameSet : `ast.FrameSet` 125 The FrameSet about which you want information 134 Index of current frame 135 isBaseSkyFrame : `bool` 136 Is the base frame an `ast.SkyFrame`? 137 isCurrSkyFrame : `bool` 138 Is the current frame an `ast.SkyFrame`? 148 """Return a list of ast.PolyMap coefficients for the specified SIP matrix 150 The returned list of coefficients for an ast.PolyMap 151 that computes the following function: 153 f(dxy) = dxy + sipPolynomial(dxy)) 154 where dxy = pixelPosition - pixelOrigin 155 and sipPolynomial is a polynomial with terms `<name>n_m for x^n y^m` 156 (e.g. A2_0 is the coefficient for x^2 y^0) 160 metadata : lsst.daf.base.PropertySet 161 FITS metadata describing a WCS with the specified SIP coefficients 163 The desired SIP terms: one of A, B, AP, BP 168 A list of coefficients for an ast.PolyMap that computes 169 the specified SIP polynomial, including a term for out = in 173 This is an internal function for use by makeSipIwcToPixel 174 and makeSipPixelToIwc 176 outAxisDict = dict(A=1, B=2, AP=1, BP=2)
177 outAxis = outAxisDict.get(name)
179 raise RuntimeError(
"%s not a supported SIP name" % (name,))
180 width = metadata.getAsInt(
"%s_ORDER" % (name,)) + 1
185 coeffs.append([1.0, outAxis, 1, 0])
187 coeffs.append([1.0, outAxis, 0, 1])
189 for xPower
in range(width):
190 for yPower
in range(width):
191 coeffName =
"%s_%s_%s" % (name, xPower, yPower)
192 if not metadata.exists(coeffName):
195 coeff = metadata.getAsDouble(coeffName)
196 coeffs.append([coeff, outAxis, xPower, yPower])
198 raise RuntimeError(
"No %s coefficients found" % (name,))
203 """Make an IWC to pixel transform with SIP distortion from FITS-WCS metadata 205 This function is primarily intended for unit tests. 206 IWC is intermediate world coordinates, as described in the FITS papers. 210 metadata : lsst.daf.base.PropertySet 211 FITS metadata describing a WCS with inverse SIP coefficients 215 lsst.afw.geom.TransformPoint2ToPoint2 216 Transform from IWC position to pixel position (zero-based) 217 in the forward direction. The inverse direction is not defined. 222 The inverse SIP terms APn_m, BPn_m are polynomial coefficients x^n y^m 223 for computing transformed x, y respectively. If we call the resulting 224 polynomial inverseSipPolynomial, the returned transformation is: 226 pixelPosition = pixel origin + uv + inverseSipPolynomial(uv) 227 where uv = inverseCdMatrix * iwcPosition 229 crpix = (metadata.get(
"CRPIX1") - 1, metadata.get(
"CRPIX2") - 1)
234 coeffArr = np.array(coeffList, dtype=float)
235 sipPolyMap =
ast.PolyMap(coeffArr, 2,
"IterInverse=0")
237 iwcToPixelMap = cdMatrixMap.getInverse().
then(sipPolyMap).
then(pixelRelativeToAbsoluteMap)
242 """Make a pixel to IWC transform with SIP distortion from FITS-WCS metadata 244 This function is primarily intended for unit tests. 245 IWC is intermediate world coordinates, as described in the FITS papers. 249 metadata : lsst.daf.base.PropertySet 250 FITS metadata describing a WCS with forward SIP coefficients 254 lsst.afw.geom.TransformPoint2ToPoint2 255 Transform from pixel position (zero-based) to IWC position 256 in the forward direction. The inverse direction is not defined. 261 The forward SIP terms An_m, Bn_m are polynomial coefficients x^n y^m 262 for computing transformed x, y respectively. If we call the resulting 263 polynomial sipPolynomial, the returned transformation is: 265 iwcPosition = cdMatrix * (dxy + sipPolynomial(dxy)) 266 where dxy = pixelPosition - pixelOrigin 268 crpix = (metadata.get(
"CRPIX1") - 1, metadata.get(
"CRPIX2") - 1)
269 pixelAbsoluteToRelativeMap =
ast.ShiftMap(crpix).getInverse()
273 coeffArr = np.array(coeffList, dtype=float)
274 sipPolyMap =
ast.PolyMap(coeffArr, 2,
"IterInverse=0")
275 pixelToIwcMap = pixelAbsoluteToRelativeMap.then(sipPolyMap).
then(cdMatrixMap)
280 """A FrameSet with base or current frame possibly permuted, with associated 283 Only two-axis frames will be permuted. 287 frameSet : `ast.FrameSet` 288 The FrameSet you wish to permute. A deep copy is made. 290 Permute the base frame's axes? 292 Permute the current frame's axes? 297 If you try to permute a frame that does not have 2 axes 303 frameSet : `ast.FrameSet` 304 The FrameSet that may be permuted. A local copy is made. 305 isBaseSkyFrame : `bool` 306 Is the base frame an `ast.SkyFrame`? 307 isCurrSkyFrame : `bool` 308 Is the current frame an `ast.SkyFrame`? 309 isBasePermuted : `bool` 310 Are the base frame axes permuted? 311 isCurrPermuted : `bool` 312 Are the current frame axes permuted? 314 def __init__(self, frameSet, permuteBase, permuteCurr):
320 baseNAxes = self.
frameSet.getFrame(fsInfo.baseInd).nAxes
322 raise RuntimeError(
"Base frame has {} axes; 2 required to permute".format(baseNAxes))
323 self.
frameSet.current = fsInfo.baseInd
325 self.
frameSet.current = fsInfo.currInd
327 currNAxes = self.
frameSet.getFrame(fsInfo.currInd).nAxes
329 raise RuntimeError(
"Current frame has {} axes; 2 required to permute".format(currNAxes))
330 assert self.
frameSet.getFrame(fsInfo.currInd).nAxes == 2
337 """Base class for unit tests of Transform<X>To<Y> 339 Subclasses must call `TransformTestBaseClass.setUp(self)` 340 if they provide their own version. 342 If a package other than afw uses this class then it must 343 override the `getTestDir` method to avoid writing into 344 afw's test directory. 348 """Return a directory where temporary test files can be written 350 The default implementation returns the test directory of the `afw` 353 If this class is used by a test in a package other than `afw` 354 then the subclass must override this method. 361 Subclasses should call this method if they override setUp. 373 "Generic": (1, 2, 3, 4),
383 "SpherePoint": (1, 3, 4),
396 """Make an array of generic point data 398 The data will be suitable for spherical points 403 Number of points in the array 405 Number of axes in the point 409 np.array of floats with shape (nAxes, nPoints) 410 The values are as follows; if nAxes != 2: 411 The first point has values `[0, delta, 2*delta, ..., (nAxes-1)*delta]` 412 The Nth point has those values + N 413 if nAxes == 2 then the data is scaled so that the max value of axis 1 414 is a bit less than pi/2 418 oneAxis = np.arange(nPoints, dtype=float)
420 rawData = np.array([j * delta + oneAxis
for j
in range(nAxes)], dtype=float)
424 maxLatitude = np.max(rawData[1])
425 rawData *= math.pi * 0.4999 / maxLatitude
430 """Make one generic point 435 Number of axes in the point 437 Increment between axis values 441 A list of `nAxes` floats with values `[0, delta, ..., (nAxes-1)*delta] 443 return [i*delta
for i
in range(nAxes)]
452 Endpoint class name prefix; the full class name is name + "Endpoint" 453 nAxes : `int` or `None`, optional 454 number of axes; an int is required if `name` == "Generic"; 459 subclass of `lsst.afw.geom.BaseEndpoint` 460 The constructed endpoint 465 If `name` == "Generic" and `nAxes` is None or <= 0 467 EndpointClassName = name +
"Endpoint" 468 EndpointClass = getattr(afwGeom, EndpointClassName)
469 if name ==
"Generic":
471 raise TypeError(
"nAxes must be an integer for GenericEndpoint")
472 return EndpointClass(nAxes)
473 return EndpointClass()
477 """Return the appropriate frame for the given name and nAxes 482 Endpoint class name prefix; the full class name is name + "Endpoint" 483 nAxes : `int` or `None`, optional 484 number of axes; an int is required if `name` == "Generic"; 490 The constructed frame 495 If `name` == "Generic" and `nAxes` is `None` or <= 0 501 """Return a list of 0 or more frames that are not a valid match for the 507 Endpoint class name prefix; the full class name is name + "Endpoint" 511 Collection of `ast.Frame` 512 A collection of 0 or more frames 531 The FrameSet will contain 4 frames and three transforms connecting them. 532 The idenity of each frame is provided by self.frameIdentDict 534 Frame Index Mapping from this frame to the next 535 `baseFrame` 1 `ast.UnitMap(nIn)` 536 Frame(nIn) 2 `polyMap` 537 Frame(nOut) 3 `ast.UnitMap(nOut)` 541 - `nIn` = `baseFrame.nAxes` 542 - `nOut` = `currFrame.nAxes` 543 - `polyMap` = `makeTwoWayPolyMap(nIn, nOut)` 548 The FrameSet as described above 552 baseFrame : `ast.Frame` 554 currFrame : `ast.Frame` 557 nIn = baseFrame.nAxes
558 nOut = currFrame.nAxes
559 polyMap = makeTwoWayPolyMap(nIn, nOut)
563 baseFrame = baseFrame.copy()
565 currFrame = currFrame.copy()
571 frameSet.addFrame(ast.FrameSet.CURRENT,
ast.UnitMap(nIn), frame2)
574 frameSet.addFrame(ast.FrameSet.CURRENT, polyMap, frame3)
575 frameSet.addFrame(ast.FrameSet.CURRENT,
ast.UnitMap(nOut), currFrame)
580 """Iterator over 0 or more frameSets with SkyFrames axes permuted 582 Only base and current SkyFrames are permuted. If neither the base nor 583 the current frame is a SkyFrame then no frames are returned. 587 iterator over `PermutedFrameSet` 591 if not (fsInfo.isBaseSkyFrame
or fsInfo.isCurrSkyFrame):
594 permuteBaseList = [
False,
True]
if fsInfo.isBaseSkyFrame
else [
False]
595 permuteCurrList = [
False,
True]
if fsInfo.isCurrSkyFrame
else [
False]
596 for permuteBase
in permuteBaseList:
597 for permuteCurr
in permuteCurrList:
602 """Make a Jacobian matrix for the equation described by 608 the dimensions of the input and output data; see makeTwoWayPolyMap 609 inPoint : `numpy.ndarray` 610 an array of size `nIn` representing the point at which the Jacobian 616 an `nOut` x `nIn` array of first derivatives 618 basePolyMapCoeff = 0.001
619 baseCoeff = 2.0 * basePolyMapCoeff
620 coeffs = np.empty((nOut, nIn))
621 for iOut
in range(nOut):
622 coeffOffset = baseCoeff * iOut
623 for iIn
in range(nIn):
624 coeffs[iOut, iIn] = baseCoeff * (iIn + 1) + coeffOffset
625 coeffs[iOut, iIn] *= inPoint[iIn]
626 assert coeffs.ndim == 2
628 assert coeffs.shape == (nOut, nIn)
632 """Check applyForward and applyInverse for a transform 636 transform : `lsst.afw.geom.Transform` 637 The transform to check 638 mapping : `ast.Mapping` 639 The mapping the transform should use. This mapping 640 must contain valid forward or inverse transformations, 641 but they need not match if both present. Hence the 642 mappings returned by make*PolyMap are acceptable. 644 Error message suffix describing test parameters 646 fromEndpoint = transform.fromEndpoint
647 toEndpoint = transform.toEndpoint
648 mappingFromTransform = transform.getMapping()
652 self.assertEqual(nIn, fromEndpoint.nAxes, msg=msg)
653 self.assertEqual(nOut, toEndpoint.nAxes, msg=msg)
657 inPoint = fromEndpoint.pointFromData(rawInPoint)
662 inArray = fromEndpoint.arrayFromData(rawInArray)
664 if mapping.hasForward:
665 self.assertTrue(transform.hasForward)
666 outPoint = transform.applyForward(inPoint)
667 rawOutPoint = toEndpoint.dataFromPoint(outPoint)
668 assert_allclose(rawOutPoint, mapping.applyForward(rawInPoint), err_msg=msg)
669 assert_allclose(rawOutPoint, mappingFromTransform.applyForward(rawInPoint), err_msg=msg)
671 outArray = transform.applyForward(inArray)
672 rawOutArray = toEndpoint.dataFromArray(outArray)
673 self.assertFloatsAlmostEqual(rawOutArray, mapping.applyForward(rawInArray), msg=msg)
674 self.assertFloatsAlmostEqual(rawOutArray, mappingFromTransform.applyForward(rawInArray), msg=msg)
678 outPoint = toEndpoint.pointFromData(rawOutPoint)
680 outArray = toEndpoint.arrayFromData(rawOutArray)
682 self.assertFalse(transform.hasForward)
684 if mapping.hasInverse:
685 self.assertTrue(transform.hasInverse)
689 inversePoint = transform.applyInverse(outPoint)
690 rawInversePoint = fromEndpoint.dataFromPoint(inversePoint)
691 assert_allclose(rawInversePoint, mapping.applyInverse(rawOutPoint), err_msg=msg)
692 assert_allclose(rawInversePoint, mappingFromTransform.applyInverse(rawOutPoint), err_msg=msg)
697 inverseArray = transform.applyInverse(outArray)
698 rawInverseArray = fromEndpoint.dataFromArray(inverseArray)
699 self.assertFloatsAlmostEqual(rawInverseArray, mapping.applyInverse(rawOutArray), msg=msg)
700 self.assertFloatsAlmostEqual(rawInverseArray, mappingFromTransform.applyInverse(rawOutArray),
703 self.assertFalse(transform.hasInverse)
706 """Check that two Transforms are each others' inverses. 710 forward : `lsst.afw.geom.Transform` 711 the reference Transform to test 712 inverse : `lsst.afw.geom.Transform` 713 the transform that should be the inverse of `forward` 715 error message suffix describing test parameters 717 fromEndpoint = forward.fromEndpoint
718 toEndpoint = forward.toEndpoint
719 forwardMapping = forward.getMapping()
720 inverseMapping = inverse.getMapping()
723 self.assertEqual(forward.fromEndpoint,
724 inverse.toEndpoint, msg=msg)
725 self.assertEqual(forward.toEndpoint,
726 inverse.fromEndpoint, msg=msg)
727 self.assertEqual(forward.hasForward, inverse.hasInverse, msg=msg)
728 self.assertEqual(forward.hasInverse, inverse.hasForward, msg=msg)
734 inPoint = fromEndpoint.pointFromData(rawInPoint)
736 outPoint = toEndpoint.pointFromData(rawOutPoint)
741 inArray = fromEndpoint.arrayFromData(rawInArray)
743 outArray = toEndpoint.arrayFromData(rawOutArray)
745 if forward.hasForward:
746 self.assertEqual(forward.applyForward(inPoint),
747 inverse.applyInverse(inPoint), msg=msg)
748 self.assertEqual(forwardMapping.applyForward(rawInPoint),
749 inverseMapping.applyInverse(rawInPoint), msg=msg)
751 assert_array_equal(forward.applyForward(inArray),
752 inverse.applyInverse(inArray),
754 assert_array_equal(forwardMapping.applyForward(rawInArray),
755 inverseMapping.applyInverse(rawInArray),
758 if forward.hasInverse:
759 self.assertEqual(forward.applyInverse(outPoint),
760 inverse.applyForward(outPoint), msg=msg)
761 self.assertEqual(forwardMapping.applyInverse(rawOutPoint),
762 inverseMapping.applyForward(rawOutPoint), msg=msg)
763 assert_array_equal(forward.applyInverse(outArray),
764 inverse.applyForward(outArray),
766 assert_array_equal(forwardMapping.applyInverse(rawOutArray),
767 inverseMapping.applyForward(rawOutArray),
771 """Check Transform_<fromName>_<toName> using the Mapping constructor 775 fromName, toName : `str` 776 Endpoint name prefix for "from" and "to" endpoints, respectively, 777 e.g. "Point2" for `lsst.afw.geom.Point2Endpoint` 778 fromAxes, toAxes : `int` 779 number of axes in fromFrame and toFrame, respectively 781 transformClassName =
"Transform{}To{}".format(fromName, toName)
782 TransformClass = getattr(afwGeom, transformClassName)
783 baseMsg =
"TransformClass={}".format(TransformClass.__name__)
786 for nIn, nOut
in itertools.product(self.
goodNAxes[fromName],
788 msg =
"{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
789 polyMap = makeTwoWayPolyMap(nIn, nOut)
790 transform = TransformClass(polyMap)
793 desStr =
"{}[{}->{}]".format(transformClassName, nIn, nOut)
794 self.assertEqual(
"{}".format(transform), desStr)
795 self.assertEqual(repr(transform),
"lsst.afw.geom." + desStr)
800 polyMap = makeForwardPolyMap(nIn, nOut)
801 transform = TransformClass(polyMap)
805 polyMap = makeForwardPolyMap(nOut, nIn).getInverse()
806 transform = TransformClass(polyMap)
810 for nIn, badNOut
in itertools.product(self.
goodNAxes[fromName],
812 badPolyMap = makeTwoWayPolyMap(nIn, badNOut)
813 msg =
"{}, nIn={}, badNOut={}".format(baseMsg, nIn, badNOut)
814 with self.assertRaises(InvalidParameterError, msg=msg):
815 TransformClass(badPolyMap)
818 for badNIn, nOut
in itertools.product(self.
badNAxes[fromName],
820 badPolyMap = makeTwoWayPolyMap(badNIn, nOut)
821 msg =
"{}, badNIn={}, nOut={}".format(baseMsg, nIn, nOut)
822 with self.assertRaises(InvalidParameterError, msg=msg):
823 TransformClass(badPolyMap)
826 """Check Transform_<fromName>_<toName> using the FrameSet constructor 830 fromName, toName : `str` 831 Endpoint name prefix for "from" and "to" endpoints, respectively, 832 e.g. "Point2" for `lsst.afw.geom.Point2Endpoint` 834 transformClassName =
"Transform{}To{}".format(fromName, toName)
835 TransformClass = getattr(afwGeom, transformClassName)
836 baseMsg =
"TransformClass={}".format(TransformClass.__name__)
837 for nIn, nOut
in itertools.product(self.
goodNAxes[fromName],
839 msg =
"{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
844 self.assertEqual(frameSet.nFrame, 4)
848 badFrameSet = self.
makeFrameSet(badBaseFrame, currFrame)
849 with self.assertRaises(InvalidParameterError):
850 TransformClass(badFrameSet)
852 reallyBadFrameSet = self.
makeFrameSet(badBaseFrame, badCurrFrame)
853 with self.assertRaises(InvalidParameterError):
854 TransformClass(reallyBadFrameSet)
856 badFrameSet = self.
makeFrameSet(baseFrame, badCurrFrame)
857 with self.assertRaises(InvalidParameterError):
858 TransformClass(badFrameSet)
860 transform = TransformClass(frameSet)
862 desStr =
"{}[{}->{}]".format(transformClassName, nIn, nOut)
863 self.assertEqual(
"{}".format(transform), desStr)
864 self.assertEqual(repr(transform),
"lsst.afw.geom." + desStr)
868 mappingFromTransform = transform.getMapping()
869 transformCopy = TransformClass(mappingFromTransform)
870 self.assertEqual(type(transform), type(transformCopy))
871 self.assertEqual(transform.getMapping(), mappingFromTransform)
873 polyMap = makeTwoWayPolyMap(nIn, nOut)
883 if permutedFS.isBaseSkyFrame:
884 baseFrame = permutedFS.frameSet.getFrame(ast.FrameSet.BASE)
886 desBaseLonAxis = 2
if permutedFS.isBasePermuted
else 1
887 self.assertEqual(baseFrame.lonAxis, desBaseLonAxis)
888 if permutedFS.isCurrSkyFrame:
889 currFrame = permutedFS.frameSet.getFrame(ast.FrameSet.CURRENT)
891 desCurrLonAxis = 2
if permutedFS.isCurrPermuted
else 1
892 self.assertEqual(currFrame.lonAxis, desCurrLonAxis)
894 permTransform = TransformClass(permutedFS.frameSet)
898 """Test Transform<fromName>To<toName>.getInverse 902 fromName, toName : `str` 903 Endpoint name prefix for "from" and "to" endpoints, respectively, 904 e.g. "Point2" for `lsst.afw.geom.Point2Endpoint` 906 transformClassName =
"Transform{}To{}".format(fromName, toName)
907 TransformClass = getattr(afwGeom, transformClassName)
908 baseMsg =
"TransformClass={}".format(TransformClass.__name__)
909 for nIn, nOut
in itertools.product(self.
goodNAxes[fromName],
911 msg =
"{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
914 makeTwoWayPolyMap(nIn, nOut),
915 "{}, Map={}".format(msg,
"TwoWay"))
918 makeForwardPolyMap(nIn, nOut),
919 "{}, Map={}".format(msg,
"Forward"))
922 makeForwardPolyMap(nOut, nIn).getInverse(),
923 "{}, Map={}".format(msg,
"Inverse"))
926 """Test Transform<fromName>To<toName>.getInverse for a specific 931 TransformClass : `type` 932 The class of transform to test, such as TransformPoint2ToPoint2 933 mapping : `ast.Mapping` 934 The mapping to use for the transform 938 transform = TransformClass(mapping)
939 inverse = transform.getInverse()
940 inverseInverse = inverse.getInverse()
947 """Test Transform<fromName>To<toName>.getJacobian 951 fromName, toName : `str` 952 Endpoint name prefix for "from" and "to" endpoints, respectively, 953 e.g. "Point2" for `lsst.afw.geom.Point2Endpoint` 955 transformClassName =
"Transform{}To{}".format(fromName, toName)
956 TransformClass = getattr(afwGeom, transformClassName)
957 baseMsg =
"TransformClass={}".format(TransformClass.__name__)
958 for nIn, nOut
in itertools.product(self.
goodNAxes[fromName],
960 msg =
"{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
961 polyMap = makeForwardPolyMap(nIn, nOut)
962 transform = TransformClass(polyMap)
963 fromEndpoint = transform.fromEndpoint
967 inPoint = fromEndpoint.pointFromData(rawInPoint)
968 jacobian = transform.getJacobian(inPoint)
969 assert_allclose(jacobian, self.
makeJacobian(nIn, nOut, rawInPoint),
973 inPoint = fromEndpoint.pointFromData(rawInPoint)
974 jacobian = transform.getJacobian(inPoint)
975 assert_allclose(jacobian, self.
makeJacobian(nIn, nOut, rawInPoint),
979 """Test Transform<fromName>To<midName>.then(Transform<midName>To<toName>) 984 the prefix of the starting endpoint (e.g., "Point2" for a 985 Point2Endpoint) for the final, concatenated Transform 987 the prefix for the shared endpoint where two Transforms will be 990 the prefix of the ending endpoint for the final, concatenated 993 TransformClass1 = getattr(afwGeom,
994 "Transform{}To{}".format(fromName, midName))
995 TransformClass2 = getattr(afwGeom,
996 "Transform{}To{}".format(midName, toName))
997 baseMsg =
"{}.then({})".format(TransformClass1.__name__,
998 TransformClass2.__name__)
999 for nIn, nMid, nOut
in itertools.product(self.
goodNAxes[fromName],
1002 msg =
"{}, nIn={}, nMid={}, nOut={}".format(
1003 baseMsg, nIn, nMid, nOut)
1004 polyMap1 = makeTwoWayPolyMap(nIn, nMid)
1005 transform1 = TransformClass1(polyMap1)
1006 polyMap2 = makeTwoWayPolyMap(nMid, nOut)
1007 transform2 = TransformClass2(polyMap2)
1008 transform = transform1.then(transform2)
1010 fromEndpoint = transform1.fromEndpoint
1011 toEndpoint = transform2.toEndpoint
1014 outPointMerged = transform.applyForward(inPoint)
1015 outPointSeparate = transform2.applyForward(
1016 transform1.applyForward(inPoint))
1017 assert_allclose(toEndpoint.dataFromPoint(outPointMerged),
1018 toEndpoint.dataFromPoint(outPointSeparate),
1022 inPointMerged = transform.applyInverse(outPoint)
1023 inPointSeparate = transform1.applyInverse(
1024 transform2.applyInverse(outPoint))
1026 fromEndpoint.dataFromPoint(inPointMerged),
1027 fromEndpoint.dataFromPoint(inPointSeparate),
1031 if midName ==
"Generic":
1034 polyMap = makeTwoWayPolyMap(nIn, 3)
1035 transform1 = TransformClass1(polyMap)
1036 polyMap = makeTwoWayPolyMap(2, nOut)
1037 transform2 = TransformClass2(polyMap)
1038 with self.assertRaises(InvalidParameterError):
1039 transform = transform1.then(transform2)
1042 if fromName != midName:
1045 joinNAxes =
set(self.
goodNAxes[fromName]).intersection(
1048 for nIn, nMid, nOut
in itertools.product(self.
goodNAxes[fromName],
1051 polyMap = makeTwoWayPolyMap(nIn, nMid)
1052 transform1 = TransformClass1(polyMap)
1053 polyMap = makeTwoWayPolyMap(nMid, nOut)
1054 transform2 = TransformClass1(polyMap)
1055 with self.assertRaises(InvalidParameterError):
1056 transform = transform1.then(transform2)
1059 """Assert that two transforms are equal""" 1060 self.assertEqual(type(transform1), type(transform2))
1061 self.assertEqual(transform1.fromEndpoint, transform2.fromEndpoint)
1062 self.assertEqual(transform1.toEndpoint, transform2.toEndpoint)
1063 self.assertEqual(transform1.getMapping(), transform2.getMapping())
1065 fromEndpoint = transform1.fromEndpoint
1066 toEndpoint = transform1.toEndpoint
1067 mapping = transform1.getMapping()
1071 if mapping.hasForward:
1074 inArray = fromEndpoint.arrayFromData(rawInArray)
1075 outArray = transform1.applyForward(inArray)
1076 outData = toEndpoint.dataFromArray(outArray)
1077 outArrayRoundTrip = transform2.applyForward(inArray)
1078 outDataRoundTrip = toEndpoint.dataFromArray(outArrayRoundTrip)
1079 assert_allclose(outData, outDataRoundTrip)
1081 if mapping.hasInverse:
1084 outArray = toEndpoint.arrayFromData(rawOutArray)
1085 inArray = transform1.applyInverse(outArray)
1086 inData = fromEndpoint.dataFromArray(inArray)
1087 inArrayRoundTrip = transform2.applyInverse(outArray)
1088 inDataRoundTrip = fromEndpoint.dataFromArray(inArrayRoundTrip)
1089 assert_allclose(inData, inDataRoundTrip)
1092 """Check persistence of a transform 1094 className = type(transform).__name__
1097 transformStr = transform.writeString()
1098 serialVersion, serialClassName, serialRest = transformStr.split(
" ", 2)
1099 self.assertEqual(int(serialVersion), 1)
1100 self.assertEqual(serialClassName, className)
1101 badStr1 =
" ".join([
"2", serialClassName, serialRest])
1103 transform.readString(badStr1)
1104 badClassName =
"x" + serialClassName
1105 badStr2 =
" ".join([
"1", badClassName, serialRest])
1107 transform.readString(badStr2)
1108 transformFromStr1 = transform.readString(transformStr)
1112 transformFromStr2 = afwGeom.transformFromString(transformStr)
1120 transform.writeFits(filename)
def __init__(self, frameSet, permuteBase, permuteCurr)
Eigen::Matrix2d getCdMatrixFromMetadata(daf::base::PropertySet &metadata)
Read a CD matrix from FITS WCS metadata.
def __init__(self, frameSet)
std::string getPackageDir(std::string const &packageName)
def makeSipPixelToIwc(metadata)
def __getitem__(self, indXY)
def getTempFilePath(ext, expectOutput=True)
def __init__(self, box, numColRow)
def makeSipPolyMapCoeffs(metadata, name)
def makeSipIwcToPixel(metadata)
daf::base::PropertySet * set