LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
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)
boost::shared_ptr< Wcs > 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:138
Class for storing generic metadata.
Definition: PropertySet.h:82