lsst.skymap  14.0-2-g8373656+11
wcsFactory.py
Go to the documentation of this file.
1 from builtins import range
2 from builtins import object
3 #
4 # LSST Data Management System
5 # Copyright 2008, 2009, 2010 LSST Corporation.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <http://www.lsstcorp.org/LegalNotices/>.
23 #
24 import math
25 
26 import lsst.daf.base as dafBase
27 import lsst.afw.coord as afwCoord
28 import lsst.afw.geom as afwGeom
29 import lsst.afw.image as afwImage
30 
31 
32 class WcsFactory(object):
33  """A factory for creating Wcs objects for the sky tiles.
34  """
35 
36  def __init__(self, pixelScale, projection, rotation=0*afwGeom.radians):
37  """Make a WcsFactory
38 
39  @param[in] pixelScale: desired scale, as sky/pixel, an afwGeom.Angle
40  @param[in] projection: FITS-standard 3-letter name of projection, e.g.:
41  TAN (tangent), STG (stereographic), MOL (Mollweide's), AIT (Hammer-Aitoff)
42  see Representations of celestial coordinates in FITS (Calabretta and Greisen, 2002)
43  @param[in] rotation: Rotation relative to cardinal, as an lsst.afw.geom.Angle
44  """
45  if len(projection) != 3:
46  raise RuntimeError("projection=%r; must have length 3" % (projection,))
47  self._pixelScaleDeg = pixelScale.asDegrees()
48  self._projection = str(projection)
49  self._rotation = rotation
50  cosTerm = self._pixelScaleDeg * math.cos(rotation.asRadians())
51  sinTerm = self._pixelScaleDeg * math.sin(rotation.asRadians())
52  self._cdMatrix = {"CD1_1": -cosTerm,
53  "CD2_1": sinTerm,
54  "CD1_2": sinTerm,
55  "CD2_2": cosTerm,
56  }
57  self._ctypes = [("%-5s%3s" % (("RA", "DEC")[i], self._projection)).replace(" ", "-")
58  for i in range(2)]
59 
60  def makeWcs(self, crPixPos, crValCoord, **kargs):
61  """Make a Wcs
62 
63  @param[in] crPixPos: crPix for WCS, using the LSST standard; an afwGeom.Point2D or pair of floats
64  @param[in] crValCoord: crVal for WCS (afwCoord.Coord)
65  **kargs: FITS keyword arguments for WCS
66  """
67  ps = dafBase.PropertySet()
68  crPixFits = [ind + 1.0 for ind in crPixPos] # convert pix position to FITS standard
69  crValDeg = crValCoord.getPosition(afwGeom.degrees)
70  for i in range(2):
71  ip1 = i + 1
72  ps.add("CTYPE%1d" % (ip1,), self._ctypes[i])
73  ps.add("CRPIX%1d" % (ip1,), crPixFits[i])
74  ps.add("CRVAL%1d" % (ip1,), crValDeg[i])
75  ps.add("RADECSYS", "ICRS")
76  ps.add("EQUINOX", 2000)
77  for k, v in list(self._cdMatrix.items()) + list(kargs.items()):
78  ps.add(k, v)
79  return afwImage.makeWcs(ps)
def __init__(self, pixelScale, projection, rotation=0 *afwGeom.radians)
Definition: wcsFactory.py:36
def makeWcs(self, crPixPos, crValCoord, kargs)
Definition: wcsFactory.py:60