lsst.skymap  21.0.0-4-g65b4814+0a61ef3a55
utils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 __all__ = ["coordFromVec"]
24 
25 import numpy
26 
27 import lsst.sphgeom
28 import lsst.geom as geom
29 
30 
31 _TinyFloat = numpy.finfo(float).tiny
32 
33 
34 def coordFromVec(vec, defRA=None):
35  """Convert an ICRS cartesian vector to an ICRS lsst.geom.SpherePoint
36 
37  Parameters
38  ----------
39  vec : `list` of `float`
40  An ICRS catesian vector.
41  defRA : `lsst.geom.Angle` or None
42  The RA to use if the vector is too near a pole;
43  ignored if not near a pole.
44 
45  Raises
46  ------
47  RuntimeError
48  If vec too near a pole and defRA is None.
49  """
50  if abs(vec[0]) < _TinyFloat and abs(vec[1]) < _TinyFloat:
51  if defRA is None:
52  raise RuntimeError("At pole and defRA==None")
53  if vec[2] > 0:
54  decDeg = 90.0
55  else:
56  decDeg = -90.0
57  return geom.SpherePoint(defRA, decDeg*geom.degrees)
def coordFromVec(vec, defRA=None)
Definition: utils.py:34