lsst.afw  14.0-25-g0e8fc950e+7
utils.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division, print_function
2 #
3 # LSST Data Management System
4 # Copyright 2015 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 """Utilities that should be imported into the lsst.afw.coord namespace when lsst.afw.coord is used
24 
25 In the case of the assert functions, importing them makes them available in lsst.utils.tests.TestCase
26 """
27 __all__ = ["assertCoordsAlmostEqual", "assertCoordsNearlyEqual"]
28 
29 import warnings
30 
31 import numpy as np
32 
33 import lsst.utils.tests
34 import lsst.afw.geom as afwGeom
35 
36 
37 @lsst.utils.tests.inTestCase
38 def assertCoordsAlmostEqual(testCase, coord0, coord1, maxDiff=0.001*afwGeom.arcseconds, msg="Coords differ"):
39  """!Assert that two coords represent almost the same point on the sky
40 
41  @warning the coordinate systems are not compared; instead both angles are converted to ICRS
42  and the angular separation measured.
43 
44  @param[in] testCase unittest.TestCase instance the test is part of;
45  an object supporting one method: fail(self, msgStr)
46  @param[in] coord0 coord 0 (an lsst.afw.geom.Coord)
47  @param[in] coord1 coord 1 (an lsst.afw.geom.Coord)
48  @param[in] maxDiff maximum angular separation between the two coords (an lsst.afw.geom.Angle)
49  @param[in] msg exception message prefix; details of the error are appended after ": "
50 
51  @throw AssertionError if the unwrapped difference is greater than maxDiff
52  """
53  measDiff = coord0.toIcrs().angularSeparation(coord1.toIcrs())
54  if measDiff > maxDiff:
55  testCase.fail("%s: measured angular separation %s arcsec > max allowed %s arcsec" %
56  (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
57 
58 
59 @lsst.utils.tests.inTestCase
60 def assertCoordListsAlmostEqual(testCase, coordlist0, coordlist1, maxDiff=0.001*afwGeom.arcseconds, msg=None):
61  """!Assert that two lists of IcrsCoords represent almost the same point on the sky
62 
63  @warning the coordinate systems are not compared; instead both sets of angles are converted to ICRS
64  and the angular separation measured.
65 
66  @param[in] testCase unittest.TestCase instance the test is part of;
67  an object supporting one method: fail(self, msgStr)
68  @param[in] coordlist0 list of IcrsCoords 0
69  @param[in] coordlist1 list of IcrsCoords 1
70  @param[in] maxDiff maximum angular separation, an lsst.afw.geom.Angle
71  @param[in] msg exception message prefix; details of the error are appended after ": "
72  """
73  testCase.assertEqual(len(coordlist0), len(coordlist1), msg=msg)
74  sepArr = np.array([sp0.toIcrs().angularSeparation(sp1.toIcrs())
75  for sp0, sp1 in zip(coordlist0, coordlist1)])
76  badArr = sepArr > maxDiff
77  if np.any(badArr):
78  maxInd = np.argmax(sepArr)
79  testCase.fail("%s: IcrsCoordLists differ in %s places; max separation is at %s: %s\" > %s\"%s" %
80  (msg, np.sum(badArr), maxInd, sepArr[maxInd].asArcseconds(),
81  maxDiff.asArcseconds()))
82 
83 
84 @lsst.utils.tests.inTestCase
85 def assertCoordsNearlyEqual(*args, **kwargs):
86  warnings.warn("Deprecated. Use assertCoordsAlmostEqual",
87  DeprecationWarning, 2)
88  assertCoordsAlmostEqual(*args, **kwargs)
def assertCoordListsAlmostEqual(testCase, coordlist0, coordlist1, maxDiff=0.001 *afwGeom.arcseconds, msg=None)
Assert that two lists of IcrsCoords represent almost the same point on the sky.
Definition: utils.py:60
def assertCoordsAlmostEqual(testCase, coord0, coord1, maxDiff=0.001 *afwGeom.arcseconds, msg="Coords differ")
Assert that two coords represent almost the same point on the sky.
Definition: utils.py:38
def assertCoordsNearlyEqual(args, kwargs)
Definition: utils.py:85