LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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