LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Functions | Variables
lsst.afw.image.basicUtils Namespace Reference

Functions

def makeImageFromArray
 
def makeMaskFromArray
 
def makeMaskedImageFromArrays
 
def _compareWcsOverBBox
 Compare two WCS over a rectangular grid of pixel positions. More...
 
def wcsNearlyEqualOverBBox
 Return True if two WCS are nearly equal over a grid of pixel positions, else False. More...
 
def assertWcsNearlyEqualOverBBox
 Compare pixelToSky and skyToPixel for two WCS over a rectangular grid of pixel positions. More...
 

Variables

list __all__
 
dictionary suffixes = {str(numpy.uint16): "U", str(numpy.int32): "I", str(numpy.float32): "F", str(numpy.float64): "D"}
 

Function Documentation

def lsst.afw.image.basicUtils._compareWcsOverBBox (   wcs0,
  wcs1,
  bbox,
  maxDiffSky = 0.01*afwGeom.arcseconds,
  maxDiffPix = 0.01,
  nx = 5,
  ny = 5,
  doShortCircuit = True 
)
private

Compare two WCS over a rectangular grid of pixel positions.

Parameters
[in]wcs0WCS 0 (an lsst.afw.image.Wcs)
[in]wcs1WCS 1 (an lsst.afw.image.Wcs)
[in]bboxboundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D)
[in]maxDiffSkymaximum separation between sky positions computed using Wcs.pixelToSky (an lsst.afw.geom.Angle)
[in]maxDiffPixmaximum separation between pixel positions computed using Wcs.skyToPixel
[in]nxnumber of points in x for the grid of pixel positions
[in]nynumber of points in y for the grid of pixel positions
[in]doShortCircuitif True then stop at the first error, else test all values in the grid and return information about the worst violations found
Returns
return an empty string if the WCS are sufficiently close; else return a string describing the largest error measured in pixel coordinates (if sky to pixel error was excessive) and sky coordinates (if pixel to sky error was excessive). If doShortCircuit is true then the reported error is likely to be much less than the maximum error across the whole pixel grid.

Definition at line 63 of file basicUtils.py.

63 
64  maxDiffPix=0.01, nx=5, ny=5, doShortCircuit=True):
65  """!Compare two WCS over a rectangular grid of pixel positions
66 
67  @param[in] wcs0 WCS 0 (an lsst.afw.image.Wcs)
68  @param[in] wcs1 WCS 1 (an lsst.afw.image.Wcs)
69  @param[in] bbox boundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D)
70  @param[in] maxDiffSky maximum separation between sky positions computed using Wcs.pixelToSky
71  (an lsst.afw.geom.Angle)
72  @param[in] maxDiffPix maximum separation between pixel positions computed using Wcs.skyToPixel
73  @param[in] nx number of points in x for the grid of pixel positions
74  @param[in] ny number of points in y for the grid of pixel positions
75  @param[in] doShortCircuit if True then stop at the first error, else test all values in the grid
76  and return information about the worst violations found
77 
78  @return return an empty string if the WCS are sufficiently close; else return a string describing
79  the largest error measured in pixel coordinates (if sky to pixel error was excessive) and sky coordinates
80  (if pixel to sky error was excessive). If doShortCircuit is true then the reported error is likely to be
81  much less than the maximum error across the whole pixel grid.
82  """
83  if nx < 1 or ny < 1:
84  raise RuntimeError("nx = %s and ny = %s must both be positive" % (nx, ny))
85  if maxDiffSky <= 0*afwGeom.arcseconds:
86  raise RuntimeError("maxDiffSky = %s must be positive" % (maxDiffSky,))
87  if maxDiffPix <= 0:
88  raise RuntimeError("maxDiffPix = %s must be positive" % (maxDiffPix,))
89 
90  bboxd = afwGeom.Box2D(bbox)
91  xList = numpy.linspace(bboxd.getMinX(), bboxd.getMaxX(), nx)
92  yList = numpy.linspace(bboxd.getMinY(), bboxd.getMaxY(), ny)
93  # we don't care about measured error unless it is too large, so initialize to max allowed
94  measDiffSky = (maxDiffSky, "?") # (sky diff, pix pos)
95  measDiffPix = (maxDiffPix, "?") # (pix diff, sky pos)
96  for x, y in itertools.product(xList, yList):
97  fromPixPos = afwGeom.Point2D(x, y)
98  sky0 = wcs0.pixelToSky(fromPixPos)
99  sky1 = wcs1.pixelToSky(fromPixPos)
100  diffSky = sky0.angularSeparation(sky1)
101  if diffSky > measDiffSky[0]:
102  measDiffSky = (diffSky, fromPixPos)
103  if doShortCircuit:
104  break
105 
106  toPixPos0 = wcs0.skyToPixel(sky0)
107  toPixPos1 = wcs1.skyToPixel(sky0)
108  diffPix = math.hypot(*(toPixPos0 - toPixPos1))
109  if diffPix > measDiffPix[0]:
110  measDiffPix = (diffPix, sky0)
111  if doShortCircuit:
112  break
113 
114  msgList = []
115  if measDiffSky[0] > maxDiffSky:
116  msgList.append("%s arcsec max measured sky error > %s arcsec max allowed sky error at pix pos=%s" %
117  (measDiffSky[0].asArcseconds(), maxDiffSky.asArcseconds(), measDiffSky[1]))
118  if measDiffPix[0] > maxDiffPix:
119  msgList.append("%s max measured pix error > %s max allowed pix error at sky pos=%s" %
120  (measDiffPix[0], maxDiffPix, measDiffPix[1]))
121 
122  return "; ".join(msgList)
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.afw.image.basicUtils.assertWcsNearlyEqualOverBBox (   testCase,
  wcs0,
  wcs1,
  bbox,
  maxDiffSky = 0.01*afwGeom.arcseconds,
  maxDiffPix = 0.01,
  nx = 5,
  ny = 5,
  msg = "WCSs differ" 
)

