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
wcsFactory.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 import math
23 
24 import lsst.daf.base as dafBase
25 import lsst.afw.coord as afwCoord
26 import lsst.afw.geom as afwGeom
27 import lsst.afw.image as afwImage
28 
29 class WcsFactory(object):
30  """A factory for creating Wcs objects for the sky tiles.
31  """
32  def __init__(self, pixelScale, projection, rotation=0*afwGeom.radians):
33  """Make a WcsFactory
34 
35  @param[in] pixelScale: desired scale, as sky/pixel, an afwGeom.Angle
36  @param[in] projection: FITS-standard 3-letter name of projection, e.g.:
37  TAN (tangent), STG (stereographic), MOL (Mollweide's), AIT (Hammer-Aitoff)
38  see Representations of celestial coordinates in FITS (Calabretta and Greisen, 2002)
39  @param[in] rotation: Rotation relative to cardinal, as an lsst.afw.geom.Angle
40  """
41  if len(projection) != 3:
42  raise RuntimeError("projection=%r; must have length 3" % (projection,))
43  self._pixelScaleDeg = pixelScale.asDegrees()
44  self._projection = str(projection)
45  self._rotation = rotation
46  cosTerm = self._pixelScaleDeg * math.cos(rotation.asRadians())
47  sinTerm = self._pixelScaleDeg * math.sin(rotation.asRadians())
48  self._cdMatrix = {"CD1_1": -cosTerm,
49  "CD2_1": sinTerm,
50  "CD1_2": sinTerm,
51  "CD2_2": cosTerm,
52  }
53  self._ctypes = [("%-5s%3s" % (("RA", "DEC")[i], self._projection)).replace(" ", "-")
54  for i in range(2)]
55 
56  def makeWcs(self, crPixPos, crValCoord, **kargs):
57  """Make a Wcs
58 
59  @param[in] crPixPos: crPix for WCS, using the LSST standard; an afwGeom.Point2D or pair of floats
60  @param[in] crValCoord: crVal for WCS (afwCoord.Coord)
61  **kargs: FITS keyword arguments for WCS
62  """
63  ps = dafBase.PropertySet()
64  crPixFits = [ind + 1.0 for ind in crPixPos] # convert pix position to FITS standard
65  crValDeg = crValCoord.getPosition(afwGeom.degrees)
66  for i in range(2):
67  ip1 = i + 1
68  ps.add("CTYPE%1d" % (ip1,), self._ctypes[i])
69  ps.add("CRPIX%1d" % (ip1,), crPixFits[i])
70  ps.add("CRVAL%1d" % (ip1,), crValDeg[i])
71  ps.add("RADECSYS", "ICRS")
72  ps.add("EQUINOX", 2000)
73  for k,v in self._cdMatrix.items() + kargs.items():
74  ps.add(k, v)
75  return afwImage.makeWcs(ps)
Wcs::Ptr makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
Create a Wcs object from crval, crpix, CD, using CD elements (useful from python) ...
Definition: makeWcs.cc:141
Class for storing generic metadata.
Definition: PropertySet.h:82