1 from __future__
import absolute_import, division
24 from lsst.pex.config import Config, ListField, makeRegistry, ConfigDictField, ConfigurableField
25 from .geomLib
import IdentityXYTransform, InvertedXYTransform, \
26 AffineTransform, AffineXYTransform, RadialXYTransform, MultiXYTransform
28 __all__ = [
"xyTransformRegistry",
"OneXYTransformConfig"]
31 '''A registry of XYTransform factories
33 An XYTransform factory is a function that obeys these rules:
34 - has an attribute ConfigClass
35 - takes one argument, config (an instance of ConfigClass) by name
36 - returns an XYTransform
41 """Make an IdentityXYTransform (which has no config parameters)
43 return IdentityXYTransform()
44 makeIdentityTransform.ConfigClass = Config
45 xyTransformRegistry.register(
"identity", makeIdentityTransform)
48 transform = ConfigurableField(
49 doc =
"XYTransform factory",
50 target = makeIdentityTransform,
54 """Make an InvertedXYTransform
57 makeInvertedTransform.ConfigClass = OneXYTransformConfig
58 xyTransformRegistry.register(
"inverted", makeInvertedTransform)
63 doc =
"""2x2 linear matrix in the usual numpy order;
64 to rotate a vector by theta use: cos(theta), sin(theta), -sin(theta), cos(theta)""",
67 default = (1, 0, 0, 1),
69 translation = ListField(
70 doc =
"x, y translation vector",
76 """Make an AffineXYTransform
78 linear = numpy.array(config.linear)
80 translation = numpy.array(config.translation)
82 makeAffineXYTransform.ConfigClass = AffineXYTransformConfig
83 xyTransformRegistry.register(
"affine", makeAffineXYTransform)
88 doc =
"Coefficients for the radial polynomial; coeff[0] must be 0",
98 "invalid RadialXYTransform coeffs %s: " % (self.
coeffs,) \
99 +
" need len(coeffs)=0 or len(coeffs)>1, coeffs[0]==0, and coeffs[1]!=0")
101 """Make a RadialXYTransform
104 makeRadialXYTransform.ConfigClass = RadialXYTransformConfig
105 xyTransformRegistry.register(
"radial", makeRadialXYTransform)
109 transformDict = ConfigDictField(
110 doc =
"Dict of index: OneXYTransformConfig (a transform wrapper); key order is transform order",
112 itemtype = OneXYTransformConfig,
115 """Make an MultiXYTransform
117 transformKeys = sorted(config.transformDict.iterkeys())
118 transformList = [config.transformDict[key].transform.apply()
for key
in transformKeys]
120 makeMultiTransform.ConfigClass = MultiXYTransformConfig
121 xyTransformRegistry.register(
"multi", makeMultiTransform)