lsst.skymap  13.0-2-gf9e84ea+13
 All Classes Namespaces Files Functions Variables Pages
equatSkyMap.py
Go to the documentation of this file.
1 from __future__ import division
2 from builtins import range
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 lsst.pex.config as pexConfig
25 import lsst.afw.coord as afwCoord
26 import lsst.afw.geom as afwGeom
27 from .baseSkyMap import BaseSkyMap
28 from .tractInfo import TractInfo
29 
30 
31 class EquatSkyMapConfig(BaseSkyMap.ConfigClass):
32  numTracts = pexConfig.Field(
33  doc="number of tracts; warning: TAN projection requires at least 3",
34  dtype=int,
35  default=4,
36  )
37  decRange = pexConfig.ListField(
38  doc="range of declination (deg)",
39  dtype=float,
40  length=2,
41  default=(-1.25, 1.25),
42  )
43 
44  def setDefaults(self):
45  self.projection = "CEA"
46 
47 
48 class EquatSkyMap(BaseSkyMap):
49  """Equatorial sky map pixelization, e.g. for SDSS stripe 82 image data.
50 
51  EquatSkyMap represents an equatorial band of sky divided along declination into overlapping tracts.
52  """
53  ConfigClass = EquatSkyMapConfig
54  _version = (1, 0) # for pickle
55 
56  def __init__(self, config=None):
57  """Construct a EquatSkyMap
58 
59  @param[in] config: an instance of self.ConfigClass; if None the default config is used
60  """
61  BaseSkyMap.__init__(self, config)
62 
63  decRange = tuple(afwGeom.Angle(dr, afwGeom.degrees) for dr in self.config.decRange)
64  midDec = (decRange[0] + decRange[1]) / 2.0
65  tractWidthRA = afwGeom.Angle(360.0 / self.config.numTracts, afwGeom.degrees)
66  tractOverlap = afwGeom.Angle(self.config.tractOverlap, afwGeom.degrees)
67 
68  for id in range(self.config.numTracts):
69  begRA = tractWidthRA * id
70  endRA = begRA + tractWidthRA
71  vertexCoordList = (
72  afwCoord.IcrsCoord(begRA, decRange[0]),
73  afwCoord.IcrsCoord(endRA, decRange[0]),
74  afwCoord.IcrsCoord(endRA, decRange[1]),
75  afwCoord.IcrsCoord(begRA, decRange[1]),
76  )
77 
78  midRA = begRA + tractWidthRA / 2.0
79  ctrCoord = afwCoord.IcrsCoord(midRA, midDec)
80 
81  # CRVal must have Dec=0 for symmetry about the equator
82  crValCoord = afwCoord.IcrsCoord(midRA, afwGeom.Angle(0.0))
83 
84  # make initial WCS; don't worry about crPixPos because TractInfo will shift it as required
85  wcs = self._wcsFactory.makeWcs(crPixPos=afwGeom.Point2D(0, 0), crValCoord=crValCoord)
86 
87  self._tractInfoList.append(TractInfo(
88  id=id,
89  patchInnerDimensions=self.config.patchInnerDimensions,
90  patchBorder=self.config.patchBorder,
91  ctrCoord=ctrCoord,
92  vertexCoordList=vertexCoordList,
93  tractOverlap=tractOverlap,
94  wcs=wcs,
95  ))
96 
97  def __getstate__(self):
98  """Support pickle
99 
100  @return a dict containing:
101  - version: a pair of ints
102  - config: the config
103  """
104  return dict(
105  version=self._version,
106  config=self.config,
107  )
108 
109  def __setstate__(self, stateDict):
110  """Support unpickle
111 
112  @param[in] stateDict: a dict containing:
113  - version: a pair of ints
114  - config: the config
115  """
116  version = stateDict["version"]
117  if version >= (2, 0):
118  raise runtimeError("Version = %s >= (2,0); cannot unpickle" % (version,))
119  self.__init__(stateDict["config"])
120 
121  def getVersion(self):
122  """Return version (e.g. for pickle)
123 
124  @return version as a pair of integers
125  """
126  return self._version