22 """Utilities that should be imported into the lsst.geom namespace when lsst.geom is used 24 In the case of the assert functions, importing them makes them available in lsst.utils.tests.TestCase 33 from ._geom
import arcseconds
37 """Format extra error message, if any 44 @lsst.utils.tests.inTestCase
46 ignoreWrap=True, msg="Angles differ"):
47 r"""Assert that two `~lsst.afw.geom.Angle`\ s are almost equal, ignoring wrap differences by default 51 testCase : `unittest.TestCase` 52 test case the test is part of; an object supporting one method: fail(self, msgStr) 53 ang0 : `lsst.afw.geom.Angle` 55 ang1 : `an lsst.afw.geom.Angle` 57 maxDiff : `an lsst.afw.geom.Angle` 58 maximum difference between the two angles 60 ignore wrap when comparing the angles? 61 - if True then wrap is ignored, e.g. 0 and 360 degrees are considered equal 62 - if False then wrap matters, e.g. 0 and 360 degrees are considered different 64 exception message prefix; details of the error are appended after ": " 69 Raised if the difference is greater than ``maxDiff`` 71 measDiff = ang1 - ang0
73 measDiff = measDiff.wrapCtr()
74 if abs(measDiff) > maxDiff:
75 testCase.fail(
"%s: measured difference %s arcsec > max allowed %s arcsec" %
76 (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
79 @lsst.utils.tests.inTestCase
81 """Assert that two Cartesian points are almost equal. 83 Each point can be any indexable pair of two floats, including 84 Point2D or Extent2D, a list or a tuple. 88 testCase : `unittest.TestCase` 89 test case the test is part of; an object supporting one method: fail(self, msgStr) 90 pair0 : pair of `float` 92 pair1 : pair of `floats` 95 maximum radial separation between the two points 97 exception message prefix; details of the error are appended after ": " 102 Raised if the radial difference is greater than ``maxDiff`` 108 Does not compare types, just compares values. 111 raise RuntimeError(
"len(pair0)=%s != 2" % (len(pair0),))
113 raise RuntimeError(
"len(pair1)=%s != 2" % (len(pair1),))
115 pairDiff = [float(pair1[i] - pair0[i])
for i
in range(2)]
116 measDiff = math.hypot(*pairDiff)
117 if measDiff > maxDiff:
118 testCase.fail(
"%s: measured radial distance = %s > maxDiff = %s, pair0=(%r, %r), pair1=(%r, %r)" %
119 (msg, measDiff, maxDiff, pair0[0], pair0[1], pair1[0], pair1[1]))
122 @lsst.utils.tests.inTestCase
124 """Assert that two lists of Cartesian points are almost equal 126 Each point can be any indexable pair of two floats, including 127 Point2D or Extent2D, a list or a tuple. 131 testCase : `unittest.TestCase` 132 test case the test is part of; an object supporting one method: fail(self, msgStr) 133 list0 : `list` of pairs of `float` 135 list1 : `list` of pairs of `float` 138 maximum radial separation between the two points 140 additional information for the error message; appended after ": " 145 Raised if the radial difference is greater than ``maxDiff`` 151 Does not compare types, just values. 153 testCase.assertEqual(len(list0), len(list1))
154 lenList1 = np.array([len(val)
for val
in list0])
155 lenList2 = np.array([len(val)
for val
in list1])
156 testCase.assertTrue(np.all(lenList1 == 2))
157 testCase.assertTrue(np.all(lenList2 == 2))
159 diffArr = np.array([(val0[0] - val1[0], val0[1] - val1[1])
160 for val0, val1
in zip(list0, list1)], dtype=float)
161 sepArr = np.hypot(diffArr[:, 0], diffArr[:, 1])
162 badArr = sepArr > maxDiff
164 maxInd = np.argmax(sepArr)
165 testCase.fail(
"PairLists differ in %s places; max separation is at %s: %s > %s%s" %
166 (np.sum(badArr), maxInd, sepArr[maxInd], maxDiff,
extraMsg(msg)))
169 @lsst.utils.tests.inTestCase
171 r"""Assert that two `~lsst.afw.geom.SpherePoint`\ s are almost equal 175 testCase : `unittest.TestCase` 176 test case the test is part of; an object supporting one method: fail(self, msgStr) 177 sp0 : `lsst.afw.geom.SpherePoint` 179 sp1 : `lsst.afw.geom.SpherePoint` 181 maxSep : `lsst.afw.geom.Angle` 184 extra information to be printed with any error message 186 if sp0.separation(sp1) > maxSep:
187 testCase.fail(
"Angular separation between %s and %s = %s\" > maxSep = %s\"%s" %
188 (sp0, sp1, sp0.separation(sp1).asArcseconds(), maxSep.asArcseconds(),
extraMsg(msg)))
191 @lsst.utils.tests.inTestCase
193 r"""Assert that two lists of `~lsst.afw.geom.SpherePoint`\ s are almost equal 197 testCase : `unittest.TestCase` 198 test case the test is part of; an object supporting one method: fail(self, msgStr) 199 splist0 : `list` of `lsst.afw.geom.SpherePoint` 200 list of SpherePoints 0 201 splist1 : `list` of `lsst.afw.geom.SpherePoint` 202 list of SpherePoints 1 203 maxSep : `lsst.afw.geom.Angle` 206 exception message prefix; details of the error are appended after ": " 208 testCase.assertEqual(len(splist0), len(splist1), msg=msg)
209 sepArr = np.array([sp0.separation(sp1)
210 for sp0, sp1
in zip(splist0, splist1)])
211 badArr = sepArr > maxSep
213 maxInd = np.argmax(sepArr)
214 testCase.fail(
"SpherePointLists differ in %s places; max separation is at %s: %s\" > %s\"%s" %
215 (np.sum(badArr), maxInd, sepArr[maxInd].asArcseconds(),
216 maxSep.asArcseconds(),
extraMsg(msg)))
219 @lsst.utils.tests.inTestCase
221 """Assert that two boxes (`~lsst.afw.geom.Box2D` or `~lsst.afw.geom.Box2I`) are almost equal 225 testCase : `unittest.TestCase` 226 test case the test is part of; an object supporting one method: fail(self, msgStr) 227 box0 : `lsst.afw.geom.Box2D` or `lsst.afw.geom.Box2I` 229 box1 : `lsst.afw.geom.Box2D` or `lsst.afw.geom.Box2I` 232 maximum radial separation between the min points and max points 234 exception message prefix; details of the error are appended after ": " 239 Raised if the radial difference of the min points or max points is greater than maxDiff 245 Does not compare types, just compares values. 248 box1.getMin(), maxDiff=maxDiff, msg=msg +
": min")
250 box1.getMax(), maxDiff=maxDiff, msg=msg +
": max")
def assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ")
def assertSpherePointsAlmostEqual(testCase, sp0, sp1, maxSep=0.001 *arcseconds, msg="")
def assertBoxesAlmostEqual(testCase, box0, box1, maxDiff=1e-7, msg="Boxes differ")
def assertSpherePointListsAlmostEqual(testCase, splist0, splist1, maxSep=0.001 *arcseconds, msg=None)
def assertAnglesAlmostEqual(testCase, ang0, ang1, maxDiff=0.001 *arcseconds, ignoreWrap=True, msg="Angles differ")
def assertPairListsAlmostEqual(testCase, list0, list1, maxDiff=1e-7, msg=None)