LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.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 46 of file testUtils.py.

46 def assertAnglesAlmostEqual(testCase, ang0, ang1, maxDiff=0.001*arcseconds,
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 
68  - if True then wrap is ignored, e.g. 0 and 360 degrees are considered
69  equal
70  - if False then wrap matters, e.g. 0 and 360 degrees are considered
71  different
72 
73  msg : `str`
74  exception message prefix; details of the error are appended after ": "
75 
76  Raises
77  ------
78  AssertionError
79  Raised if the difference is greater than ``maxDiff``
80  """
81  isNan0 = math.isnan(ang0.asRadians())
82  isNan1 = math.isnan(ang1.asRadians())
83  if isNan0 and isNan1:
84  return
85  if isNan0:
86  testCase.fail("ang0 is NaN")
87  if isNan1:
88  testCase.fail("ang1 is NaN")
89  measDiff = ang1 - ang0
90  if ignoreWrap:
91  measDiff = measDiff.wrapCtr()
92  if abs(measDiff) > maxDiff:
93  testCase.fail("%s: measured difference %s arcsec > max allowed %s arcsec" %
94  (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
95 
96 
97 @lsst.utils.tests.inTestCase

◆ 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 250 of file testUtils.py.

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

◆ 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 141 of file testUtils.py.

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

◆ 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 98 of file testUtils.py.

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

◆ 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 216 of file testUtils.py.

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

◆ 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 188 of file testUtils.py.

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

◆ 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
lsst::geom.testUtils.assertBoxesAlmostEqual
def assertBoxesAlmostEqual(testCase, box0, box1, maxDiff=1e-7, msg="Boxes differ")
Definition: testUtils.py:250
lsst::sphgeom::abs
Angle abs(Angle const &a)
Definition: Angle.h:106
lsst::geom.testUtils.assertSpherePointListsAlmostEqual
def assertSpherePointListsAlmostEqual(testCase, splist0, splist1, maxSep=0.001 *arcseconds, msg=None)
Definition: testUtils.py:216
lsst::geom.testUtils.assertSpherePointsAlmostEqual
def assertSpherePointsAlmostEqual(testCase, sp0, sp1, maxSep=0.001 *arcseconds, msg="")
Definition: testUtils.py:188
lsst::geom.testUtils.assertPairListsAlmostEqual
def assertPairListsAlmostEqual(testCase, list0, list1, maxDiff=1e-7, msg=None)
Definition: testUtils.py:141
lsst::geom.testUtils.extraMsg
def extraMsg(msg)
Definition: testUtils.py:37
lsst::geom.testUtils.assertPairsAlmostEqual
def assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ")
Definition: testUtils.py:98
lsst::geom.testUtils.assertAnglesAlmostEqual
def assertAnglesAlmostEqual(testCase, ang0, ang1, maxDiff=0.001 *arcseconds, ignoreWrap=True, msg="Angles differ")
Definition: testUtils.py:46