LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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 class MakeSkyMapConfig(pexConfig.Config):
31  """Config for MakeSkyMapTask
32  """
33  coaddName = pexConfig.Field(
34  doc = "coadd name, e.g. deep, goodSeeing, chiSquared",
35  dtype = str,
36  default = "deep",
37  )
38  skyMap = skyMapRegistry.makeField(
39  doc = "type of skyMap",
40  default = "dodeca",
41  )
42  doWrite = pexConfig.Field(
43  doc = "persist the skyMap? If False then run generates the sky map and returns it, " \
44  + "but does not save it to the data repository",
45  dtype = bool,
46  default = True,
47  )
48 
49 
50 class MakeSkyMapRunner(pipeBase.TaskRunner):
51  """Only need a single butler instance to run on."""
52  @staticmethod
53  def getTargetList(parsedCmd):
54  return [parsedCmd.butler]
55 
56  def precall(self, parsedCmd):
57  # We overload to disable writing/checking of schemas and configs.
58  # There's only one SkyMap per rerun anyway, so the config is redundant,
59  # and checking it means we can't overwrite or append to one once we've
60  # written it.
61  return True
62 
63  def __call__(self, butler):
64  task = self.TaskClass(config=self.config, log=self.log)
65  if self.doRaise:
66  results = task.run(butler)
67  else:
68  try:
69  results = task.run(butler)
70  except Exception, e:
71  task.log.fatal("Failed: %s" % e)
72  if not isinstance(e, pipeBase.TaskError):
73  traceback.print_exc(file=sys.stderr)
74  task.writeMetadata(butler)
75  if self.doReturnResults:
76  return results
77 
78 class MakeSkyMapTask(pipeBase.CmdLineTask):
79  """!Make a sky map in a repository
80 
81  Making a sky map in a repository is a prerequisite for making a coadd,
82  since the sky map is used as the pixelization for the coadd.
83  """
84  ConfigClass = MakeSkyMapConfig
85  _DefaultName = "makeSkyMap"
86  RunnerClass = MakeSkyMapRunner
87 
88  def __init__(self, **kwargs):
89  pipeBase.CmdLineTask.__init__(self, **kwargs)
90 
91  @pipeBase.timeMethod
92  def run(self, butler):
93  """!Make a skymap, persist it (optionally) and log some information about it
94 
95  @param[in] butler data butler
96  @return a pipeBase Struct containing:
97  - skyMap: the constructed SkyMap
98  """
99  skyMap = self.config.skyMap.apply()
100  self.logSkyMapInfo(skyMap)
101  if self.config.doWrite:
102  butler.put(skyMap, self.config.coaddName + "Coadd_skyMap")
103  return pipeBase.Struct(
104  skyMap = skyMap
105  )
106 
107  def logSkyMapInfo(self, skyMap):
108  """!Log information about a sky map
109 
110  @param[in] skyMap sky map (an lsst.skyMap.SkyMap)
111  """
112  self.log.info("sky map has %s tracts" % (len(skyMap),))
113  for tractInfo in skyMap:
114  wcs = tractInfo.getWcs()
115  posBox = afwGeom.Box2D(tractInfo.getBBox())
116  pixelPosList = (
117  posBox.getMin(),
118  afwGeom.Point2D(posBox.getMaxX(), posBox.getMinY()),
119  posBox.getMax(),
120  afwGeom.Point2D(posBox.getMinX(), posBox.getMaxY()),
121  )
122  skyPosList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees) for pos in pixelPosList]
123  posStrList = ["(%0.3f, %0.3f)" % tuple(skyPos) for skyPos in skyPosList]
124  self.log.info("tract %s has corners %s (RA, Dec deg) and %s x %s patches" % \
125  (tractInfo.getId(), ", ".join(posStrList), \
126  tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
127 
128  @classmethod
130  """Create an argument parser
131 
132  No identifiers are added because none are used.
133  """
134  return pipeBase.ArgumentParser(name=cls._DefaultName)
135 
136  def _getConfigName(self):
137  """Return the name of the config dataset
138  """
139  return "%s_makeSkyMap_config" % (self.config.coaddName,)
140 
141  def _getMetadataName(self):
142  """Return the name of the metadata dataset
143  """
144  return "%s_makeSkyMap_metadata" % (self.config.coaddName,)
145 
def run
Make a skymap, persist it (optionally) and log some information about it.
Definition: makeSkyMap.py:92
def logSkyMapInfo
Log information about a sky map.
Definition: makeSkyMap.py:107
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
Make a sky map in a repository.
Definition: makeSkyMap.py:78