Compare pixelToSky and skyToPixel for two WCS over a rectangular grid of pixel positions.

If the WCS are too divergent, call testCase.fail; the message describes the largest error measured in pixel coordinates (if sky to pixel error was excessive) and sky coordinates (if pixel to sky error was excessive) across the entire pixel grid.

Parameters
[in]testCaseunittest.TestCase instance the test is part of; an object supporting one method: fail(self, msgStr)
[in]wcs0WCS 0 (an lsst.afw.image.Wcs)
[in]wcs1WCS 1 (an lsst.afw.image.Wcs)
[in]bboxboundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D)
[in]maxDiffSkymaximum separation between sky positions computed using Wcs.pixelToSky (an lsst.afw.geom.Angle)
[in]maxDiffPixmaximum separation between pixel positions computed using Wcs.skyToPixel
[in]nxnumber of points in x for the grid of pixel positions
[in]nynumber of points in y for the grid of pixel positions
[in]msgexception message prefix; details of the error are appended after ": "

Definition at line 151 of file basicUtils.py.

152  nx=5, ny=5, msg="WCSs differ"):
153  """!Compare pixelToSky and skyToPixel for two WCS over a rectangular grid of pixel positions
154 
155  If the WCS are too divergent, call testCase.fail; the message describes the largest error measured
156  in pixel coordinates (if sky to pixel error was excessive) and sky coordinates (if pixel to sky error
157  was excessive) across the entire pixel grid.
158 
159  @param[in] testCase unittest.TestCase instance the test is part of;
160  an object supporting one method: fail(self, msgStr)
161  @param[in] wcs0 WCS 0 (an lsst.afw.image.Wcs)
162  @param[in] wcs1 WCS 1 (an lsst.afw.image.Wcs)
163  @param[in] bbox boundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D)
164  @param[in] maxDiffSky maximum separation between sky positions computed using Wcs.pixelToSky
165  (an lsst.afw.geom.Angle)
166  @param[in] maxDiffPix maximum separation between pixel positions computed using Wcs.skyToPixel
167  @param[in] nx number of points in x for the grid of pixel positions
168  @param[in] ny number of points in y for the grid of pixel positions
169  @param[in] msg exception message prefix; details of the error are appended after ": "
170  """
171  errMsg = _compareWcsOverBBox(
172  wcs0 = wcs0,
173  wcs1 = wcs1,
174  bbox = bbox,
175  maxDiffSky = maxDiffSky,
176  maxDiffPix = maxDiffPix,
177  nx = nx,
178  ny = ny,
179  doShortCircuit = False,
180  )
181  if errMsg:
182  testCase.fail("%s: %s" % (msg, errMsg))
def _compareWcsOverBBox
Compare two WCS over a rectangular grid of pixel positions.
Definition: basicUtils.py:63
def lsst.afw.image.basicUtils.makeImageFromArray (   array)
Construct an Image from a NumPy array, inferring the Image type from the NumPy type.
Return None if input is None.

Definition at line 40 of file basicUtils.py.

