35 """Config for MakeDiscreteSkyMapTask 37 coaddName = pexConfig.Field(
38 doc=
"coadd name, e.g. deep, goodSeeing, chiSquared",
42 skyMap = pexConfig.ConfigField(
43 dtype=BaseSkyMap.ConfigClass,
44 doc=
"SkyMap configuration parameters, excluding position and radius" 46 borderSize = pexConfig.Field(
47 doc=
"additional border added to the bounding box of the calexps, in degrees",
51 doAppend = pexConfig.Field(
52 doc=
"append another tract to an existing DiscreteSkyMap on disk, if present?",
56 doWrite = pexConfig.Field(
57 doc=
"persist the skyMap?",
63 self.
skyMap.tractOverlap = 0.0
67 """Run a task with all dataRefs at once, rather than one dataRef at a time. 69 Call the run method of the task using two positional arguments: 71 - dataRefList: list of all dataRefs, 75 return [(parsedCmd.butler, parsedCmd.id.refList)]
79 @param args Arguments for Task.run() 82 - None if self.doReturnResults false 83 - A pipe_base Struct containing these fields if self.doReturnResults true: 84 - dataRef: the provided data reference 85 - metadata: task metadata after execution of run 86 - result: result returned by task run, or None if the task fails 88 butler, dataRefList = args
89 task = self.TaskClass(config=self.config, log=self.log)
93 result = task.runDataRef(butler, dataRefList)
96 result = task.runDataRef(butler, dataRefList)
97 except Exception
as e:
98 task.log.fatal(
"Failed: %s" % e)
100 if not isinstance(e, pipeBase.TaskError):
101 traceback.print_exc(file=sys.stderr)
102 for dataRef
in dataRefList:
103 task.writeMetadata(dataRef)
105 if self.doReturnResults:
106 return pipeBase.Struct(
107 dataRefList=dataRefList,
108 metadata=task.metadata,
110 exitStatus=exitStatus,
113 return pipeBase.Struct(
114 exitStatus=exitStatus,
119 """!Make a DiscreteSkyMap in a repository, using the bounding box of a set of calexps. 121 The command-line and run signatures and config are sufficiently different from MakeSkyMapTask 122 that we don't inherit from it, but it is a replacement, so we use the same config/metadata names. 124 ConfigClass = MakeDiscreteSkyMapConfig
125 _DefaultName =
"makeDiscreteSkyMap" 126 RunnerClass = MakeDiscreteSkyMapRunner
129 pipeBase.CmdLineTask.__init__(self, **kwargs)
133 """!Make a skymap from the bounds of the given set of calexps. 135 @param[in] butler data butler used to save the SkyMap 136 @param[in] dataRefList dataRefs of calexps used to determine the size and pointing of the SkyMap 137 @return a pipeBase Struct containing: 138 - skyMap: the constructed SkyMap 140 self.log.
info(
"Extracting bounding boxes of %d images" % len(dataRefList))
142 for dataRef
in dataRefList:
143 if not dataRef.datasetExists(
"calexp"):
144 self.log.
warn(
"CalExp for %s does not exist: ignoring" % (dataRef.dataId,))
146 md = dataRef.get(
"calexp_md", immediate=
True)
151 points.extend(wcs.pixelToSky(corner).getVector()
for corner
in boxD.getCorners())
153 raise RuntimeError(
"No data found from which to compute convex hull")
154 self.log.
info(
"Computing spherical convex hull")
158 "Failed to compute convex hull of the vertices of all calexp bounding boxes; " 159 "they may not be hemispherical." 161 circle = polygon.getBoundingCircle()
163 datasetName = self.config.coaddName +
"Coadd_skyMap" 165 skyMapConfig = DiscreteSkyMap.ConfigClass()
166 if self.config.doAppend
and butler.datasetExists(datasetName):
167 oldSkyMap = butler.get(datasetName, immediate=
True)
168 if not isinstance(oldSkyMap.config, DiscreteSkyMap.ConfigClass):
169 raise TypeError(
"Cannot append to existing non-discrete skymap")
171 if not self.config.skyMap.compare(oldSkyMap.config, output=compareLog.append):
172 raise ValueError(
"Cannot append to existing skymap - configurations differ:", *compareLog)
173 skyMapConfig.raList.extend(oldSkyMap.config.raList)
174 skyMapConfig.decList.extend(oldSkyMap.config.decList)
175 skyMapConfig.radiusList.extend(oldSkyMap.config.radiusList)
176 skyMapConfig.update(**self.config.skyMap.toDict())
178 skyMapConfig.raList.append(circleCenter[0].asDegrees())
179 skyMapConfig.decList.append(circleCenter[1].asDegrees())
180 circleRadiusDeg = circle.getOpeningAngle().asDegrees()
181 skyMapConfig.radiusList.append(circleRadiusDeg + self.config.borderSize)
184 for tractInfo
in skyMap:
185 wcs = tractInfo.getWcs()
193 skyPosList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees)
for pos
in pixelPosList]
194 posStrList = [
"(%0.3f, %0.3f)" % tuple(skyPos)
for skyPos
in skyPosList]
195 self.log.
info(
"tract %s has corners %s (RA, Dec deg) and %s x %s patches" %
196 (tractInfo.getId(),
", ".join(posStrList),
197 tractInfo.getNumPatches()[0], tractInfo.getNumPatches()[1]))
198 if self.config.doWrite:
199 butler.put(skyMap, datasetName)
200 return pipeBase.Struct(
204 def _getConfigName(self):
205 """Return None to disable saving config 207 There's only one SkyMap per repository, so the config is redundant, and checking it means we can't 208 easily overwrite or append to an existing repository. 212 def _getMetadataName(self):
213 """Return None to disable saving metadata 215 The metadata is not interesting, and by not saving it we can eliminate a dataset type. 220 def _makeArgumentParser(cls):
222 parser.add_id_argument(name=
"--id", datasetType=
"calexp", help=
"data ID, e.g. --id visit=123 ccd=1,2")
def __init__(self, kwargs)
A floating-point coordinate rectangle geometry.
def runDataRef(self, butler, dataRefList)
Make a skymap from the bounds of the given set of calexps.
def getTargetList(parsedCmd)
static ConvexPolygon convexHull(std::vector< UnitVector3d > const &points)
convexHull returns the convex hull of the given set of points if it exists and throws an exception ot...
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
std::shared_ptr< SkyWcs > makeSkyWcs(TransformPoint2ToPoint2 const &pixelsToFieldAngle, lsst::geom::Angle const &orientation, bool flipX, lsst::geom::SpherePoint const &boresight, std::string const &projection="TAN")
Construct a FITS SkyWcs from camera geometry.
lsst::geom::Box2I bboxFromMetadata(daf::base::PropertySet &metadata)
Determine the image bounding box from its metadata (FITS header)
Make a DiscreteSkyMap in a repository, using the bounding box of a set of calexps.