lsst.afw  13.0-49-g6f23dda
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 lsst.utils.tests
32 import lsst.afw.geom as afwGeom
33 
34 
35 @lsst.utils.tests.inTestCase
36 def assertCoordsAlmostEqual(testCase, coord0, coord1, maxDiff=0.001*afwGeom.arcseconds, msg="Coords differ"):
37  """!Assert that two coords represent almost the same point on the sky
38 
39  @warning the coordinate systems are not compared; instead both angles are converted to ICRS
40  and the angular separation measured.
41 
42  @param[in] testCase unittest.TestCase instance the test is part of;
43  an object supporting one method: fail(self, msgStr)
44  @param[in] coord0 coord 0 (an lsst.afw.geom.Coord)
45  @param[in] coord1 coord 1 (an lsst.afw.geom.Coord)
46  @param[in] maxDiff maximum angular separation between the two coords (an lsst.afw.geom.Angle)
47  @param[in] msg exception message prefix; details of the error are appended after ": "
48 
49  @throw AssertionError if the unwrapped difference is greater than maxDiff
50  """
51  measDiff = coord0.toIcrs().angularSeparation(coord1.toIcrs())
52  if measDiff > maxDiff:
53  testCase.fail("%s: measured angular separation %s arcsec > max allowed %s arcsec" %
54  (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
55 
56 
57 @lsst.utils.tests.inTestCase
58 def assertCoordsNearlyEqual(*args, **kwargs):
59  warnings.warn("Deprecated. Use assertCoordsAlmostEqual",
60  DeprecationWarning)
61  assertCoordsAlmostEqual(*args, **kwargs)
def assertCoordsNearlyEqual
Definition: utils.py:58
def assertCoordsAlmostEqual
Assert that two coords represent almost the same point on the sky.
Definition: utils.py:36