LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Classes | Functions
lsst.afw.geom.testUtils Namespace Reference

Classes

class  BoxGrid
 
class  FrameSetInfo
 
class  PermutedFrameSet
 
class  TransformTestBaseClass
 

Functions

def makeSipPolyMapCoeffs (metadata, name)
 
def makeSipIwcToPixel (metadata)
 
def makeSipPixelToIwc (metadata)
 

Function Documentation

◆ makeSipIwcToPixel()

def lsst.afw.geom.testUtils.makeSipIwcToPixel (   metadata)
Make an IWC to pixel transform with SIP distortion from FITS-WCS metadata

This function is primarily intended for unit tests.
IWC is intermediate world coordinates, as described in the FITS papers.

Parameters
----------
metadata : lsst.daf.base.PropertySet
    FITS metadata describing a WCS with inverse SIP coefficients

Returns
-------
lsst.afw.geom.TransformPoint2ToPoint2
    Transform from IWC position to pixel position (zero-based)
    in the forward direction. The inverse direction is not defined.

Notes
-----

The inverse SIP terms APn_m, BPn_m are polynomial coefficients x^n y^m
for computing transformed x, y respectively. If we call the resulting
polynomial inverseSipPolynomial, the returned transformation is:

    pixelPosition = pixel origin + uv + inverseSipPolynomial(uv)
    where uv = inverseCdMatrix * iwcPosition

Definition at line 198 of file testUtils.py.

198 def makeSipIwcToPixel(metadata):
199  """Make an IWC to pixel transform with SIP distortion from FITS-WCS metadata
200 
201  This function is primarily intended for unit tests.
202  IWC is intermediate world coordinates, as described in the FITS papers.
203 
204  Parameters
205  ----------
206  metadata : lsst.daf.base.PropertySet
207  FITS metadata describing a WCS with inverse SIP coefficients
208 
209  Returns
210  -------
211  lsst.afw.geom.TransformPoint2ToPoint2
212  Transform from IWC position to pixel position (zero-based)
213  in the forward direction. The inverse direction is not defined.
214 
215  Notes
216  -----
217 
218  The inverse SIP terms APn_m, BPn_m are polynomial coefficients x^n y^m
219  for computing transformed x, y respectively. If we call the resulting
220  polynomial inverseSipPolynomial, the returned transformation is:
221 
222  pixelPosition = pixel origin + uv + inverseSipPolynomial(uv)
223  where uv = inverseCdMatrix * iwcPosition
224  """
225  crpix = (metadata.getScalar("CRPIX1") - 1, metadata.getScalar("CRPIX2") - 1)
226  pixelRelativeToAbsoluteMap = ast.ShiftMap(crpix)
227  cdMatrix = getCdMatrixFromMetadata(metadata)
228  cdMatrixMap = ast.MatrixMap(cdMatrix.copy())
229  coeffList = makeSipPolyMapCoeffs(metadata, "AP") + makeSipPolyMapCoeffs(metadata, "BP")
230  coeffArr = np.array(coeffList, dtype=float)
231  sipPolyMap = ast.PolyMap(coeffArr, 2, "IterInverse=0")
232 
233  iwcToPixelMap = cdMatrixMap.inverted().then(sipPolyMap).then(pixelRelativeToAbsoluteMap)
234  return afwGeom.TransformPoint2ToPoint2(iwcToPixelMap)
235 
236 
Eigen::Matrix2d getCdMatrixFromMetadata(daf::base::PropertySet &metadata)
Read a CD matrix from FITS WCS metadata.
Definition: wcsUtils.cc:78
MatrixMap is a form of Mapping which performs a general linear transformation.
Definition: MatrixMap.h:42
ShiftMap is a linear Mapping which shifts each axis by a specified constant value.
Definition: ShiftMap.h:40
PolyMap is a Mapping which performs a general polynomial transformation.
Definition: PolyMap.h:49
def makeSipPolyMapCoeffs(metadata, name)
Definition: testUtils.py:143
def makeSipIwcToPixel(metadata)
Definition: testUtils.py:198
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67

◆ makeSipPixelToIwc()

def lsst.afw.geom.testUtils.makeSipPixelToIwc (   metadata)
Make a pixel to IWC transform with SIP distortion from FITS-WCS metadata

This function is primarily intended for unit tests.
IWC is intermediate world coordinates, as described in the FITS papers.

Parameters
----------
metadata : lsst.daf.base.PropertySet
    FITS metadata describing a WCS with forward SIP coefficients

Returns
-------
lsst.afw.geom.TransformPoint2ToPoint2
    Transform from pixel position (zero-based) to IWC position
    in the forward direction. The inverse direction is not defined.

Notes
-----

The forward SIP terms An_m, Bn_m are polynomial coefficients x^n y^m
for computing transformed x, y respectively. If we call the resulting
polynomial sipPolynomial, the returned transformation is:

    iwcPosition = cdMatrix * (dxy + sipPolynomial(dxy))
    where dxy = pixelPosition - pixelOrigin

Definition at line 237 of file testUtils.py.

