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
makeSkyMap.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008-2015 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
21 #
22 import sys
23 import traceback
24 
25 import lsst.afw.geom as afwGeom
26 import lsst.pex.config as pexConfig
27 import lsst.pipe.base as pipeBase
28 from lsst.skymap import skyMapRegistry
29 
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 as 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 
80 class MakeSkyMapTask(pipeBase.CmdLineTask):
81  """!Make a sky map in a repository
82 
83  Making a sky map in a repository is a prerequisite for making a coadd,
84  since the sky map is used as the pixelization for the coadd.
85  """
86  ConfigClass = MakeSkyMapConfig
87  _DefaultName = "makeSkyMap"
88  RunnerClass = MakeSkyMapRunner
89 
90  def __init__(self, **kwargs):
91  pipeBase.CmdLineTask.__init__(self, **kwargs)
92 
93  @pipeBase.timeMethod
94  def run(self, butler):
95  """!Make a skymap, persist it (optionally) and log some information about it
96 
97  @param[in] butler data butler
98  @return a pipeBase Struct containing:
99  - skyMap: the constructed SkyMap
100  """
101  skyMap = self.config.skyMap.apply()
102  self.logSkyMapInfo(skyMap)
103  if self.config.doWrite:
104  butler.put(skyMap, self.config.coaddName + "Coadd_skyMap")
105  return pipeBase.Struct(
106  skyMap=skyMap
107  )
108 
109  def logSkyMapInfo(self, skyMap):
110  """!Log information about a sky map
111 
112  @param[in] skyMap sky map (an lsst.skyMap.SkyMap)
113  """
114  self.log.info("sky map has %s tracts" % (len(skyMap),))
115  for tractInfo in skyMap:
116  wcs = tractInfo.getWcs()
117  posBox = afwGeom.Box2D(tractInfo.getBBox())
118  pixelPosList = (
119  posBox.getMin(),
120  afwGeom.Point2D(posBox.getMaxX(), posBox.getMinY()),
121  posBox.getMax(),
122  afwGeom.Point2D(posBox.getMinX(), posBox.getMaxY()),
123  )
124  skyPosList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees) for pos in pixelPosList]
125  posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
126  self.log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches" %
127  (tractInfo.getId(), ", ".join(posStrList),
128  tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
129 
130  @classmethod
132  """Create an argument parser
133 
134  No identifiers are added because none are used.
135  """
136  return pipeBase.ArgumentParser(name=cls._DefaultName)
137 
138  def _getConfigName(self):
139  """Return the name of the config dataset
140  """
141  return "%s_makeSkyMap_config" % (self.config.coaddName,)
142 
143  def _getMetadataName(self):
144  """Return the name of the metadata dataset
145  """
146  return "%s_makeSkyMap_metadata" % (self.config.coaddName,)
def run
Make a skymap, persist it (optionally) and log some information about it.
Definition: makeSkyMap.py:94
def logSkyMapInfo
Log information about a sky map.
Definition: makeSkyMap.py:109
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
Make a sky map in a repository.
Definition: makeSkyMap.py:80