LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
makeSkyMap.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008-2015 AURA/LSST.
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 <https://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 precall(self, parsedCmd):
58  # We overload to disable writing/checking of schemas and configs.
59  # There's only one SkyMap per rerun anyway, so the config is redundant,
60  # and checking it means we can't overwrite or append to one once we've
61  # written it.
62  return True
63 
64  def __call__(self, butler):
65  task = self.TaskClass(config=self.config, log=self.log)
66  if self.doRaise:
67  results = task.run(butler)
68  else:
69  try:
70  results = task.run(butler)
71  except Exception, e:
72  task.log.fatal("Failed: %s" % e)
73  if not isinstance(e, pipeBase.TaskError):
74  traceback.print_exc(file=sys.stderr)
75  task.writeMetadata(butler)
76  if self.doReturnResults:
77  return results
78 
79 class MakeSkyMapTask(pipeBase.CmdLineTask):
80  """!Make a sky map in a repository
81 
82  Making a sky map in a repository is a prerequisite for making a coadd,
83  since the sky map is used as the pixelization for the coadd.
84  """
85  ConfigClass = MakeSkyMapConfig
86  _DefaultName = "makeSkyMap"
87  RunnerClass = MakeSkyMapRunner
88 
89  def __init__(self, **kwargs):
90  pipeBase.CmdLineTask.__init__(self, **kwargs)
91 
92  @pipeBase.timeMethod
93  def run(self, butler):
94  """!Make a skymap, persist it (optionally) and log some information about it
95 
96  @param[in] butler data butler
97  @return a pipeBase Struct containing:
98  - skyMap: the constructed SkyMap
99  """
100  skyMap = self.config.skyMap.apply()
101  self.logSkyMapInfo(skyMap)
102  if self.config.doWrite:
103  butler.put(skyMap, self.config.coaddName + "Coadd_skyMap")
104  return pipeBase.Struct(
105  skyMap = skyMap
106  )
107 
108  def logSkyMapInfo(self, skyMap):
109  """!Log information about a sky map
110 
111  @param[in] skyMap sky map (an lsst.skyMap.SkyMap)
112  """
113  self.log.info("sky map has %s tracts" % (len(skyMap),))
114  for tractInfo in skyMap:
115  wcs = tractInfo.getWcs()
116  posBox = afwGeom.Box2D(tractInfo.getBBox())
117  pixelPosList = (
118  posBox.getMin(),
119  afwGeom.Point2D(posBox.getMaxX(), posBox.getMinY()),
120  posBox.getMax(),
121  afwGeom.Point2D(posBox.getMinX(), posBox.getMaxY()),
122  )
123  skyPosList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees) for pos in pixelPosList]
124  posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
125  self.log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches" % \
126  (tractInfo.getId(), ", ".join(posStrList), \
127  tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
128 
129  @classmethod
131  """Create an argument parser
132 
133  No identifiers are added because none are used.
134  """
135  return pipeBase.ArgumentParser(name=cls._DefaultName)
136 
137  def _getConfigName(self):
138  """Return the name of the config dataset
139  """
140  return "%s_makeSkyMap_config" % (self.config.coaddName,)
141 
142  def _getMetadataName(self):
143  """Return the name of the metadata dataset
144  """
145  return "%s_makeSkyMap_metadata" % (self.config.coaddName,)
146 
def run
Make a skymap, persist it (optionally) and log some information about it.
Definition: makeSkyMap.py:93
def logSkyMapInfo
Log information about a sky map.
Definition: makeSkyMap.py:108
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
Make a sky map in a repository.
Definition: makeSkyMap.py:79