LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
makeSkyMap.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 import sys
24 import traceback
25 
26 import lsst.afw.geom as afwGeom
27 import lsst.pex.config as pexConfig
28 import lsst.pipe.base as pipeBase
29 from lsst.skymap import skyMapRegistry
30 
31 class MakeSkyMapConfig(pexConfig.Config):
32  """Config for MakeSkyMapTask
33  """
34  coaddName = pexConfig.Field(
35  doc = "coadd name, e.g. deep, goodSeeing, chiSquared",
36  dtype = str,
37  default = "deep",
38  )
39  skyMap = skyMapRegistry.makeField(
40  doc = "type of skyMap",
41  default = "dodeca",
42  )
43  doWrite = pexConfig.Field(
44  doc = "persist the skyMap? If False then run generates the sky map and returns it, " \
45  + "but does not save it to the data repository",
46  dtype = bool,
47  default = True,
48  )
49 
50 
51 class MakeSkyMapRunner(pipeBase.TaskRunner):
52  """Only need a single butler instance to run on."""
53  @staticmethod
54  def getTargetList(parsedCmd):
55  return [parsedCmd.butler]
56 
57  def __call__(self, butler):
58  task = self.TaskClass(config=self.config, log=self.log)
59  if self.doRaise:
60  results = task.run(butler)
61  else:
62  try:
63  results = task.run(butler)
64  except Exception, e:
65  task.log.fatal("Failed: %s" % e)
66  if not isinstance(e, pipeBase.TaskError):
67  traceback.print_exc(file=sys.stderr)
68  task.writeMetadata(butler)
69  if self.doReturnResults:
70  return results
71 
72 class MakeSkyMapTask(pipeBase.CmdLineTask):
73  """Make a sky map in a repository
74 
75  Making a sky map in a repository is a prerequisite for making a coadd,
76  since the sky map is used as the pixelization for the coadd.
77  """
78  ConfigClass = MakeSkyMapConfig
79  _DefaultName = "makeSkyMap"
80  RunnerClass = MakeSkyMapRunner
81 
82  def __init__(self, **kwargs):
83  pipeBase.CmdLineTask.__init__(self, **kwargs)
84 
85  @pipeBase.timeMethod
86  def run(self, butler):
87  """Make a skymap, persist it (optionally) and log some information about it
88 
89  @param butler: data butler
90  @return a pipeBase Struct containing:
91  - skyMap: the constructed SkyMap
92  """
93  skyMap = self.config.skyMap.apply()
94  self.logSkyMapInfo(skyMap)
95  if self.config.doWrite:
96  butler.put(skyMap, self.config.coaddName + "Coadd_skyMap")
97  return pipeBase.Struct(
98  skyMap = skyMap
99  )
100 
101  def logSkyMapInfo(self, skyMap):
102  """Log information about a sky map
103 
104  @param[in] skyMap: sky map (an lsst.skyMap.SkyMap)
105  """
106  self.log.info("sky map has %s tracts" % (len(skyMap),))
107  for tractInfo in skyMap:
108  wcs = tractInfo.getWcs()
109  posBox = afwGeom.Box2D(tractInfo.getBBox())
110  pixelPosList = (
111  posBox.getMin(),
112  afwGeom.Point2D(posBox.getMaxX(), posBox.getMinY()),
113  posBox.getMax(),
114  afwGeom.Point2D(posBox.getMinX(), posBox.getMaxY()),
115  )
116  skyPosList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees) for pos in pixelPosList]
117  posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
118  self.log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches" % \
119  (tractInfo.getId(), ", ".join(posStrList), \
120  tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
121 
122  @classmethod
124  """Create an argument parser
125 
126  No identifiers are added because none are used.
127  """
128  return pipeBase.ArgumentParser(name=cls._DefaultName)
129 
130  def _getConfigName(self):
131  """Return the name of the config dataset
132  """
133  return "%s_makeSkyMap_config" % (self.config.coaddName,)
134 
135  def _getMetadataName(self):
136  """Return the name of the metadata dataset
137  """
138  return "%s_makeSkyMap_metadata" % (self.config.coaddName,)
139 
A floating-point coordinate rectangle geometry.
Definition: Box.h:271