LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
transformConfig.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 import functools
24 import numpy
25 
26 import lsst.geom
27 from lsst.pex.config import Config, ListField, makeRegistry, \
28  ConfigDictField, ConfigurableField
29 from .transformFactory import makeTransform, makeIdentityTransform, \
30  makeRadialTransform
31 
32 __all__ = ["transformRegistry", "OneTransformConfig", "TransformConfig",
33  "IdentityTransformConfig", "AffineTransformConfig", "RadialTransformConfig",
34  "MultiTransformConfig"]
35 
36 transformRegistry = makeRegistry(
37  """"A registry of ``Transform`` factories
38 
39  A ``Transform`` factory is a function that obeys these rules:
40  - has an attribute ``ConfigClass``
41  - takes one argument, ``config`` (an instance of ``ConfigClass``) by name
42  - returns a ``Transform``
43  """
44 )
45 
46 
48  """A Config representing a ``Transform`` that does nothing.
49 
50  See Also
51  --------
52  lsst.afw.geom.makeIdentityTransform
53  """
54  pass
55 
56 
57 def identityFactory(config):
58  """Make an identity ``Transform``
59  """
60  return makeIdentityTransform()
61 
62 
63 identityFactory.ConfigClass = IdentityTransformConfig
64 transformRegistry.register("identity", identityFactory)
65 
66 
68  """A Config representing a single ``Transform`` in a compound ``Transform``.
69 
70  See Also
71  --------
72  lsst.afw.geom.MultiTransformConfig
73  """
74  transform = ConfigurableField(
75  doc="Transform factory",
76  target=identityFactory,
77  )
78 
79 
80 def invertingFactory(config):
81  """Invert a ``Transform`` specified by config.
82  """
83  return config.transform.apply().inverted()
84 
85 
86 invertingFactory.ConfigClass = OneTransformConfig
87 transformRegistry.register("inverted", invertingFactory)
88 
89 
91  """A Config representing an affine ``Transform``.
92 
93  See Also
94  --------
95  lsst.afw.geom.makeTransform
96  """
97  linear = ListField(
98  doc="2x2 linear matrix in the usual numpy order; "
99  "to rotate a vector by theta use: cos(theta), sin(theta), "
100  "-sin(theta), cos(theta)",
101  dtype=float,
102  length=4,
103  default=(1, 0, 0, 1),
104  )
105  translation = ListField(
106  doc="x, y translation vector",
107  dtype=float,
108  length=2,
109  default=(0, 0),
110  )
111 
112 
113 def affineFactory(config):
114  """Make an affine ``Transform``
115  """
116  linear = numpy.array(config.linear)
117  linear.shape = (2, 2)
118  translation = numpy.array(config.translation)
119  return makeTransform(lsst.geom.AffineTransform(linear, translation))
120 
121 
122 affineFactory.ConfigClass = AffineTransformConfig
123 transformRegistry.register("affine", affineFactory)
124 
125 
127  """A Config representing a radially symmetric ``Transform``.
128 
129  See Also
130  --------
131  lsst.afw.geom.makeRadialTransform
132  """
133  coeffs = ListField(
134  doc="Coefficients for the radial polynomial; coeff[0] must be 0",
135  dtype=float,
136  minLength=1,
137  optional=False,
138  )
139 
140  def validate(self):
141  if len(self.coeffs) == 0:
142  return
143  if len(self.coeffs) == 1 or self.coeffs[0] != 0 or self.coeffs[1] == 0:
144  raise RuntimeError(
145  f"invalid radial transform coeffs {self.coeffs}: "
146  "need len(coeffs)=0 or len(coeffs)>1, coeffs[0]==0, "
147  "and coeffs[1]!=0")
148 
149 
150 def radialFactory(config):
151  """Make a radial ``Transform``
152  """
153  return makeRadialTransform(config.coeffs._list)
154 
155 
156 radialFactory.ConfigClass = RadialTransformConfig
157 transformRegistry.register("radial", radialFactory)
158 
159 
161  """A Config representing a chain of consecutive ``Transforms``.
162  """
163  transformDict = ConfigDictField(
164  doc="Dict of index: OneTransformConfig (a transform wrapper); "
165  "key order is transform order",
166  keytype=int,
167  itemtype=OneTransformConfig,
168  )
169 
170 
171 def multiFactory(config):
172  """Concatenate multiple ``Transforms``
173  """
174  transformKeys = sorted(config.transformDict.keys())
175  transformList = [config.transformDict[key].transform.apply()
176  for key in transformKeys]
177 
178  # Can't use then(self, other) directly because no single Transform class
179  def concat(transform1, transform2):
180  return transform1.then(transform2)
181 
182  return functools.reduce(concat, transformList)
183 
184 
185 multiFactory.ConfigClass = MultiTransformConfig
186 transformRegistry.register("multi", multiFactory)
187 
188 
190  """Config that identifies ``Transforms`` by keyword.
191 
192  Supported configs:
193 
194  ``"identity"``
195  `IdentityTransformConfig`
196  ``"inverted"``
197  `OneTransformConfig`
198  ``"affine"``
199  `AffineTransformConfig`
200  ``"radial"``
201  `RadialTransformConfig`
202  ``"multi"``
203  `MultiTransformConfig`
204  """
205  transform = transformRegistry.makeField(
206  doc="a Transform from the registry"
207  )
lsst::afw::geom.transformConfig.affineFactory
def affineFactory(config)
Definition: transformConfig.py:113
lsst::afw::geom.transformConfig.radialFactory
def radialFactory(config)
Definition: transformConfig.py:150
lsst.pex.config.listField.ListField
Definition: listField.py:216
lsst::afw::geom.transformConfig.RadialTransformConfig.validate
def validate(self)
Definition: transformConfig.py:140
lsst::afw::geom.transformConfig.identityFactory
def identityFactory(config)
Definition: transformConfig.py:57
lsst::afw::geom::makeRadialTransform
std::shared_ptr< TransformPoint2ToPoint2 > makeRadialTransform(std::vector< double > const &coeffs)
A purely radial polynomial distortion.
Definition: transformFactory.cc:165
lsst.pex.config.configurableField.ConfigurableField
Definition: configurableField.py:170
lsst::afw::geom.transformConfig.IdentityTransformConfig
Definition: transformConfig.py:47
lsst::afw::geom.transformConfig.multiFactory
def multiFactory(config)
Definition: transformConfig.py:171
lsst::geom::AffineTransform
An affine coordinate transformation consisting of a linear transformation and an offset.
Definition: AffineTransform.h:75
lsst.pex.config.registry.makeRegistry
def makeRegistry(doc, configBaseType=Config)
Definition: registry.py:336
lsst::afw::geom.transformConfig.RadialTransformConfig
Definition: transformConfig.py:126
lsst.pex.config
Definition: __init__.py:1
lsst.pex.config.configDictField.ConfigDictField
Definition: configDictField.py:92
lsst::afw::geom.transformConfig.OneTransformConfig
Definition: transformConfig.py:67
lsst::afw::geom.transformConfig.TransformConfig
Definition: transformConfig.py:189
lsst::afw::geom.transformConfig.MultiTransformConfig
Definition: transformConfig.py:160
lsst::geom
Definition: AffineTransform.h:36
lsst::afw::geom.transformConfig.AffineTransformConfig
Definition: transformConfig.py:90
lsst.pex.config.config.Config
Definition: config.py:736
lsst::afw::geom.transformConfig.invertingFactory
def invertingFactory(config)
Definition: transformConfig.py:80
lsst::afw::geom::makeIdentityTransform
std::shared_ptr< TransformPoint2ToPoint2 > makeIdentityTransform()
Trivial Transform x → x.
Definition: transformFactory.cc:214
lsst::afw::geom.transformConfig.RadialTransformConfig.coeffs
coeffs
Definition: transformConfig.py:133
lsst::afw::geom::makeTransform
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.
Definition: transformFactory.cc:154