LSSTApplications  11.0-24-g0a022a1,14.0+64,15.0,15.0+1,15.0-1-g14e9bfd,15.0-1-g1eca518,15.0-1-g499c38d,15.0-1-g60afb23,15.0-1-g6668b0b,15.0-1-g788a293,15.0-1-g82223af,15.0-1-ga91101e,15.0-1-gae1598d,15.0-1-gc45031d,15.0-1-gd076f1f,15.0-1-gf4f1c34,15.0-1-gfe1617d,15.0-16-g953e39cab,15.0-2-g2010ef9,15.0-2-g33d94b3,15.0-2-g5218728,15.0-2-g947dc0d,15.0-3-g9103c06,15.0-3-ga03b4ca,15.0-3-ga659d1f3,15.0-3-ga695220+2,15.0-3-gaec6799,15.0-3-gb7a597c,15.0-3-gd5b9ff95,15.0-4-g0478fed+2,15.0-4-g45f767a,15.0-4-gff20472+2,15.0-6-ge2d9597
LSSTDataManagementBasePackage
xyTransformFactory.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
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 .xyTransform import IdentityXYTransform, InvertedXYTransform, RadialXYTransform, \
26  MultiXYTransform, AffineXYTransform
27 from .affineTransform import AffineTransform
28 
29 __all__ = ["xyTransformRegistry", "OneXYTransformConfig"]
30 
31 xyTransformRegistry = makeRegistry(
32  '''A registry of XYTransform factories
33 
34  .. note:: Deprecated in 14.0
35  Will be removed in 15.0; it is superseded by
36  afw.geom.transformRegistry.
37 
38  An XYTransform factory is a function that obeys these rules:
39  - has an attribute ConfigClass
40  - takes one argument, config (an instance of ConfigClass) by name
41  - returns an XYTransform
42  '''
43 )
44 
45 
46 def makeIdentityTransform(config=None):
47  """Make an IdentityXYTransform (which has no config parameters)
48  """
49  return IdentityXYTransform()
50 
51 
52 makeIdentityTransform.ConfigClass = Config
53 xyTransformRegistry.register("identity", makeIdentityTransform)
54 
55 
57  '''Specifies a dependent XYTransform for creating InvertedXYTransform and
58  MultiXYTransform.
59 
60  .. note:: Deprecated in 14.0
61  Will be removed in 15.0; it is superseded by
62  afw.geom.OneTransformConfig.
63  '''
64  transform = ConfigurableField(
65  doc="XYTransform factory",
66  target=makeIdentityTransform,
67  )
68 
69 
71  """Make an InvertedXYTransform
72  """
73  return InvertedXYTransform(config.transform.apply())
74 
75 
76 makeInvertedTransform.ConfigClass = OneXYTransformConfig
77 xyTransformRegistry.register("inverted", makeInvertedTransform)
78 
79 
81  linear = ListField(
82  doc="""2x2 linear matrix in the usual numpy order;
83  to rotate a vector by theta use: cos(theta), sin(theta), -sin(theta), cos(theta)""",
84  dtype=float,
85  length=4,
86  default=(1, 0, 0, 1),
87  )
88  translation = ListField(
89  doc="x, y translation vector",
90  dtype=float,
91  length=2,
92  default=(0, 0),
93  )
94 
95 
96 def affineFactory(config):
97  """Make an AffineXYTransform
98  """
99  linear = numpy.array(config.linear)
100  linear.shape = (2, 2)
101  translation = numpy.array(config.translation)
102  return AffineXYTransform(AffineTransform(linear, translation))
103 
104 
105 affineFactory.ConfigClass = AffineTransformConfig
106 xyTransformRegistry.register("affine", affineFactory)
107 
108 
110  coeffs = ListField(
111  doc="Coefficients for the radial polynomial; coeff[0] must be 0",
112  dtype=float,
113  minLength=1,
114  optional=False,
115  )
116 
117  def validate(self):
118  if len(self.coeffs) == 0:
119  return
120  if len(self.coeffs) == 1 or self.coeffs[0] != 0 or self.coeffs[1] == 0:
121  raise RuntimeError(
122  "invalid RadialXYTransform coeffs %s: " % (self.coeffs,) +
123  " need len(coeffs)=0 or len(coeffs)>1, coeffs[0]==0, and coeffs[1]!=0")
124 
125 
126 def radialFactory(config):
127  """Make a RadialXYTransform
128  """
129  return RadialXYTransform(config.coeffs._list)
130 
131 
132 radialFactory.ConfigClass = RadialTransformConfig
133 xyTransformRegistry.register("radial", radialFactory)
134 
135 
137  transformDict = ConfigDictField(
138  doc="Dict of index: OneXYTransformConfig (a transform wrapper); key order is transform order",
139  keytype=int,
140  itemtype=OneXYTransformConfig,
141  )
142 
143 
144 def multiFactory(config):
145  """Make an MultiXYTransform
146  """
147  transformKeys = sorted(config.transformDict.keys())
148  transformList = [config.transformDict[key].transform.apply()
149  for key in transformKeys]
150  return MultiXYTransform(transformList)
151 
152 
153 multiFactory.ConfigClass = MultiTransformConfig
154 xyTransformRegistry.register("multi", multiFactory)
def makeRegistry(doc, configBaseType=Config)
Definition: registry.py:214
Wrap a sequence of multiple XYTransforms.
Definition: XYTransform.h:158
Wrap an AffineTransform.
Definition: XYTransform.h:185