34 """Config for MakeDiscreteSkyMapTask
36 coaddName = pexConfig.Field(
37 doc =
"coadd name, e.g. deep, goodSeeing, chiSquared",
41 skyMap = pexConfig.ConfigField(
42 dtype = BaseSkyMap.ConfigClass,
43 doc =
"SkyMap configuration parameters, excluding position and radius"
45 borderSize = pexConfig.Field(
46 doc =
"additional border added to the bounding box of the calexps, in degrees",
50 doAppend = pexConfig.Field(
51 doc =
"append another tract to an existing DiscreteSkyMap on disk, if present?",
55 doWrite = pexConfig.Field(
56 doc =
"persist the skyMap?",
62 self.skyMap.tractOverlap = 0.0
65 """Run a task with all dataRefs at once, rather than one dataRef at a time.
67 Call the run method of the task using two positional arguments:
69 - dataRefList: list of all dataRefs,
73 return [(parsedCmd.butler, parsedCmd.id.refList)]
77 @param args Arguments for Task.run()
80 - None if self.doReturnResults false
81 - A pipe_base Struct containing these fields if self.doReturnResults true:
82 - dataRef: the provided data reference
83 - metadata: task metadata after execution of run
84 - result: result returned by task run, or None if the task fails
86 butler, dataRefList = args
87 task = self.TaskClass(config=self.config, log=self.log)
90 result = task.run(butler, dataRefList)
93 result = task.run(butler, dataRefList)
95 task.log.fatal(
"Failed: %s" % e)
96 if not isinstance(e, pipeBase.TaskError):
97 traceback.print_exc(file=sys.stderr)
98 for dataRef
in dataRefList:
99 task.writeMetadata(dataRef)
101 if self.doReturnResults:
102 return pipeBase.Struct(
103 dataRefList = dataRefList,
104 metadata = task.metadata,
109 """!Make a DiscreteSkyMap in a repository, using the bounding box of a set of calexps.
111 The command-line and run signatures and config are sufficiently different from MakeSkyMapTask
112 that we don't inherit from it, but it is a replacement, so we use the same config/metadata names.
114 ConfigClass = MakeDiscreteSkyMapConfig
115 _DefaultName =
"makeDiscreteSkyMap"
116 RunnerClass = MakeDiscreteSkyMapRunner
119 pipeBase.CmdLineTask.__init__(self, **kwargs)
122 def run(self, butler, dataRefList):
123 """!Make a skymap from the bounds of the given set of calexps.
125 @param[in] butler data butler used to save the SkyMap
126 @param[in] dataRefList dataRefs of calexps used to determine the size and pointing of the SkyMap
127 @return a pipeBase Struct containing:
128 - skyMap: the constructed SkyMap
130 self.log.info(
"Extracting bounding boxes of %d images" % len(dataRefList))
132 for dataRef
in dataRefList:
133 if not dataRef.datasetExists(
"calexp"):
134 self.log.warn(
"CalExp for %s does not exist: ignoring" % (dataRef.dataId,))
136 md = dataRef.get(
"calexp_md", immediate=
True)
141 points.extend(tuple(wcs.pixelToSky(corner).getVector())
for corner
in boxD.getCorners())
143 raise RuntimeError(
"No data found from which to compute convex hull")
144 self.log.info(
"Computing spherical convex hull")
145 polygon = lsst.geom.convexHull(points)
148 "Failed to compute convex hull of the vertices of all calexp bounding boxes; "
149 "they may not be hemispherical."
151 circle = polygon.getBoundingCircle()
153 datasetName = self.config.coaddName +
"Coadd_skyMap"
155 skyMapConfig = DiscreteSkyMap.ConfigClass()
156 if self.config.doAppend
and butler.datasetExists(datasetName):
157 oldSkyMap = butler.get(datasetName, immediate=
True)
158 if not isinstance(oldSkyMap.config, DiscreteSkyMap.ConfigClass):
159 raise TypeError(
"Cannot append to existing non-discrete skymap")
161 if not self.config.skyMap.compare(oldSkyMap.config, output=compareLog.append):
162 raise ValueError(
"Cannot append to existing skymap - configurations differ:", *compareLog)
163 skyMapConfig.raList.extend(oldSkyMap.config.raList)
164 skyMapConfig.decList.extend(oldSkyMap.config.decList)
165 skyMapConfig.radiusList.extend(oldSkyMap.config.radiusList)
166 skyMapConfig.update(**self.config.skyMap.toDict())
167 skyMapConfig.raList.append(circle.center[0])
168 skyMapConfig.decList.append(circle.center[1])
169 skyMapConfig.radiusList.append(circle.radius + self.config.borderSize)
170 skyMap = DiscreteSkyMap(skyMapConfig)
172 for tractInfo
in skyMap:
173 wcs = tractInfo.getWcs()
181 skyPosList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees)
for pos
in pixelPosList]
182 posStrList = [
"(%0.3f, %0.3f)" % tuple(skyPos)
for skyPos
in skyPosList]
183 self.log.info(
"tract %s has corners %s (RA, Dec deg) and %s x %s patches" % \
184 (tractInfo.getId(),
", ".join(posStrList), \
185 tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
186 if self.config.doWrite:
187 butler.put(skyMap, datasetName)
188 return pipeBase.Struct(
193 """Return None to disable saving config
195 There's only one SkyMap per repository, so the config is redundant, and checking it means we can't
196 easily overwrite or append to an existing repository.
201 """Return None to disable saving metadata
203 The metadata is not interesting, and by not saving it we can eliminate a dataset type.
An integer coordinate rectangle.
Wcs::Ptr makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
Create a Wcs object from crval, crpix, CD, using CD elements (useful from python) ...
def run
Make a skymap from the bounds of the given set of calexps.
A floating-point coordinate rectangle geometry.
Make a DiscreteSkyMap in a repository, using the bounding box of a set of calexps.