22 """Utilities that should be imported into the lsst.geom namespace when 25 In the case of the assert functions, importing them makes them available in lsst.utils.tests.TestCase 34 from ._geom
import arcseconds
38 """Format extra error message, if any 45 @lsst.utils.tests.inTestCase
47 ignoreWrap=True, msg="Angles differ"):
48 r"""Assert that two `~lsst.geom.Angle`\ s are almost equal, ignoring 49 wrap differences by default. 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. 56 testCase : `unittest.TestCase` 57 test case the test is part of; an object supporting one method: 59 ang0 : `lsst.geom.Angle` 61 ang1 : `lsst.geom.Angle` 63 maxDiff : `lsst.geom.Angle` 64 maximum difference between the two angles 66 ignore wrap when comparing the angles? 67 - if True then wrap is ignored, e.g. 0 and 360 degrees are considered 69 - if False then wrap matters, e.g. 0 and 360 degrees are considered 72 exception message prefix; details of the error are appended after ": " 77 Raised if the difference is greater than ``maxDiff`` 79 isNan0 = math.isnan(ang0.asRadians())
80 isNan1 = math.isnan(ang1.asRadians())
84 testCase.fail(
"ang0 is NaN")
86 testCase.fail(
"ang1 is NaN")
87 measDiff = ang1 - ang0
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()))
95 @lsst.utils.tests.inTestCase
97 """Assert that two Cartesian points are almost equal. 99 Each point can be any indexable pair of two floats, including 100 Point2D or Extent2D, a list or a tuple. 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` 108 pair1 : pair of `floats` 111 maximum radial separation between the two points 113 exception message prefix; details of the error are appended after ": " 118 Raised if the radial difference is greater than ``maxDiff`` 124 Does not compare types, just compares values. 127 raise RuntimeError(
"len(pair0)=%s != 2" % (len(pair0),))
129 raise RuntimeError(
"len(pair1)=%s != 2" % (len(pair1),))
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]))
138 @lsst.utils.tests.inTestCase
140 """Assert that two lists of Cartesian points are almost equal 142 Each point can be any indexable pair of two floats, including 143 Point2D or Extent2D, a list or a tuple. 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` 151 list1 : `list` of pairs of `float` 154 maximum radial separation between the two points 156 additional information for the error message; appended after ": " 161 Raised if the radial difference is greater than ``maxDiff`` 167 Does not compare types, just values. 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))
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
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)))
185 @lsst.utils.tests.inTestCase
187 r"""Assert that two `~lsst.geom.SpherePoint`\ s are almost equal 191 testCase : `unittest.TestCase` 192 test case the test is part of; an object supporting one method: 194 sp0 : `lsst.geom.SpherePoint` 196 sp1 : `lsst.geom.SpherePoint` 198 maxSep : `lsst.geom.Angle` 201 extra information to be printed with any error message 206 The SpherePoints are not equal. 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)))
213 @lsst.utils.tests.inTestCase
215 r"""Assert that two lists of `~lsst.geom.SpherePoint`\ s are almost equal 219 testCase : `unittest.TestCase` 220 test case the test is part of; an object supporting one method: 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` 229 exception message prefix; details of the error are appended after ": " 234 The SpherePoint lists are not equal. 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
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)))
247 @lsst.utils.tests.inTestCase
249 """Assert that two boxes (`~lsst.geom.Box2D` or `~lsst.geom.Box2I`) are 254 testCase : `unittest.TestCase` 255 test case the test is part of; an object supporting one method: 257 box0 : `lsst.geom.Box2D` or `lsst.geom.Box2I` 259 box1 : `lsst.geom.Box2D` or `lsst.geom.Box2I` 262 maximum radial separation between the min points and max points 264 exception message prefix; details of the error are appended after ": " 269 Raised if the radial difference of the min points or max points is 276 Does not compare types, just compares values. 279 box1.getMin(), maxDiff=maxDiff, msg=msg +
": min")
281 box1.getMax(), maxDiff=maxDiff, msg=msg +
": max")
def assertPairsAlmostEqual(testCase, pair0, pair1, maxDiff=1e-7, msg="Pairs differ")
Angle abs(Angle const &a)
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)