lsst.afw  14.0-52-g19103d347
testUtils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2016 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 from __future__ import absolute_import, division, print_function
23 
24 __all__ = ["BoxGrid", "makeSipIwcToPixel", "makeSipPixelToIwc"]
25 
26 from builtins import range
27 from builtins import object
28 
29 import itertools
30 import math
31 import os
32 import pickle
33 
34 import astshim as ast
35 import numpy as np
36 from numpy.testing import assert_allclose, assert_array_equal
37 from astshim.test import makeForwardPolyMap, makeTwoWayPolyMap
38 import lsst.afw.coord # required to use IcrsCoordEndpoint
39 from lsst.afw.geom.wcsUtils import getCdMatrixFromMetadata
40 
41 from .box import Box2I, Box2D
42 import lsst.afw.geom as afwGeom
43 from lsst.pex.exceptions import InvalidParameterError
44 import lsst.utils
45 import lsst.utils.tests
46 
47 
48 class BoxGrid(object):
49  """!Divide a box into nx by ny sub-boxes that tile the region
50  """
51 
52  def __init__(self, box, numColRow):
53  """!Construct a BoxGrid
54 
55  The sub-boxes will be of the same type as `box` and will exactly tile `box`;
56  they will also all be the same size, to the extent possible (some variation
57  is inevitable for integer boxes that cannot be evenly divided.
58 
59  @param[in] box box (an lsst.afw.geom.Box2I or Box2D);
60  the boxes in the grid will be of the same type
61  @param[in] numColRow number of columns and rows (a pair of ints)
62  """
63  if len(numColRow) != 2:
64  raise RuntimeError(
65  "numColRow=%r; must be a sequence of two integers" % (numColRow,))
66  self._numColRow = tuple(int(val) for val in numColRow)
67 
68  if isinstance(box, Box2I):
69  stopDelta = 1
70  elif isinstance(box, Box2D):
71  stopDelta = 0
72  else:
73  raise RuntimeError("Unknown class %s of box %s" % (type(box), box))
74  self.boxClass = type(box)
75  self.stopDelta = stopDelta
76 
77  minPoint = box.getMin()
78  self.pointClass = type(minPoint)
79  dtype = np.array(minPoint).dtype
80 
81  self._divList = [np.linspace(start=box.getMin()[i],
82  stop=box.getMax()[i] + self.stopDelta,
83  num=self._numColRow[i] + 1,
84  endpoint=True,
85  dtype=dtype) for i in range(2)]
86 
87  @property
88  def numColRow(self):
89  return self._numColRow
90 
91  def __getitem__(self, indXY):
92  """!Return the box at the specified x,y index (a pair of ints)
93  """
94  beg = self.pointClass(*[self._divList[i][indXY[i]] for i in range(2)])
95  end = self.pointClass(
96  *[self._divList[i][indXY[i] + 1] - self.stopDelta for i in range(2)])
97  return self.boxClass(beg, end)
98 
99  def __len__(self):
100  return self.shape[0]*self.shape[1]
101 
102  def __iter__(self):
103  """!Return an iterator over all boxes, where column varies most quickly
104  """
105  for row in range(self.numColRow[1]):
106  for col in range(self.numColRow[0]):
107  yield self[col, row]
108 
109 
110 class FrameSetInfo(object):
111  """Information about a FrameSet
112 
113  Attributes
114  ----------
115  baseInd : `int`
116  Index of base frame
117  currInd : `int`
118  Index of current frame
119  isBaseSkyFrame : `bool`
120  Is the base frame an `ast.SkyFrame`?
121  isCurrSkyFrame : `bool`
122  Is the current frame an `ast.SkyFrame`?
123  """
124  def __init__(self, frameSet):
125  """Construct a FrameSetInfo
126 
127  Parameters
128  ----------
129  frameSet : `ast.FrameSet`
130  The FrameSet about which you want information
131  """
132  self.baseInd = frameSet.base
133  self.currInd = frameSet.current
134  self.isBaseSkyFrame = frameSet.getFrame(self.baseInd).className == "SkyFrame"
135  self.isCurrSkyFrame = frameSet.getFrame(self.currInd).className == "SkyFrame"
136 
137 
138 def makeSipPolyMapCoeffs(metadata, name):
139  """Return a list of ast.PolyMap coefficients for the specified SIP matrix
140 
141  The returned list of coefficients for an ast.PolyMap
142  that computes the following function:
143 
144  f(dxy) = dxy + sipPolynomial(dxy))
145  where dxy = pixelPosition - pixelOrigin
146  and sipPolynomial is a polynomial with terms `<name>n_m for x^n y^m`
147  (e.g. A2_0 is the coefficient for x^2 y^0)
148 
149  Parameters
150  ----------
151  metadata : lsst.daf.base.PropertySet
152  FITS metadata describing a WCS with the specified SIP coefficients
153  name : str
154  The desired SIP terms: one of A, B, AP, BP
155 
156  Returns
157  -------
158  list
159  A list of coefficients for an ast.PolyMap that computes
160  the specified SIP polynomial, including a term for out = in
161 
162  Note
163  ----
164  This is an internal function for use by makeSipIwcToPixel
165  and makeSipPixelToIwc
166  """
167  outAxisDict = dict(A=1, B=2, AP=1, BP=2)
168  outAxis = outAxisDict.get(name)
169  if outAxis is None:
170  raise RuntimeError("%s not a supported SIP name" % (name,))
171  width = metadata.getAsInt("%s_ORDER" % (name,)) + 1
172  found = False
173  # start with a term for out = in
174  coeffs = []
175  if outAxis == 1:
176  coeffs.append([1.0, outAxis, 1, 0])
177  else:
178  coeffs.append([1.0, outAxis, 0, 1])
179  # add SIP distortion terms
180  for xPower in range(width):
181  for yPower in range(width):
182  coeffName = "%s_%s_%s" % (name, xPower, yPower)
183  if not metadata.exists(coeffName):
184  continue
185  found = True
186  coeff = metadata.getAsDouble(coeffName)
187  coeffs.append([coeff, outAxis, xPower, yPower])
188  if not found:
189  raise RuntimeError("No %s coefficients found" % (name,))
190  return coeffs
191 
192 
193 def makeSipIwcToPixel(metadata):
194  """Make an IWC to pixel transform with SIP distortion from FITS-WCS metadata
195 
196  This function is primarily intended for unit tests.
197  IWC is intermediate world coordinates, as described in the FITS papers.
198 
199  Parameters
200  ----------
201  metadata : lsst.daf.base.PropertySet
202  FITS metadata describing a WCS with inverse SIP coefficients
203 
204  Returns
205  -------
206  lsst.afw.geom.TransformPoint2ToPoint2
207  Transform from IWC position to pixel position (zero-based)
208  in the forward direction. The inverse direction is not defined.
209 
210  Notes
211  -----
212 
213  The inverse SIP terms APn_m, BPn_m are polynomial coefficients x^n y^m
214  for computing transformed x, y respectively. If we call the resulting
215  polynomial inverseSipPolynomial, the returned transformation is:
216 
217  pixelPosition = pixel origin + uv + inverseSipPolynomial(uv)
218  where uv = inverseCdMatrix * iwcPosition
219  """
220  crpix = (metadata.get("CRPIX1") - 1, metadata.get("CRPIX2") - 1)
221  pixelRelativeToAbsoluteMap = ast.ShiftMap(crpix)
222  cdMatrix = getCdMatrixFromMetadata(metadata)
223  cdMatrixMap = ast.MatrixMap(cdMatrix.copy())
224  coeffList = makeSipPolyMapCoeffs(metadata, "AP") + makeSipPolyMapCoeffs(metadata, "BP")
225  coeffArr = np.array(coeffList, dtype=float)
226  sipPolyMap = ast.PolyMap(coeffArr, 2, "IterInverse=0")
227 
228  iwcToPixelMap = cdMatrixMap.getInverse().then(sipPolyMap).then(pixelRelativeToAbsoluteMap)
229  return afwGeom.TransformPoint2ToPoint2(iwcToPixelMap)
230 
231 
232 def makeSipPixelToIwc(metadata):
233  """Make a pixel to IWC transform with SIP distortion from FITS-WCS metadata
234 
235  This function is primarily intended for unit tests.
236  IWC is intermediate world coordinates, as described in the FITS papers.
237 
238  Parameters
239  ----------
240  metadata : lsst.daf.base.PropertySet
241  FITS metadata describing a WCS with forward SIP coefficients
242 
243  Returns
244  -------
245  lsst.afw.geom.TransformPoint2ToPoint2
246  Transform from pixel position (zero-based) to IWC position
247  in the forward direction. The inverse direction is not defined.
248 
249  Notes
250  -----
251 
252  The forward SIP terms An_m, Bn_m are polynomial coefficients x^n y^m
253  for computing transformed x, y respectively. If we call the resulting
254  polynomial sipPolynomial, the returned transformation is:
255 
256  iwcPosition = cdMatrix * (dxy + sipPolynomial(dxy))
257  where dxy = pixelPosition - pixelOrigin
258  """
259  crpix = (metadata.get("CRPIX1") - 1, metadata.get("CRPIX2") - 1)
260  pixelAbsoluteToRelativeMap = ast.ShiftMap(crpix).getInverse()
261  cdMatrix = getCdMatrixFromMetadata(metadata)
262  cdMatrixMap = ast.MatrixMap(cdMatrix.copy())
263  coeffList = makeSipPolyMapCoeffs(metadata, "A") + makeSipPolyMapCoeffs(metadata, "B")
264  coeffArr = np.array(coeffList, dtype=float)
265  sipPolyMap = ast.PolyMap(coeffArr, 2, "IterInverse=0")
266  pixelToIwcMap = pixelAbsoluteToRelativeMap.then(sipPolyMap).then(cdMatrixMap)
267  return afwGeom.TransformPoint2ToPoint2(pixelToIwcMap)
268 
269 
270 class PermutedFrameSet(object):
271  """A FrameSet with base or current frame possibly permuted, with associated
272  information
273 
274  Only two-axis frames will be permuted.
275 
276  Attributes
277  ----------
278  frameSet : `ast.FrameSet`
279  The FrameSet that may be permuted. A local copy is made.
280  isBaseSkyFrame : `bool`
281  Is the base frame an `ast.SkyFrame`?
282  isCurrSkyFrame : `bool`
283  Is the current frame an `ast.SkyFrame`?
284  isBasePermuted : `bool`
285  Are the base frame axes permuted?
286  isCurrPermuted : `bool`
287  Are the current frame axes permuted?
288  """
289  def __init__(self, frameSet, permuteBase, permuteCurr):
290  """Construct a PermutedFrameSet
291 
292  Make a copy of a FrameSet and permute the base and/or current frames if
293  requested
294 
295  Parameters
296  ----------
297  frameSet : `ast.FrameSet`
298  The FrameSet you wish to permute. A deep copy is made.
299  permuteBase : `bool`
300  Permute the base frame's axes?
301  permuteCurr : `bool`
302  Permute the current frame's axes?
303 
304  Raises
305  ------
306  `RuntimeError`
307  If you try to permute a frame that does not have 2 axes
308  """
309  self.frameSet = frameSet.copy()
310  fsInfo = FrameSetInfo(self.frameSet)
311  self.isBaseSkyFrame = fsInfo.isBaseSkyFrame
312  self.isCurrSkyFrame = fsInfo.isCurrSkyFrame
313  if permuteBase:
314  baseNAxes = self.frameSet.getFrame(fsInfo.baseInd).nAxes
315  if baseNAxes != 2:
316  raise RuntimeError("Base frame has {} axes; 2 required to permute".format(baseNAxes))
317  self.frameSet.current = fsInfo.baseInd
318  self.frameSet.permAxes([2, 1])
319  self.frameSet.current = fsInfo.currInd
320  if permuteCurr:
321  currNAxes = self.frameSet.getFrame(fsInfo.currInd).nAxes
322  if currNAxes != 2:
323  raise RuntimeError("Current frame has {} axes; 2 required to permute".format(currNAxes))
324  assert self.frameSet.getFrame(fsInfo.currInd).nAxes == 2
325  self.frameSet.permAxes([2, 1])
326  self.isBasePermuted = permuteBase
327  self.isCurrPermuted = permuteCurr
328 
329 
331  """Base class for unit tests of Transform<X>To<Y>
332 
333  Subclasses must call `TransformTestBaseClass.setUp(self)`
334  if they provide their own version.
335 
336  If a package other than afw uses this class then it must
337  override the `getTestDir` method to avoid writing into
338  afw's test directory.
339  """
340 
341  def getTestDir(self):
342  """Return a directory where temporary test files can be written
343 
344  The default implementation returns the test directory of the `afw`
345  package.
346 
347  If this class is used by a test in a package other than `afw`
348  then the subclass must override this method.
349  """
350  return os.path.join(lsst.utils.getPackageDir("afw"), "tests")
351 
352  def setUp(self):
353  """Set up a test
354 
355  Subclasses should call this method if they override setUp.
356  """
357  # tell unittest to use the msg argument of asserts as a supplement
358  # to the error message, rather than as the whole error message
359  self.longMessage = True
360 
361  # list of endpoint class name prefixes; the full name is prefix + "Endpoint"
362  self.endpointPrefixes = ("Generic", "Point2", "IcrsCoord")
363 
364  # GoodNAxes is dict of endpoint class name prefix:
365  # tuple containing 0 or more valid numbers of axes
366  self.goodNAxes = {
367  "Generic": (1, 2, 3, 4), # all numbers of axes are valid for GenericEndpoint
368  "Point2": (2,),
369  "IcrsCoord": (2,),
370  }
371 
372  # BadAxes is dict of endpoint class name prefix:
373  # tuple containing 0 or more invalid numbers of axes
374  self.badNAxes = {
375  "Generic": (), # all numbers of axes are valid for GenericEndpoint
376  "Point2": (1, 3, 4),
377  "IcrsCoord": (1, 3, 4),
378  }
379 
380  # Dict of frame index: identity name for frames created by makeFrameSet
381  self.frameIdentDict = {
382  1: "baseFrame",
383  2: "frame2",
384  3: "frame3",
385  4: "currFrame",
386  }
387 
388  @staticmethod
389  def makeRawArrayData(nPoints, nAxes, delta=0.123):
390  """Make an array of generic point data
391 
392  The data will be suitable for spherical points
393 
394  Parameters
395  ----------
396  nPoints : `int`
397  Number of points in the array
398  nAxes : `int`
399  Number of axes in the point
400 
401  Returns
402  -------
403  np.array of floats with shape (nAxes, nPoints)
404  The values are as follows; if nAxes != 2:
405  The first point has values `[0, delta, 2*delta, ..., (nAxes-1)*delta]`
406  The Nth point has those values + N
407  if nAxes == 2 then the data is scaled so that the max value of axis 1
408  is a bit less than pi/2
409  """
410  delta = 0.123
411  # oneAxis = [0, 1, 2, ...nPoints-1]
412  oneAxis = np.arange(nPoints, dtype=float) # [0, 1, 2...]
413  # rawData = [oneAxis, oneAxis + delta, oneAxis + 2 delta, ...]
414  rawData = np.array([j * delta + oneAxis for j in range(nAxes)], dtype=float)
415  if nAxes == 2:
416  # scale rawData so that max value of 2nd axis is a bit less than pi/2,
417  # thus making the data safe for IcrsCoord
418  maxLatitude = np.max(rawData[1])
419  rawData *= math.pi * 0.4999 / maxLatitude
420  return rawData
421 
422  @staticmethod
423  def makeRawPointData(nAxes, delta=0.123):
424  """Make one generic point
425 
426  Parameters
427  ----------
428  nAxes : `int`
429  Number of axes in the point
430  delta : `float`
431  Increment between axis values
432 
433  Returns
434  -------
435  A list of `nAxes` floats with values `[0, delta, ..., (nAxes-1)*delta]
436  """
437  return [i*delta for i in range(nAxes)]
438 
439  @staticmethod
440  def makeEndpoint(name, nAxes=None):
441  """Make an endpoint
442 
443  Parameters
444  ----------
445  name : `str`
446  Endpoint class name prefix; the full class name is name + "Endpoint"
447  nAxes : `int` or `None`, optional
448  number of axes; an int is required if `name` == "Generic";
449  otherwise ignored
450 
451  Returns
452  -------
453  subclass of `lsst.afw.geom.BaseEndpoint`
454  The constructed endpoint
455 
456  Raises
457  ------
458  `TypeError`
459  If `name` == "Generic" and `nAxes` is None or <= 0
460  """
461  EndpointClassName = name + "Endpoint"
462  EndpointClass = getattr(afwGeom, EndpointClassName)
463  if name == "Generic":
464  if nAxes is None:
465  raise TypeError("nAxes must be an integer for GenericEndpoint")
466  return EndpointClass(nAxes)
467  return EndpointClass()
468 
469  @classmethod
470  def makeGoodFrame(cls, name, nAxes=None):
471  """Return the appropriate frame for the given name and nAxes
472 
473  Parameters
474  ----------
475  name : `str`
476  Endpoint class name prefix; the full class name is name + "Endpoint"
477  nAxes : `int` or `None`, optional
478  number of axes; an int is required if `name` == "Generic";
479  otherwise ignored
480 
481  Returns
482  -------
483  `ast.Frame`
484  The constructed frame
485 
486  Raises
487  ------
488  `TypeError`
489  If `name` == "Generic" and `nAxes` is `None` or <= 0
490  """
491  return cls.makeEndpoint(name, nAxes).makeFrame()
492 
493  @staticmethod
494  def makeBadFrames(name):
495  """Return a list of 0 or more frames that are not a valid match for the
496  named endpoint
497 
498  Parameters
499  ----------
500  name : `str`
501  Endpoint class name prefix; the full class name is name + "Endpoint"
502 
503  Returns
504  -------
505  Collection of `ast.Frame`
506  A collection of 0 or more frames
507  """
508  return {
509  "Generic": [],
510  "Point2": [
511  ast.SkyFrame(),
512  ast.Frame(1),
513  ast.Frame(3),
514  ],
515  "IcrsCoord": [
516  ast.Frame(1),
517  ast.Frame(2),
518  ast.Frame(3),
519  ],
520  }[name]
521 
522  def makeFrameSet(self, baseFrame, currFrame):
523  """Make a FrameSet
524 
525  The FrameSet will contain 4 frames and three transforms connecting them.
526  The idenity of each frame is provided by self.frameIdentDict
527 
528  Frame Index Mapping from this frame to the next
529  `baseFrame` 1 `ast.UnitMap(nIn)`
530  Frame(nIn) 2 `polyMap`
531  Frame(nOut) 3 `ast.UnitMap(nOut)`
532  `currFrame` 4
533 
534  where:
535  - `nIn` = `baseFrame.nAxes`
536  - `nOut` = `currFrame.nAxes`
537  - `polyMap` = `makeTwoWayPolyMap(nIn, nOut)`
538 
539  Return
540  ------
541  `ast.FrameSet`
542  The FrameSet as described above
543 
544  Parameters
545  ----------
546  baseFrame : `ast.Frame`
547  base frame
548  currFrame : `ast.Frame`
549  current frame
550  """
551  nIn = baseFrame.nAxes
552  nOut = currFrame.nAxes
553  polyMap = makeTwoWayPolyMap(nIn, nOut)
554 
555  # The only way to set the Ident of a frame in a FrameSet is to set it in advance,
556  # and I don't want to modify the inputs, so replace the input frames with copies
557  baseFrame = baseFrame.copy()
558  baseFrame.ident = self.frameIdentDict[1]
559  currFrame = currFrame.copy()
560  currFrame.ident = self.frameIdentDict[4]
561 
562  frameSet = ast.FrameSet(baseFrame)
563  frame2 = ast.Frame(nIn)
564  frame2.ident = self.frameIdentDict[2]
565  frameSet.addFrame(ast.FrameSet.CURRENT, ast.UnitMap(nIn), frame2)
566  frame3 = ast.Frame(nOut)
567  frame3.ident = self.frameIdentDict[3]
568  frameSet.addFrame(ast.FrameSet.CURRENT, polyMap, frame3)
569  frameSet.addFrame(ast.FrameSet.CURRENT, ast.UnitMap(nOut), currFrame)
570  return frameSet
571 
572  @staticmethod
573  def permuteFrameSetIter(frameSet):
574  """Iterator over 0 or more frameSets with SkyFrames axes permuted
575 
576  Only base and current SkyFrames are permuted. If neither the base nor
577  the current frame is a SkyFrame then no frames are returned.
578 
579  Returns
580  -------
581  iterator over `PermutedFrameSet`
582  """
583 
584  fsInfo = FrameSetInfo(frameSet)
585  if not (fsInfo.isBaseSkyFrame or fsInfo.isCurrSkyFrame):
586  return
587 
588  permuteBaseList = [False, True] if fsInfo.isBaseSkyFrame else [False]
589  permuteCurrList = [False, True] if fsInfo.isCurrSkyFrame else [False]
590  for permuteBase in permuteBaseList:
591  for permuteCurr in permuteCurrList:
592  yield PermutedFrameSet(frameSet, permuteBase, permuteCurr)
593 
594  @staticmethod
595  def makeJacobian(nIn, nOut, inPoint):
596  """Make a Jacobian matrix for the equation described by
597  `makeTwoWayPolyMap`.
598 
599  Parameters
600  ----------
601  nIn, nOut : `int`
602  the dimensions of the input and output data; see makeTwoWayPolyMap
603  inPoint : `numpy.ndarray`
604  an array of size `nIn` representing the point at which the Jacobian
605  is measured
606 
607  Returns
608  -------
609  J : `numpy.ndarray`
610  an `nOut` x `nIn` array of first derivatives
611  """
612  basePolyMapCoeff = 0.001 # see makeTwoWayPolyMap
613  baseCoeff = 2.0 * basePolyMapCoeff
614  coeffs = np.empty((nOut, nIn))
615  for iOut in range(nOut):
616  coeffOffset = baseCoeff * iOut
617  for iIn in range(nIn):
618  coeffs[iOut, iIn] = baseCoeff * (iIn + 1) + coeffOffset
619  coeffs[iOut, iIn] *= inPoint[iIn]
620  assert coeffs.ndim == 2
621  # Avoid spurious errors when comparing to a simplified array
622  assert coeffs.shape == (nOut, nIn)
623  return coeffs
624 
625  def checkTransformation(self, transform, mapping, msg=""):
626  """Check applyForward and applyInverse for a transform
627 
628  Parameters
629  ----------
630  transform : `lsst.afw.geom.Transform`
631  The transform to check
632  mapping : `ast.Mapping`
633  The mapping the transform should use. This mapping
634  must contain valid forward or inverse transformations,
635  but they need not match if both present. Hence the
636  mappings returned by make*PolyMap are acceptable.
637  msg : `str`
638  Error message suffix describing test parameters
639  """
640  fromEndpoint = transform.fromEndpoint
641  toEndpoint = transform.toEndpoint
642  frameSet = transform.getFrameSet()
643 
644  nIn = mapping.nIn
645  nOut = mapping.nOut
646  self.assertEqual(nIn, fromEndpoint.nAxes, msg=msg)
647  self.assertEqual(nOut, toEndpoint.nAxes, msg=msg)
648 
649  # forward transformation of one point
650  rawInPoint = self.makeRawPointData(nIn)
651  inPoint = fromEndpoint.pointFromData(rawInPoint)
652 
653  # forward transformation of an array of points
654  nPoints = 7 # arbitrary
655  rawInArray = self.makeRawArrayData(nPoints, nIn)
656  inArray = fromEndpoint.arrayFromData(rawInArray)
657 
658  if mapping.hasForward:
659  self.assertTrue(transform.hasForward)
660  outPoint = transform.applyForward(inPoint)
661  rawOutPoint = toEndpoint.dataFromPoint(outPoint)
662  assert_allclose(rawOutPoint, mapping.applyForward(rawInPoint), err_msg=msg)
663  assert_allclose(rawOutPoint, frameSet.applyForward(rawInPoint), err_msg=msg)
664 
665  outArray = transform.applyForward(inArray)
666  rawOutArray = toEndpoint.dataFromArray(outArray)
667  self.assertFloatsAlmostEqual(rawOutArray, mapping.applyForward(rawInArray), msg=msg)
668  self.assertFloatsAlmostEqual(rawOutArray, frameSet.applyForward(rawInArray), msg=msg)
669  else:
670  # Need outPoint, but don't need it to be consistent with inPoint
671  rawOutPoint = self.makeRawPointData(nOut)
672  outPoint = toEndpoint.pointFromData(rawOutPoint)
673  rawOutArray = self.makeRawArrayData(nPoints, nOut)
674  outArray = toEndpoint.arrayFromData(rawOutArray)
675 
676  self.assertFalse(transform.hasForward)
677 
678  if mapping.hasInverse:
679  self.assertTrue(transform.hasInverse)
680  # inverse transformation of one point;
681  # remember that the inverse need not give the original values
682  # (see the description of the `mapping` parameter)
683  inversePoint = transform.applyInverse(outPoint)
684  rawInversePoint = fromEndpoint.dataFromPoint(inversePoint)
685  assert_allclose(rawInversePoint, mapping.applyInverse(rawOutPoint), err_msg=msg)
686  assert_allclose(rawInversePoint, frameSet.applyInverse(rawOutPoint), err_msg=msg)
687 
688  # inverse transformation of an array of points;
689  # remember that the inverse will not give the original values
690  # (see the description of the `mapping` parameter)
691  inverseArray = transform.applyInverse(outArray)
692  rawInverseArray = fromEndpoint.dataFromArray(inverseArray)
693  self.assertFloatsAlmostEqual(rawInverseArray, mapping.applyInverse(rawOutArray), msg=msg)
694  self.assertFloatsAlmostEqual(rawInverseArray, frameSet.applyInverse(rawOutArray), msg=msg)
695  else:
696  self.assertFalse(transform.hasInverse)
697 
698  def checkInverseTransformation(self, forward, inverse, msg=""):
699  """Check that two Transforms are each others' inverses.
700 
701  Parameters
702  ----------
703  forward : `lsst.afw.geom.Transform`
704  the reference Transform to test
705  inverse : `lsst.afw.geom.Transform`
706  the transform that should be the inverse of `forward`
707  msg : `str`
708  error message suffix describing test parameters
709  """
710  fromEndpoint = forward.fromEndpoint
711  toEndpoint = forward.toEndpoint
712  frameSet = forward.getFrameSet()
713  invFrameSet = inverse.getFrameSet()
714 
715  # properties
716  self.assertEqual(forward.fromEndpoint,
717  inverse.toEndpoint, msg=msg)
718  self.assertEqual(forward.toEndpoint,
719  inverse.fromEndpoint, msg=msg)
720  self.assertEqual(forward.hasForward, inverse.hasInverse, msg=msg)
721  self.assertEqual(forward.hasInverse, inverse.hasForward, msg=msg)
722 
723  # transformations of one point
724  # we don't care about whether the transformation itself is correct
725  # (see checkTransformation), so inPoint/outPoint need not be related
726  rawInPoint = self.makeRawPointData(fromEndpoint.nAxes)
727  inPoint = fromEndpoint.pointFromData(rawInPoint)
728  rawOutPoint = self.makeRawPointData(toEndpoint.nAxes)
729  outPoint = toEndpoint.pointFromData(rawOutPoint)
730 
731  # transformations of arrays of points
732  nPoints = 7 # arbitrary
733  rawInArray = self.makeRawArrayData(nPoints, fromEndpoint.nAxes)
734  inArray = fromEndpoint.arrayFromData(rawInArray)
735  rawOutArray = self.makeRawArrayData(nPoints, toEndpoint.nAxes)
736  outArray = toEndpoint.arrayFromData(rawOutArray)
737 
738  if forward.hasForward:
739  self.assertEqual(forward.applyForward(inPoint),
740  inverse.applyInverse(inPoint), msg=msg)
741  self.assertEqual(frameSet.applyForward(rawInPoint),
742  invFrameSet.applyInverse(rawInPoint), msg=msg)
743  # Assertions must work with both lists and numpy arrays
744  assert_array_equal(forward.applyForward(inArray),
745  inverse.applyInverse(inArray),
746  err_msg=msg)
747  assert_array_equal(frameSet.applyForward(rawInArray),
748  invFrameSet.applyInverse(rawInArray),
749  err_msg=msg)
750 
751  if forward.hasInverse:
752  self.assertEqual(forward.applyInverse(outPoint),
753  inverse.applyForward(outPoint), msg=msg)
754  self.assertEqual(frameSet.applyInverse(rawOutPoint),
755  invFrameSet.applyForward(rawOutPoint), msg=msg)
756  assert_array_equal(forward.applyInverse(outArray),
757  inverse.applyForward(outArray),
758  err_msg=msg)
759  assert_array_equal(frameSet.applyInverse(rawOutArray),
760  invFrameSet.applyForward(rawOutArray),
761  err_msg=msg)
762 
763  def checkTransformFromMapping(self, fromName, toName):
764  """Check Transform_<fromName>_<toName> using the Mapping constructor
765 
766  Parameters
767  ----------
768  fromName, toName : `str`
769  Endpoint name prefix for "from" and "to" endpoints, respectively,
770  e.g. "Point2" for `lsst.afw.geom.Point2Endpoint`
771  fromAxes, toAxes : `int`
772  number of axes in fromFrame and toFrame, respectively
773  """
774  transformClassName = "Transform{}To{}".format(fromName, toName)
775  TransformClass = getattr(afwGeom, transformClassName)
776  baseMsg = "TransformClass={}".format(TransformClass.__name__)
777 
778  # check valid numbers of inputs and outputs
779  for nIn, nOut in itertools.product(self.goodNAxes[fromName],
780  self.goodNAxes[toName]):
781  msg = "{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
782  polyMap = makeTwoWayPolyMap(nIn, nOut)
783  transform = TransformClass(polyMap)
784 
785  # desired output from `str(transform)`
786  desStr = "{}[{}->{}]".format(transformClassName, nIn, nOut)
787  self.assertEqual("{}".format(transform), desStr)
788  self.assertEqual(repr(transform), "lsst.afw.geom." + desStr)
789 
790  self.checkTransformation(transform, polyMap, msg=msg)
791 
792  # Forward transform but no inverse
793  polyMap = makeForwardPolyMap(nIn, nOut)
794  transform = TransformClass(polyMap)
795  self.checkTransformation(transform, polyMap, msg=msg)
796 
797  # Inverse transform but no forward
798  polyMap = makeForwardPolyMap(nOut, nIn).getInverse()
799  transform = TransformClass(polyMap)
800  self.checkTransformation(transform, polyMap, msg=msg)
801 
802  # check invalid # of output against valid # of inputs
803  for nIn, badNOut in itertools.product(self.goodNAxes[fromName],
804  self.badNAxes[toName]):
805  badPolyMap = makeTwoWayPolyMap(nIn, badNOut)
806  msg = "{}, nIn={}, badNOut={}".format(baseMsg, nIn, badNOut)
807  with self.assertRaises(InvalidParameterError, msg=msg):
808  TransformClass(badPolyMap)
809 
810  # check invalid # of inputs against valid and invalid # of outputs
811  for badNIn, nOut in itertools.product(self.badNAxes[fromName],
812  self.goodNAxes[toName] + self.badNAxes[toName]):
813  badPolyMap = makeTwoWayPolyMap(badNIn, nOut)
814  msg = "{}, badNIn={}, nOut={}".format(baseMsg, nIn, nOut)
815  with self.assertRaises(InvalidParameterError, msg=msg):
816  TransformClass(badPolyMap)
817 
818  def checkTransformFromFrameSet(self, fromName, toName):
819  """Check Transform_<fromName>_<toName> using the FrameSet constructor
820 
821  Parameters
822  ----------
823  fromName, toName : `str`
824  Endpoint name prefix for "from" and "to" endpoints, respectively,
825  e.g. "Point2" for `lsst.afw.geom.Point2Endpoint`
826  """
827  transformClassName = "Transform{}To{}".format(fromName, toName)
828  TransformClass = getattr(afwGeom, transformClassName)
829  baseMsg = "TransformClass={}".format(TransformClass.__name__)
830  for nIn, nOut in itertools.product(self.goodNAxes[fromName],
831  self.goodNAxes[toName]):
832  msg = "{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
833 
834  baseFrame = self.makeGoodFrame(fromName, nIn)
835  currFrame = self.makeGoodFrame(toName, nOut)
836  frameSet = self.makeFrameSet(baseFrame, currFrame)
837  self.assertEqual(frameSet.nFrame, 4)
838 
839  # construct 0 or more frame sets that are invalid for this transform class
840  for badBaseFrame in self.makeBadFrames(fromName):
841  badFrameSet = self.makeFrameSet(badBaseFrame, currFrame)
842  with self.assertRaises(InvalidParameterError):
843  TransformClass(badFrameSet)
844  for badCurrFrame in self.makeBadFrames(toName):
845  reallyBadFrameSet = self.makeFrameSet(badBaseFrame, badCurrFrame)
846  with self.assertRaises(InvalidParameterError):
847  TransformClass(reallyBadFrameSet)
848  for badCurrFrame in self.makeBadFrames(toName):
849  badFrameSet = self.makeFrameSet(baseFrame, badCurrFrame)
850  with self.assertRaises(InvalidParameterError):
851  TransformClass(badFrameSet)
852 
853  transform = TransformClass(frameSet)
854 
855  desStr = "{}[{}->{}]".format(transformClassName, nIn, nOut)
856  self.assertEqual("{}".format(transform), desStr)
857  self.assertEqual(repr(transform), "lsst.afw.geom." + desStr)
858 
859  self.checkPersistence(transform)
860 
861  frameSetCopy = transform.getFrameSet()
862  transformCopy = TransformClass(frameSetCopy)
863  self.assertEqual(type(transform), type(transformCopy))
864  self.assertEqual(transform.getFrameSet(), transformCopy.getFrameSet())
865 
866  desNFrame = 4 # desired number of frames
867  self.assertEqual(frameSet.nFrame, desNFrame)
868  self.assertEqual(frameSetCopy.nFrame, desNFrame)
869  for frameInd in range(1, 1 + desNFrame):
870  self.assertEqual(frameSet.getFrame(frameInd).ident,
871  self.frameIdentDict[frameInd])
872 
873  polyMap = makeTwoWayPolyMap(nIn, nOut)
874 
875  self.checkTransformation(transform, mapping=polyMap, msg=msg)
876 
877  # If the base and/or current frame of frameSet is a SkyFrame,
878  # try permuting that frame (in place, so the connected mappings are
879  # correctly updated). The Transform constructor should undo the permutation,
880  # (via IcrsCoordEndpoint.normalizeFrame) in its internal copy of frameSet,
881  # forcing the axes of the SkyFrame into standard (longitude, latitude) order
882  for permutedFS in self.permuteFrameSetIter(frameSet):
883  if permutedFS.isBaseSkyFrame:
884  baseFrame = permutedFS.frameSet.getFrame(ast.FrameSet.BASE)
885  # desired base longitude axis
886  desBaseLonAxis = 2 if permutedFS.isBasePermuted else 1
887  self.assertEqual(baseFrame.lonAxis, desBaseLonAxis)
888  if permutedFS.isCurrSkyFrame:
889  currFrame = permutedFS.frameSet.getFrame(ast.FrameSet.CURRENT)
890  # desired current base longitude axis
891  desCurrLonAxis = 2 if permutedFS.isCurrPermuted else 1
892  self.assertEqual(currFrame.lonAxis, desCurrLonAxis)
893 
894  permTransform = TransformClass(permutedFS.frameSet)
895  # If the base and/or current frame is a SkyFrame then make sure the frame
896  # in the *Transform* has axes in standard (longitude, latitude) order
897  unpermFrameSet = permTransform.getFrameSet()
898  if permutedFS.isBaseSkyFrame:
899  self.assertEqual(unpermFrameSet.getFrame(ast.FrameSet.BASE).lonAxis, 1)
900  if permutedFS.isCurrSkyFrame:
901  self.assertEqual(unpermFrameSet.getFrame(ast.FrameSet.CURRENT).lonAxis, 1)
902 
903  self.checkTransformation(permTransform, mapping=polyMap, msg=msg)
904 
905  def checkGetInverse(self, fromName, toName):
906  """Test Transform<fromName>To<toName>.getInverse
907 
908  Parameters
909  ----------
910  fromName, toName : `str`
911  Endpoint name prefix for "from" and "to" endpoints, respectively,
912  e.g. "Point2" for `lsst.afw.geom.Point2Endpoint`
913  """
914  transformClassName = "Transform{}To{}".format(fromName, toName)
915  TransformClass = getattr(afwGeom, transformClassName)
916  baseMsg = "TransformClass={}".format(TransformClass.__name__)
917  for nIn, nOut in itertools.product(self.goodNAxes[fromName],
918  self.goodNAxes[toName]):
919  msg = "{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
920  self.checkInverseMapping(
921  TransformClass,
922  makeTwoWayPolyMap(nIn, nOut),
923  "{}, Map={}".format(msg, "TwoWay"))
924  self.checkInverseMapping(
925  TransformClass,
926  makeForwardPolyMap(nIn, nOut),
927  "{}, Map={}".format(msg, "Forward"))
928  self.checkInverseMapping(
929  TransformClass,
930  makeForwardPolyMap(nOut, nIn).getInverse(),
931  "{}, Map={}".format(msg, "Inverse"))
932 
933  self.checkInverseFrameSet(TransformClass,
934  self.makeGoodFrame(fromName, nIn),
935  self.makeGoodFrame(toName, nOut))
936 
937  def checkInverseMapping(self, TransformClass, mapping, msg):
938  """Test Transform<fromName>To<toName>.getInverse for a specific mapping.
939 
940  Parameters
941  ----------
942  TransformClass : `type`
943  The class of transform to test, such as TransformPoint2ToIcrsCoord
944  mapping : `ast.Mapping`
945  The mapping to use for the transform
946  msg : `str`
947  Error message suffix
948  """
949  transform = TransformClass(mapping)
950  inverse = transform.getInverse()
951  inverseInverse = inverse.getInverse()
952 
953  self.checkInverseTransformation(transform, inverse, msg=msg)
954  self.checkInverseTransformation(inverse, inverseInverse, msg=msg)
955  self.checkTransformation(inverseInverse, mapping, msg=msg)
956 
957  def checkInverseFrameSet(self, TransformClass, frameIn, frameOut):
958  """Test whether inverting a Transform preserves all information
959  in its FrameSet.
960 
961  Parameters
962  ----------
963  TransformClass : `type`
964  the transform to test
965  frameIn, frameOut : `ast.Frame`
966  the frames to between which `TransformClass` shall convert. Must be
967  compatible with `TransformClass`.
968  """
969  desNFrame = 4 # desired number of frames
970  frameSet = self.makeFrameSet(frameIn, frameOut)
971  self.assertEqual(frameSet.nFrame, desNFrame)
972 
973  baseMsg = "TransformClass={}, nIn={}, nOut={}".format(
974  TransformClass.__name__, frameIn.nAxes, frameOut.nAxes)
975  transform = TransformClass(frameSet)
976  forwardFrames = transform.getFrameSet()
977  self.assertFalse(forwardFrames.isInverted)
978  self.assertEqual(forwardFrames.base, 1)
979  self.assertEqual(forwardFrames.current, desNFrame)
980 
981  self.assertEqual(forwardFrames.nFrame, desNFrame, msg=baseMsg)
982  for frameInd in range(1, 1 + desNFrame):
983  self.assertEqual(forwardFrames.getFrame(frameInd).ident,
984  self.frameIdentDict[frameInd], msg=baseMsg)
985 
986  reverseFrames = transform.getInverse().getFrameSet()
987  self.assertTrue(reverseFrames.isInverted)
988  self.assertEqual(reverseFrames.base, desNFrame)
989  self.assertEqual(reverseFrames.current, 1)
990  self.assertEqual(reverseFrames.nFrame, desNFrame, msg=baseMsg)
991  for frameInd in range(1, 1 + desNFrame):
992  self.assertEqual(reverseFrames.getFrame(frameInd).ident,
993  self.frameIdentDict[frameInd], msg=baseMsg)
994 
995  def checkGetJacobian(self, fromName, toName):
996  """Test Transform<fromName>To<toName>.getJacobian
997 
998  Parameters
999  ----------
1000  fromName, toName : `str`
1001  Endpoint name prefix for "from" and "to" endpoints, respectively,
1002  e.g. "Point2" for `lsst.afw.geom.Point2Endpoint`
1003  """
1004  transformClassName = "Transform{}To{}".format(fromName, toName)
1005  TransformClass = getattr(afwGeom, transformClassName)
1006  baseMsg = "TransformClass={}".format(TransformClass.__name__)
1007  for nIn, nOut in itertools.product(self.goodNAxes[fromName],
1008  self.goodNAxes[toName]):
1009  msg = "{}, nIn={}, nOut={}".format(baseMsg, nIn, nOut)
1010  polyMap = makeForwardPolyMap(nIn, nOut)
1011  transform = TransformClass(polyMap)
1012  fromEndpoint = transform.fromEndpoint
1013 
1014  # Test multiple points to ensure correct functional form
1015  rawInPoint = self.makeRawPointData(nIn)
1016  inPoint = fromEndpoint.pointFromData(rawInPoint)
1017  jacobian = transform.getJacobian(inPoint)
1018  assert_allclose(jacobian, self.makeJacobian(nIn, nOut, rawInPoint),
1019  err_msg=msg)
1020 
1021  rawInPoint = self.makeRawPointData(nIn, 0.111)
1022  inPoint = fromEndpoint.pointFromData(rawInPoint)
1023  jacobian = transform.getJacobian(inPoint)
1024  assert_allclose(jacobian, self.makeJacobian(nIn, nOut, rawInPoint),
1025  err_msg=msg)
1026 
1027  def checkThen(self, fromName, midName, toName):
1028  """Test Transform<fromName>To<midName>.then(Transform<midName>To<toName>)
1029 
1030  Parameters
1031  ----------
1032  fromName : `str`
1033  the prefix of the starting endpoint (e.g., "Point2" for a
1034  Point2Endpoint) for the final, concatenated Transform
1035  midName : `str`
1036  the prefix for the shared endpoint where two Transforms will be
1037  concatenated
1038  toName : `str`
1039  the prefix of the ending endpoint for the final, concatenated
1040  Transform
1041  """
1042  TransformClass1 = getattr(afwGeom,
1043  "Transform{}To{}".format(fromName, midName))
1044  TransformClass2 = getattr(afwGeom,
1045  "Transform{}To{}".format(midName, toName))
1046  baseMsg = "{}.then({})".format(TransformClass1.__name__,
1047  TransformClass2.__name__)
1048  for nIn, nMid, nOut in itertools.product(self.goodNAxes[fromName],
1049  self.goodNAxes[midName],
1050  self.goodNAxes[toName]):
1051  msg = "{}, nIn={}, nMid={}, nOut={}".format(
1052  baseMsg, nIn, nMid, nOut)
1053  polyMap1 = makeTwoWayPolyMap(nIn, nMid)
1054  transform1 = TransformClass1(polyMap1)
1055  polyMap2 = makeTwoWayPolyMap(nMid, nOut)
1056  transform2 = TransformClass2(polyMap2)
1057  transform = transform1.then(transform2)
1058 
1059  fromEndpoint = transform1.fromEndpoint
1060  toEndpoint = transform2.toEndpoint
1061 
1062  inPoint = fromEndpoint.pointFromData(self.makeRawPointData(nIn))
1063  outPointMerged = transform.applyForward(inPoint)
1064  outPointSeparate = transform2.applyForward(
1065  transform1.applyForward(inPoint))
1066  assert_allclose(toEndpoint.dataFromPoint(outPointMerged),
1067  toEndpoint.dataFromPoint(outPointSeparate),
1068  err_msg=msg)
1069 
1070  outPoint = toEndpoint.pointFromData(self.makeRawPointData(nOut))
1071  inPointMerged = transform.applyInverse(outPoint)
1072  inPointSeparate = transform1.applyInverse(
1073  transform2.applyInverse(outPoint))
1074  assert_allclose(
1075  fromEndpoint.dataFromPoint(inPointMerged),
1076  fromEndpoint.dataFromPoint(inPointSeparate),
1077  err_msg=msg)
1078 
1079  # Mismatched number of axes should fail
1080  if midName == "Generic":
1081  nIn = self.goodNAxes[fromName][0]
1082  nOut = self.goodNAxes[toName][0]
1083  polyMap = makeTwoWayPolyMap(nIn, 3)
1084  transform1 = TransformClass1(polyMap)
1085  polyMap = makeTwoWayPolyMap(2, nOut)
1086  transform2 = TransformClass2(polyMap)
1087  with self.assertRaises(InvalidParameterError):
1088  transform = transform1.then(transform2)
1089 
1090  # Mismatched types of endpoints should fail
1091  if fromName != midName:
1092  # Use TransformClass1 for both args to keep test logic simple
1093  outName = midName
1094  joinNAxes = set(self.goodNAxes[fromName]).intersection(
1095  self.goodNAxes[outName])
1096 
1097  for nIn, nMid, nOut in itertools.product(self.goodNAxes[fromName],
1098  joinNAxes,
1099  self.goodNAxes[outName]):
1100  polyMap = makeTwoWayPolyMap(nIn, nMid)
1101  transform1 = TransformClass1(polyMap)
1102  polyMap = makeTwoWayPolyMap(nMid, nOut)
1103  transform2 = TransformClass1(polyMap)
1104  with self.assertRaises(InvalidParameterError):
1105  transform = transform1.then(transform2)
1106 
1107  def assertTransformsEqual(self, transform1, transform2):
1108  """Assert that two transforms are equal"""
1109  self.assertEqual(type(transform1), type(transform2))
1110  self.assertEqual(transform1.fromEndpoint, transform2.fromEndpoint)
1111  self.assertEqual(transform1.toEndpoint, transform2.toEndpoint)
1112  self.assertEqual(transform1.getFrameSet(), transform2.getFrameSet())
1113 
1114  fromEndpoint = transform1.fromEndpoint
1115  toEndpoint = transform1.toEndpoint
1116  frameSet = transform1.getFrameSet()
1117  nIn = frameSet.nIn
1118  nOut = frameSet.nOut
1119 
1120  if frameSet.hasForward:
1121  nPoints = 7 # arbitrary
1122  rawInArray = self.makeRawArrayData(nPoints, nIn)
1123  inArray = fromEndpoint.arrayFromData(rawInArray)
1124  outArray = transform1.applyForward(inArray)
1125  outData = toEndpoint.dataFromArray(outArray)
1126  outArrayRoundTrip = transform2.applyForward(inArray)
1127  outDataRoundTrip = toEndpoint.dataFromArray(outArrayRoundTrip)
1128  assert_allclose(outData, outDataRoundTrip)
1129 
1130  if frameSet.hasInverse:
1131  nPoints = 7 # arbitrary
1132  rawOutArray = self.makeRawArrayData(nPoints, nOut)
1133  outArray = toEndpoint.arrayFromData(rawOutArray)
1134  inArray = transform1.applyInverse(outArray)
1135  inData = fromEndpoint.dataFromArray(inArray)
1136  inArrayRoundTrip = transform2.applyInverse(outArray)
1137  inDataRoundTrip = fromEndpoint.dataFromArray(inArrayRoundTrip)
1138  assert_allclose(inData, inDataRoundTrip)
1139 
1140  def checkPersistence(self, transform):
1141  """Check persistence of a transform
1142  """
1143  className = type(transform).__name__
1144 
1145  # check writeString and readString
1146  transformStr = transform.writeString()
1147  serialVersion, serialClassName, serialRest = transformStr.split(" ", 2)
1148  self.assertEqual(int(serialVersion), 1)
1149  self.assertEqual(serialClassName, className)
1150  badStr1 = " ".join(["2", serialClassName, serialRest])
1151  with self.assertRaises(lsst.pex.exceptions.InvalidParameterError):
1152  transform.readString(badStr1)
1153  badClassName = "x" + serialClassName
1154  badStr2 = " ".join(["1", badClassName, serialRest])
1155  with self.assertRaises(lsst.pex.exceptions.InvalidParameterError):
1156  transform.readString(badStr2)
1157  transformFromStr1 = transform.readString(transformStr)
1158  self.assertTransformsEqual(transform, transformFromStr1)
1159 
1160  # check transformFromString
1161  transformFromStr2 = afwGeom.transformFromString(transformStr)
1162  self.assertTransformsEqual(transform, transformFromStr2)
1163 
1164  # Check pickling
1165  self.assertTransformsEqual(transform, pickle.loads(pickle.dumps(transform)))
1166 
1167  # Check afw::table::io persistence round-trip
1168  with lsst.utils.tests.getTempFilePath(".fits") as filename:
1169  transform.writeFits(filename)
1170  self.assertTransformsEqual(transform, type(transform).readFits(filename))
def __init__(self, frameSet, permuteBase, permuteCurr)
Definition: testUtils.py:289
Eigen::Matrix2d getCdMatrixFromMetadata(daf::base::PropertySet &metadata)
Read a CD matrix from FITS WCS metadata.
def makeGoodFrame(cls, name, nAxes=None)
Definition: testUtils.py:470
def checkThen(self, fromName, midName, toName)
Definition: testUtils.py:1027
def checkTransformFromFrameSet(self, fromName, toName)
Definition: testUtils.py:818
def makeRawArrayData(nPoints, nAxes, delta=0.123)
Definition: testUtils.py:389
def checkTransformation(self, transform, mapping, msg="")
Definition: testUtils.py:625
def checkInverseTransformation(self, forward, inverse, msg="")
Definition: testUtils.py:698
std::string getPackageDir(std::string const &packageName)
def checkGetJacobian(self, fromName, toName)
Definition: testUtils.py:995
def checkInverseFrameSet(self, TransformClass, frameIn, frameOut)
Definition: testUtils.py:957
Divide a box into nx by ny sub-boxes that tile the region.
Definition: testUtils.py:48
def makeSipPixelToIwc(metadata)
Definition: testUtils.py:232
def __getitem__(self, indXY)
Return the box at the specified x,y index (a pair of ints)
Definition: testUtils.py:91
def getTempFilePath(ext, expectOutput=True)
def checkGetInverse(self, fromName, toName)
Definition: testUtils.py:905
def __init__(self, box, numColRow)
Construct a BoxGrid.
Definition: testUtils.py:52
def __iter__(self)
Return an iterator over all boxes, where column varies most quickly.
Definition: testUtils.py:102
def assertTransformsEqual(self, transform1, transform2)
Definition: testUtils.py:1107
def makeSipPolyMapCoeffs(metadata, name)
Definition: testUtils.py:138
def makeSipIwcToPixel(metadata)
Definition: testUtils.py:193
def checkInverseMapping(self, TransformClass, mapping, msg)
Definition: testUtils.py:937
Transform LSST spatial data, such as Point2D and IcrsCoord, using an AST transform.
Definition: Transform.h:69
def makeFrameSet(self, baseFrame, currFrame)
Definition: testUtils.py:522
def checkTransformFromMapping(self, fromName, toName)
Definition: testUtils.py:763