22 """Python helpers for pybind11 wrapping of Transform classes and subclasses
24 .. _pybind11_transform_classes:
26 Transform Classes and Subclasses
27 --------------------------------
29 Transforms are instances of
30 lsst::afw::geom::Transform<FromEndpoint, ToEndpoint>
31 and subclasses, such as lsst::afw::geom::SkyWcs.
33 In Python the templated Transform classes have names such as
34 `lsst.afw.geom.TransformIcrsCoordToPoint2` for
35 `lsst::afw::geom::Transform<IcrsCoordEndpoint, Point2Endpoint>`
38 from __future__
import absolute_import, division, print_function
40 __all__ = [
"addTransformMethods",
"transformRegistry"]
42 import lsst.pex.exceptions
45 transformRegistry = {}
50 matrix = self._getJacobian(x)
51 matrix.shape = (self.toEndpoint.nAxes,
52 self.fromEndpoint.nAxes)
57 """Concatenate two transforms
59 The result of A.then(B) is is C(x) = B(A(x))
61 if self.toEndpoint == next.fromEndpoint:
62 return self._then(next)
64 raise lsst.pex.exceptions.InvalidParameterError(
65 "Cannot concatenate %r and %r: endpoints do not match."
70 """Save this @ref pybind11_transform "Transform" to the specified file
72 className = type(self).__name__
73 bodyText = self.getFrameSet().
show()
74 with open(path,
"w")
as outFile:
75 outFile.write(className +
"\n")
76 outFile.write(bodyText)
80 """Add pure python methods to the specified Transform class, and register
81 the class in `transformRegistry`
83 All :ref:`_pybind11_transform_classes` must call this function.
87 cls : :ref:`_pybind11_transform_classes`
88 A Transform class or subclass, e.g.
89 `lsst.afw.geom.TransformPoint2ToIcrsCoord`
91 global transformRegistry
92 className = cls.__name__
93 if className
in transformRegistry:
94 raise RuntimeError(
"Class %r=%s already registered; cannot register class %s" %
95 (className, transformRegistry[className], cls))
96 transformRegistry[cls.__name__] = cls
97 cls.getJacobian = getJacobian
99 cls.saveToFile = saveToFile