LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
utils.py
Go to the documentation of this file.
1 from __future__ import absolute_import, division
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 import lsst.utils.tests
28 import lsst.afw.geom as afwGeom
29 
30 __all__ = ["assertCoordsNearlyEqual"]
31 
32 @lsst.utils.tests.inTestCase
33 def assertCoordsNearlyEqual(testCase, coord0, coord1, maxDiff=0.001*afwGeom.arcseconds, msg="Coords differ"):
34  """!Assert that two coords represent nearly the same point on the sky
35 
36  @warning the coordinate systems are not compared; instead both angles are converted to ICRS
37  and the angular separation measured.
38 
39  @param[in] testCase unittest.TestCase instance the test is part of;
40  an object supporting one method: fail(self, msgStr)
41  @param[in] coord0 coord 0 (an lsst.afw.geom.Coord)
42  @param[in] coord1 coord 1 (an lsst.afw.geom.Coord)
43  @param[in] maxDiff maximum angular separation between the two coords (an lsst.afw.geom.Angle)
44  @param[in] msg exception message prefix; details of the error are appended after ": "
45 
46  @throw AssertionError if the unwrapped difference is greater than maxDiff
47  """
48  measDiff = coord0.toIcrs().angularSeparation(coord1.toIcrs())
49  if measDiff > maxDiff:
50  testCase.fail("%s: measured angular separation %s arcsec > max allowed %s arcsec" %
51  (msg, measDiff.asArcseconds(), maxDiff.asArcseconds()))
def assertCoordsNearlyEqual
Assert that two coords represent nearly the same point on the sky.
Definition: utils.py:33