LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
xyTransformFactory.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 import numpy
24 from lsst.pex.config import Config, ListField, makeRegistry, ConfigDictField, ConfigurableField
25 from .geomLib import IdentityXYTransform, InvertedXYTransform, \
26  AffineTransform, AffineXYTransform, RadialXYTransform, MultiXYTransform
27 
28 __all__ = ["xyTransformRegistry", "OneXYTransformConfig"]
29 
30 xyTransformRegistry = makeRegistry(
31  '''A registry of XYTransform factories
32 
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
37  '''
38 )
39 
40 def makeIdentityTransform(config=None):
41  """Make an IdentityXYTransform (which has no config parameters)
42  """
43  return IdentityXYTransform()
44 makeIdentityTransform.ConfigClass = Config
45 xyTransformRegistry.register("identity", makeIdentityTransform)
46 
47 class OneXYTransformConfig(Config):
48  transform = ConfigurableField(
49  doc = "XYTransform factory",
50  target = makeIdentityTransform,
51  )
52 
54  """Make an InvertedXYTransform
55  """
56  return InvertedXYTransform(config.transform.apply())
57 makeInvertedTransform.ConfigClass = OneXYTransformConfig
58 xyTransformRegistry.register("inverted", makeInvertedTransform)
59 
60 
62  linear = ListField(
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)""",
65  dtype = float,
66  length = 4,
67  default = (1, 0, 0, 1),
68  )
69  translation = ListField(
70  doc = "x, y translation vector",
71  dtype = float,
72  length = 2,
73  default = (0, 0),
74  )
76  """Make an AffineXYTransform
77  """
78  linear = numpy.array(config.linear)
79  linear.shape = (2,2)
80  translation = numpy.array(config.translation)
81  return AffineXYTransform(AffineTransform(linear, translation))
82 makeAffineXYTransform.ConfigClass = AffineXYTransformConfig
83 xyTransformRegistry.register("affine", makeAffineXYTransform)
84 
85 
87  coeffs = ListField(
88  doc = "Coefficients for the radial polynomial; coeff[0] must be 0",
89  dtype = float,
90  minLength = 1,
91  optional = False,
92  )
93  def validate(self):
94  if len(self.coeffs) == 0:
95  return
96  if len(self.coeffs) == 1 or self.coeffs[0] != 0 or self.coeffs[1] == 0:
97  raise RuntimeError(
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
102  """
103  return RadialXYTransform(config.coeffs)
104 makeRadialXYTransform.ConfigClass = RadialXYTransformConfig
105 xyTransformRegistry.register("radial", makeRadialXYTransform)
106 
107 
109  transformDict = ConfigDictField(
110  doc = "Dict of index: OneXYTransformConfig (a transform wrapper); key order is transform order",
111  keytype = int,
112  itemtype = OneXYTransformConfig,
113  )
114 def makeMultiTransform(config):
115  """Make an MultiXYTransform
116  """
117  transformKeys = sorted(config.transformDict.iterkeys())
118  transformList = [config.transformDict[key].transform.apply() for key in transformKeys]
119  return MultiXYTransform(transformList)
120 makeMultiTransform.ConfigClass = MultiXYTransformConfig
121 xyTransformRegistry.register("multi", makeMultiTransform)
122 
Wrap an XYTransform, swapping forward and reverse transforms.
Definition: XYTransform.h:107
An affine coordinate transformation consisting of a linear transformation and an offset.
A purely radial polynomial distortion, up to 6th order.
Definition: XYTransform.h:186
Wrap a sequence of multiple XYTransforms.
Definition: XYTransform.h:133
Wrap an AffineTransform.
Definition: XYTransform.h:152