LSSTApplications  17.0+50,17.0+84,17.0+9,18.0.0+14,18.0.0+2,18.0.0+30,18.0.0+4,18.0.0+9,18.0.0-2-ge43143a+4,18.1.0-1-g0001055,18.1.0-1-g0896a44+6,18.1.0-1-g1349e88+4,18.1.0-1-g2505f39+3,18.1.0-1-g380d4d4+4,18.1.0-1-g5e4b7ea,18.1.0-1-g85f8cd4+3,18.1.0-1-g9a6769a+2,18.1.0-1-ga1a4c1a+2,18.1.0-1-gc037db8,18.1.0-1-gd55f500+1,18.1.0-1-ge10677a+3,18.1.0-10-g73b8679e+7,18.1.0-11-g311e899+3,18.1.0-12-g0d73a3591,18.1.0-12-gc95f69a+3,18.1.0-2-g000ad9a+3,18.1.0-2-g31c43f9+3,18.1.0-2-g9c63283+4,18.1.0-2-gdf0b915+4,18.1.0-2-gf03bb23,18.1.0-3-g2e29e3d+6,18.1.0-3-g52aa583+2,18.1.0-3-g9cb968e+3,18.1.0-4-gd2e8982+6,18.1.0-5-g510c42a+3,18.1.0-5-gaeab27e+4,18.1.0-6-gdda7f3e+6,18.1.0-7-g89824ecc+4,w.2019.32
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