LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
Functions
lsst.geom.testUtils Namespace Reference

Functions

def extraMsg (msg)
 
def assertAnglesAlmostEqual (testCase, ang0, ang1, maxDiff=0.001 *arcseconds, ignoreWrap=True, msg="Angles differ")
 
def assertPairsAlmostEqual (testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ")
 
def assertPairListsAlmostEqual (testCase, list0, list1, maxDiff=1e-7, msg=None)
 
def assertSpherePointsAlmostEqual (testCase, sp0, sp1, maxSep=0.001 *arcseconds, msg="")
 
def assertSpherePointListsAlmostEqual (testCase, splist0, splist1, maxSep=0.001 *arcseconds, msg=None)
 
def assertBoxesAlmostEqual (testCase, box0, box1, maxDiff=1e-7, msg="Boxes differ")
 

Function Documentation

◆ assertAnglesAlmostEqual()

def lsst.geom.testUtils.assertAnglesAlmostEqual (   testCase,
  ang0,
  ang1,
  maxDiff = 0.001*arcseconds,
  ignoreWrap = True,
  msg = "Angles differ" 
)
Assert that two `~lsst.geom.Angle`\ s are almost equal, ignoring
wrap differences by default.

If both arguments are NaN the assert will pass.  If one of the arguments
is NaN but the other is not the assert will fail.

Parameters
----------
testCase : `unittest.TestCase`
    test case the test is part of; an object supporting one method:
    fail(self, msgStr)
ang0 : `lsst.geom.Angle`
    angle 0
ang1 : `lsst.geom.Angle`
    angle 1
maxDiff : `lsst.geom.Angle`
    maximum difference between the two angles
ignoreWrap : `bool`
    ignore wrap when comparing the angles?
    - if True then wrap is ignored, e.g. 0 and 360 degrees are considered
      equal
    - if False then wrap matters, e.g. 0 and 360 degrees are considered
      different
msg : `str`
    exception message prefix; details of the error are appended after ": "

Raises
------
AssertionError
    Raised if the difference is greater than ``maxDiff``

Definition at line 47 of file testUtils.py.

47  ignoreWrap=True, msg="Angles differ"):
48  r"""Assert that two `~lsst.geom.Angle`\ s are almost equal, ignoring
49  wrap differences by default.
50 
51  If both arguments are NaN the assert will pass. If one of the arguments
52  is NaN but the other is not the assert will fail.
53 
54  Parameters
55  ----------
56  testCase : `unittest.TestCase`
57  test case the test is part of; an object supporting one method:
58  fail(self, msgStr)
59  ang0 : `lsst.geom.Angle`
60  angle 0
61  ang1 : `lsst.geom.Angle`
62  angle 1
63  maxDiff : `lsst.geom.Angle`
64  maximum difference between the two angles
65  ignoreWrap : `bool`
66  ignore wrap when comparing the angles?
67  - if True then wrap is ignored, e.g. 0 and 360 degrees are considered
68  equal
69  - if False then wrap matters, e.g. 0 and 360 degrees are considered
70  different
71  msg : `str`
72  exception message prefix; details of the error are appended after ": "
73 
74  Raises
75  ------
76  AssertionError
77  Raised if the difference is greater than ``maxDiff``
78  """
79  isNan0 = math.isnan(ang0.asRadians())
80  isNan1 = math.isnan(ang1.asRadians())
81  if isNan0 and isNan1:
82  return
83  if isNan0:
84  testCase.fail("ang0 is NaN")
85  if isNan1:
86  testCase.fail("ang1 is NaN")
87  measDiff = ang1 - ang0
88  if ignoreWrap:
89  measDiff = measDiff.wrapCtr()
90  if abs(measDiff) > maxDiff:
91  testCase.fail("%s: measured difference %s arcsec > max allowed %s arcsec" %
92  (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
93 
94 
95 @lsst.utils.tests.inTestCase
Angle abs(Angle const &a)
Definition: Angle.h:106

◆ assertBoxesAlmostEqual()

def lsst.geom.testUtils.assertBoxesAlmostEqual (   testCase,
  box0,
  box1,
  maxDiff = 1e-7,
  msg = "Boxes differ" 
)
Assert that two boxes (`~lsst.geom.Box2D` or `~lsst.geom.Box2I`) are
almost equal

Parameters
----------
testCase : `unittest.TestCase`
    test case the test is part of; an object supporting one method:
    fail(self, msgStr)
box0 : `lsst.geom.Box2D` or `lsst.geom.Box2I`
    box 0
box1 : `lsst.geom.Box2D` or `lsst.geom.Box2I`
    box 1
maxDiff : `float`
    maximum radial separation between the min points and max points
msg : `str`
    exception message prefix; details of the error are appended after ": "

Raises
------
AssertionError
    Raised if the radial difference of the min points or max points is
    greater than maxDiff

Notes
-----
.. warning::

   Does not compare types, just compares values.

Definition at line 248 of file testUtils.py.

248 def assertBoxesAlmostEqual(testCase, box0, box1, maxDiff=1e-7, msg="Boxes differ"):
249  """Assert that two boxes (`~lsst.geom.Box2D` or `~lsst.geom.Box2I`) are
250  almost equal
251 
252  Parameters
253  ----------
254  testCase : `unittest.TestCase`
255  test case the test is part of; an object supporting one method:
256  fail(self, msgStr)
257  box0 : `lsst.geom.Box2D` or `lsst.geom.Box2I`
258  box 0
259  box1 : `lsst.geom.Box2D` or `lsst.geom.Box2I`
260  box 1
261  maxDiff : `float`
262  maximum radial separation between the min points and max points
263  msg : `str`
264  exception message prefix; details of the error are appended after ": "
265 
266  Raises
267  ------
268  AssertionError
269  Raised if the radial difference of the min points or max points is
270  greater than maxDiff
271 
272  Notes
273  -----
274  .. warning::
275 
276  Does not compare types, just compares values.
277  """
278  assertPairsAlmostEqual(testCase, box0.getMin(),
279  box1.getMin(), maxDiff=maxDiff, msg=msg + ": min")
280  assertPairsAlmostEqual(testCase, box0.getMax(),
281  box1.getMax(), maxDiff=maxDiff, msg=msg + ": max")
282 
def assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ")
Definition: testUtils.py:96
def assertBoxesAlmostEqual(testCase, box0, box1, maxDiff=1e-7, msg="Boxes differ")
Definition: testUtils.py:248

◆ assertPairListsAlmostEqual()

def lsst.geom.testUtils.assertPairListsAlmostEqual (   testCase,
  list0,
  list1,
  maxDiff = 1e-7,
  msg = None 
)
Assert that two lists of Cartesian points are almost equal

Each point can be any indexable pair of two floats, including
Point2D or Extent2D, a list or a tuple.

Parameters
----------
testCase : `unittest.TestCase`
    test case the test is part of; an object supporting one method: fail(self, msgStr)
list0 : `list` of pairs of `float`
    list of pairs 0
list1 : `list` of pairs of `float`
    list of pairs 1
maxDiff : `float`
    maximum radial separation between the two points
msg : `str`
    additional information for the error message; appended after ": "

Raises
------
AssertionError
    Raised if the radial difference is greater than ``maxDiff``

Notes
-----
.. warning::

   Does not compare types, just values.

Definition at line 139 of file testUtils.py.

139 def assertPairListsAlmostEqual(testCase, list0, list1, maxDiff=1e-7, msg=None):
140  """Assert that two lists of Cartesian points are almost equal
141 
142  Each point can be any indexable pair of two floats, including
143  Point2D or Extent2D, a list or a tuple.
144 
145  Parameters
146  ----------
147  testCase : `unittest.TestCase`
148  test case the test is part of; an object supporting one method: fail(self, msgStr)
149  list0 : `list` of pairs of `float`
150  list of pairs 0
151  list1 : `list` of pairs of `float`
152  list of pairs 1
153  maxDiff : `float`
154  maximum radial separation between the two points
155  msg : `str`
156  additional information for the error message; appended after ": "
157 
158  Raises
159  ------
160  AssertionError
161  Raised if the radial difference is greater than ``maxDiff``
162 
163  Notes
164  -----
165  .. warning::
166 
167  Does not compare types, just values.
168  """
169  testCase.assertEqual(len(list0), len(list1))
170  lenList1 = np.array([len(val) for val in list0])
171  lenList2 = np.array([len(val) for val in list1])
172  testCase.assertTrue(np.all(lenList1 == 2))
173  testCase.assertTrue(np.all(lenList2 == 2))
174 
175  diffArr = np.array([(val0[0] - val1[0], val0[1] - val1[1])
176  for val0, val1 in zip(list0, list1)], dtype=float)
177  sepArr = np.hypot(diffArr[:, 0], diffArr[:, 1])
178  badArr = sepArr > maxDiff
179  if np.any(badArr):
180  maxInd = np.argmax(sepArr)
181  testCase.fail("PairLists differ in %s places; max separation is at %s: %s > %s%s" %
182  (np.sum(badArr), maxInd, sepArr[maxInd], maxDiff, extraMsg(msg)))
183 
184 
185 @lsst.utils.tests.inTestCase
def assertPairListsAlmostEqual(testCase, list0, list1, maxDiff=1e-7, msg=None)
Definition: testUtils.py:139

◆ assertPairsAlmostEqual()

def lsst.geom.testUtils.assertPairsAlmostEqual (   testCase,
  pair0,
  pair1,
  maxDiff = 1e-7,
  msg = "Pairs differ" 
)
Assert that two Cartesian points are almost equal.

Each point can be any indexable pair of two floats, including
Point2D or Extent2D, a list or a tuple.

Parameters
----------
testCase : `unittest.TestCase`
    test case the test is part of; an object supporting one method: fail(self, msgStr)
pair0 : pair of `float`
    pair 0
pair1 : pair of `floats`
    pair 1
maxDiff : `float`
    maximum radial separation between the two points
msg : `str`
    exception message prefix; details of the error are appended after ": "

Raises
------
AssertionError
    Raised if the radial difference is greater than ``maxDiff``

Notes
-----
.. warning::

   Does not compare types, just compares values.

Definition at line 96 of file testUtils.py.

96 def assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ"):
97  """Assert that two Cartesian points are almost equal.
98 
99  Each point can be any indexable pair of two floats, including
100  Point2D or Extent2D, a list or a tuple.
101 
102  Parameters
103  ----------
104  testCase : `unittest.TestCase`
105  test case the test is part of; an object supporting one method: fail(self, msgStr)
106  pair0 : pair of `float`
107  pair 0
108  pair1 : pair of `floats`
109  pair 1
110  maxDiff : `float`
111  maximum radial separation between the two points
112  msg : `str`
113  exception message prefix; details of the error are appended after ": "
114 
115  Raises
116  ------
117  AssertionError
118  Raised if the radial difference is greater than ``maxDiff``
119 
120  Notes
121  -----
122  .. warning::
123 
124  Does not compare types, just compares values.
125  """
126  if len(pair0) != 2:
127  raise RuntimeError("len(pair0)=%s != 2" % (len(pair0),))
128  if len(pair1) != 2:
129  raise RuntimeError("len(pair1)=%s != 2" % (len(pair1),))
130 
131  pairDiff = [float(pair1[i] - pair0[i]) for i in range(2)]
132  measDiff = math.hypot(*pairDiff)
133  if measDiff > maxDiff:
134  testCase.fail("%s: measured radial distance = %s > maxDiff = %s, pair0=(%r, %r), pair1=(%r, %r)" %
135  (msg, measDiff, maxDiff, pair0[0], pair0[1], pair1[0], pair1[1]))
136 
137 
138 @lsst.utils.tests.inTestCase
def assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ")
Definition: testUtils.py:96

◆ assertSpherePointListsAlmostEqual()

def lsst.geom.testUtils.assertSpherePointListsAlmostEqual (   testCase,
  splist0,
  splist1,
  maxSep = 0.001*arcseconds,
  msg = None 
)
Assert that two lists of `~lsst.geom.SpherePoint`\ s are almost equal

Parameters
----------
testCase : `unittest.TestCase`
    test case the test is part of; an object supporting one method:
    fail(self, msgStr)
splist0 : `list` of `lsst.geom.SpherePoint`
    list of SpherePoints 0
splist1 : `list` of `lsst.geom.SpherePoint`
    list of SpherePoints 1
maxSep : `lsst.geom.Angle`
    maximum separation
msg : `str`
    exception message prefix; details of the error are appended after ": "

Raises
------
AssertionError
    The SpherePoint lists are not equal.

Definition at line 214 of file testUtils.py.

214 def assertSpherePointListsAlmostEqual(testCase, splist0, splist1, maxSep=0.001*arcseconds, msg=None):
215  r"""Assert that two lists of `~lsst.geom.SpherePoint`\ s are almost equal
216 
217  Parameters
218  ----------
219  testCase : `unittest.TestCase`
220  test case the test is part of; an object supporting one method:
221  fail(self, msgStr)
222  splist0 : `list` of `lsst.geom.SpherePoint`
223  list of SpherePoints 0
224  splist1 : `list` of `lsst.geom.SpherePoint`
225  list of SpherePoints 1
226  maxSep : `lsst.geom.Angle`
227  maximum separation
228  msg : `str`
229  exception message prefix; details of the error are appended after ": "
230 
231  Raises
232  ------
233  AssertionError
234  The SpherePoint lists are not equal.
235  """
236  testCase.assertEqual(len(splist0), len(splist1), msg=msg)
237  sepArr = np.array([sp0.separation(sp1)
238  for sp0, sp1 in zip(splist0, splist1)])
239  badArr = sepArr > maxSep
240  if np.any(badArr):
241  maxInd = np.argmax(sepArr)
242  testCase.fail("SpherePointLists differ in %s places; max separation is at %s: %s\" > %s\"%s" %
243  (np.sum(badArr), maxInd, sepArr[maxInd].asArcseconds(),
244  maxSep.asArcseconds(), extraMsg(msg)))
245 
246 
247 @lsst.utils.tests.inTestCase
def assertSpherePointListsAlmostEqual(testCase, splist0, splist1, maxSep=0.001 *arcseconds, msg=None)
Definition: testUtils.py:214

◆ assertSpherePointsAlmostEqual()

def lsst.geom.testUtils.assertSpherePointsAlmostEqual (   testCase,
  sp0,
  sp1,
  maxSep = 0.001*arcseconds,
  msg = "" 
)
Assert that two `~lsst.geom.SpherePoint`\ s are almost equal

Parameters
----------
testCase : `unittest.TestCase`
    test case the test is part of; an object supporting one method:
    fail(self, msgStr)
sp0 : `lsst.geom.SpherePoint`
    SpherePoint 0
sp1 : `lsst.geom.SpherePoint`
    SpherePoint 1
maxSep : `lsst.geom.Angle`
    maximum separation
msg : `str`
    extra information to be printed with any error message

Raises
------
AssertionError
    The SpherePoints are not equal.

Definition at line 186 of file testUtils.py.

186 def assertSpherePointsAlmostEqual(testCase, sp0, sp1, maxSep=0.001*arcseconds, msg=""):
187  r"""Assert that two `~lsst.geom.SpherePoint`\ s are almost equal
188 
189  Parameters
190  ----------
191  testCase : `unittest.TestCase`
192  test case the test is part of; an object supporting one method:
193  fail(self, msgStr)
194  sp0 : `lsst.geom.SpherePoint`
195  SpherePoint 0
196  sp1 : `lsst.geom.SpherePoint`
197  SpherePoint 1
198  maxSep : `lsst.geom.Angle`
199  maximum separation
200  msg : `str`
201  extra information to be printed with any error message
202 
203  Raises
204  ------
205  AssertionError
206  The SpherePoints are not equal.
207  """
208  if sp0.separation(sp1) > maxSep:
209  testCase.fail("Angular separation between %s and %s = %s\" > maxSep = %s\"%s" %
210  (sp0, sp1, sp0.separation(sp1).asArcseconds(), maxSep.asArcseconds(), extraMsg(msg)))
211 
212 
213 @lsst.utils.tests.inTestCase
def assertSpherePointsAlmostEqual(testCase, sp0, sp1, maxSep=0.001 *arcseconds, msg="")
Definition: testUtils.py:186

◆ extraMsg()

def lsst.geom.testUtils.extraMsg (   msg)
Format extra error message, if any

Definition at line 37 of file testUtils.py.

37 def extraMsg(msg):
38  """Format extra error message, if any
39  """
40  if msg:
41  return ": " + msg
42  return ""
43 
44 
45 @lsst.utils.tests.inTestCase