40 
41 def makeImageFromArray(array):
42  """Construct an Image from a NumPy array, inferring the Image type from the NumPy type.
43  Return None if input is None.
44  """
45  if array is None: return None
46  cls = getattr(imageLib, "Image%s" % (suffixes[str(array.dtype.type)],))
47  return cls(array)
def lsst.afw.image.basicUtils.makeMaskedImageFromArrays (   image,
  mask = None,
  variance = None 
)
Construct a MaskedImage from three NumPy arrays, inferring the MaskedImage types from the NumPy types.

Definition at line 56 of file basicUtils.py.

56 
57 def makeMaskedImageFromArrays(image, mask=None, variance=None):
58  """Construct a MaskedImage from three NumPy arrays, inferring the MaskedImage types from the NumPy types.
59  """
60  cls = getattr(imageLib, "MaskedImage%s" % (suffixes[str(image.dtype.type)],))
61  return cls(makeImageFromArray(image), makeMaskFromArray(mask), makeImageFromArray(variance))
def lsst.afw.image.basicUtils.makeMaskFromArray (   array)
Construct an Mask from a NumPy array, inferring the Mask type from the NumPy type.
Return None if input is None.

Definition at line 48 of file basicUtils.py.

48 
49 def makeMaskFromArray(array):
50  """Construct an Mask from a NumPy array, inferring the Mask type from the NumPy type.
51  Return None if input is None.
52  """
53  if array is None: return None
54  cls = getattr(imageLib, "Mask%s" % (suffixes[str(array.dtype.type)],))
55  return cls(array)
def lsst.afw.image.basicUtils.wcsNearlyEqualOverBBox (   wcs0,
  wcs1,
  bbox,
  maxDiffSky = 0.01*afwGeom.arcseconds,
  maxDiffPix = 0.01,
  nx = 5,
  ny = 5 
)

Return True if two WCS are nearly equal over a grid of pixel positions, else False.

Parameters
[in]wcs0WCS 0 (an lsst.afw.image.Wcs)
[in]wcs1WCS 1 (an lsst.afw.image.Wcs)
[in]bboxboundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D)
[in]maxDiffSkymaximum separation between sky positions computed using Wcs.pixelToSky (an lsst.afw.geom.Angle)
[in]maxDiffPixmaximum separation between pixel positions computed using Wcs.skyToPixel
[in]nxnumber of points in x for the grid of pixel positions
[in]nynumber of points in y for the grid of pixel positions
[in]doShortCircuitif True then stop at the first error, else test all values in the grid and return information about the worst violations found

Definition at line 124 of file basicUtils.py.

125  maxDiffPix=0.01, nx=5, ny=5):
126  """!Return True if two WCS are nearly equal over a grid of pixel positions, else False
127 
128  @param[in] wcs0 WCS 0 (an lsst.afw.image.Wcs)
129  @param[in] wcs1 WCS 1 (an lsst.afw.image.Wcs)
130  @param[in] bbox boundaries of pixel grid over which to compare the WCSs (an lsst.afw.geom.Box2I or Box2D)
131  @param[in] maxDiffSky maximum separation between sky positions computed using Wcs.pixelToSky
132  (an lsst.afw.geom.Angle)
133  @param[in] maxDiffPix maximum separation between pixel positions computed using Wcs.skyToPixel
134  @param[in] nx number of points in x for the grid of pixel positions
135  @param[in] ny number of points in y for the grid of pixel positions
136  @param[in] doShortCircuit if True then stop at the first error, else test all values in the grid
137  and return information about the worst violations found
138  """
139  return not bool(_compareWcsOverBBox(
140  wcs0 = wcs0,
141  wcs1 = wcs1,
142  bbox = bbox,
143  maxDiffSky = maxDiffSky,
144  maxDiffPix = maxDiffPix,
145  nx = nx,
146  ny = ny,
147  doShortCircuit = True,
148  ))
149 
@lsst.utils.tests.inTestCase
def _compareWcsOverBBox
Compare two WCS over a rectangular grid of pixel positions.
Definition: basicUtils.py:63

Variable Documentation

list lsst.afw.image.basicUtils.__all__
Initial value:
1 = ["makeImageFromArray", "makeMaskFromArray", "makeMaskedImageFromArrays",
2  "wcsNearlyEqualOverBBox", "assertWcsNearlyEqualOverBBox"]

Definition at line 35 of file basicUtils.py.

dictionary lsst.afw.image.basicUtils.suffixes = {str(numpy.uint16): "U", str(numpy.int32): "I", str(numpy.float32): "F", str(numpy.float64): "D"}

Definition at line 38 of file basicUtils.py.