237 def makeSipPixelToIwc(metadata):
238  """Make a pixel to IWC transform with SIP distortion from FITS-WCS metadata
239 
240  This function is primarily intended for unit tests.
241  IWC is intermediate world coordinates, as described in the FITS papers.
242 
243  Parameters
244  ----------
245  metadata : lsst.daf.base.PropertySet
246  FITS metadata describing a WCS with forward SIP coefficients
247 
248  Returns
249  -------
250  lsst.afw.geom.TransformPoint2ToPoint2
251  Transform from pixel position (zero-based) to IWC position
252  in the forward direction. The inverse direction is not defined.
253 
254  Notes
255  -----
256 
257  The forward SIP terms An_m, Bn_m are polynomial coefficients x^n y^m
258  for computing transformed x, y respectively. If we call the resulting
259  polynomial sipPolynomial, the returned transformation is:
260 
261  iwcPosition = cdMatrix * (dxy + sipPolynomial(dxy))
262  where dxy = pixelPosition - pixelOrigin
263  """
264  crpix = (metadata.getScalar("CRPIX1") - 1, metadata.getScalar("CRPIX2") - 1)
265  pixelAbsoluteToRelativeMap = ast.ShiftMap(crpix).inverted()
266  cdMatrix = getCdMatrixFromMetadata(metadata)
267  cdMatrixMap = ast.MatrixMap(cdMatrix.copy())
268  coeffList = makeSipPolyMapCoeffs(metadata, "A") + makeSipPolyMapCoeffs(metadata, "B")
269  coeffArr = np.array(coeffList, dtype=float)
270  sipPolyMap = ast.PolyMap(coeffArr, 2, "IterInverse=0")
271  pixelToIwcMap = pixelAbsoluteToRelativeMap.then(sipPolyMap).then(cdMatrixMap)
272  return afwGeom.TransformPoint2ToPoint2(pixelToIwcMap)
273 
274 
Eigen::Matrix2d getCdMatrixFromMetadata(daf::base::PropertySet &metadata)
Read a CD matrix from FITS WCS metadata.
Definition: wcsUtils.cc:78
MatrixMap is a form of Mapping which performs a general linear transformation.
Definition: MatrixMap.h:42
def makeSipPixelToIwc(metadata)
Definition: testUtils.py:237
ShiftMap is a linear Mapping which shifts each axis by a specified constant value.
Definition: ShiftMap.h:40
PolyMap is a Mapping which performs a general polynomial transformation.
Definition: PolyMap.h:49
def makeSipPolyMapCoeffs(metadata, name)
Definition: testUtils.py:143
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67

◆ makeSipPolyMapCoeffs()

def lsst.afw.geom.testUtils.makeSipPolyMapCoeffs (   metadata,
  name 
)
Return a list of ast.PolyMap coefficients for the specified SIP matrix

The returned list of coefficients for an ast.PolyMap
that computes the following function:

    f(dxy) = dxy + sipPolynomial(dxy))
    where dxy = pixelPosition - pixelOrigin
    and sipPolynomial is a polynomial with terms `<name>n_m for x^n y^m`
        (e.g. A2_0 is the coefficient for x^2 y^0)

Parameters
----------
metadata : lsst.daf.base.PropertySet
    FITS metadata describing a WCS with the specified SIP coefficients
name : str
    The desired SIP terms: one of A, B, AP, BP

Returns
-------
list
    A list of coefficients for an ast.PolyMap that computes
    the specified SIP polynomial, including a term for out = in

Note
----
This is an internal function for use by makeSipIwcToPixel
and makeSipPixelToIwc

Definition at line 143 of file testUtils.py.

143 def makeSipPolyMapCoeffs(metadata, name):
144  """Return a list of ast.PolyMap coefficients for the specified SIP matrix
145 
146  The returned list of coefficients for an ast.PolyMap
147  that computes the following function:
148 
149  f(dxy) = dxy + sipPolynomial(dxy))
150  where dxy = pixelPosition - pixelOrigin
151  and sipPolynomial is a polynomial with terms `<name>n_m for x^n y^m`
152  (e.g. A2_0 is the coefficient for x^2 y^0)
153 
154  Parameters
155  ----------
156  metadata : lsst.daf.base.PropertySet
157  FITS metadata describing a WCS with the specified SIP coefficients
158  name : str
159  The desired SIP terms: one of A, B, AP, BP
160 
161  Returns
162  -------
163  list
164  A list of coefficients for an ast.PolyMap that computes
165  the specified SIP polynomial, including a term for out = in
166 
167  Note
168  ----
169  This is an internal function for use by makeSipIwcToPixel
170  and makeSipPixelToIwc
171  """
172  outAxisDict = dict(A=1, B=2, AP=1, BP=2)
173  outAxis = outAxisDict.get(name)
174  if outAxis is None:
175  raise RuntimeError("%s not a supported SIP name" % (name,))
176  width = metadata.getAsInt("%s_ORDER" % (name,)) + 1
177  found = False
178  # start with a term for out = in
179  coeffs = []
180  if outAxis == 1:
181  coeffs.append([1.0, outAxis, 1, 0])
182  else:
183  coeffs.append([1.0, outAxis, 0, 1])
184  # add SIP distortion terms
185  for xPower in range(width):
186  for yPower in range(width):
187  coeffName = "%s_%s_%s" % (name, xPower, yPower)
188  if not metadata.exists(coeffName):
189  continue
190  found = True
191  coeff = metadata.getAsDouble(coeffName)
192  coeffs.append([coeff, outAxis, xPower, yPower])
193  if not found:
194  raise RuntimeError("No %s coefficients found" % (name,))
195  return coeffs
196 
197 
def makeSipPolyMapCoeffs(metadata, name)
Definition: testUtils.py:143