24 Subtasks for creating the reference catalogs used in forced measurement.
31 __all__ = (
"BaseReferencesTask",
"CoaddSrcReferencesTask")
34 removePatchOverlaps = lsst.pex.config.Field(
35 doc =
"Only include reference sources for each patch that lie within the patch's inner bbox",
39 filter = lsst.pex.config.Field(
40 doc =
"Bandpass for reference sources; None indicates chi-squared detections.",
47 Base class for forced photometry subtask that retrieves reference sources.
49 BaseReferencesTask defines the required API for the references task, which includes:
51 - fetchInPatches(butler, tract, filter, patchList)
52 - fetchInBox(self, butler, tract, filter, bbox, wcs)
53 - the removePatchOverlaps config option
55 It also provides the subset() method, which may be of use to derived classes when
56 reimplementing fetchInBox.
59 ConfigClass = BaseReferencesConfig
63 Return the schema for the reference sources.
65 Must be available even before any data has been processed.
67 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
71 Return the WCS for reference sources. The given dataRef must include the tract in its dataId.
73 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
77 Return reference sources that overlap a region defined by a pixel-coordinate bounding box
78 and corresponding Wcs.
80 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key.
81 @param[in] bbox a afw.geom.Box2I or Box2D that defines the region in pixel coordinates
82 @param[in] wcs afw.image.Wcs that maps the bbox to sky coordinates
84 @return an iterable of reference sources
86 It is not required that the returned object be a SourceCatalog; it may be any Python iterable
87 containing SourceRecords (including a lazy iterator).
89 The returned set of sources should be complete and close to minimal.
91 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
95 Return reference sources that overlap a region defined by one or more SkyMap patches.
97 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key.
98 @param[in] patchList list of skymap.PatchInfo instances for which to fetch reference sources
100 @return an iterable of reference sources
102 It is not required that the returned object be a SourceCatalog; it may be any Python sequence
103 containing SourceRecords (including a lazy iterator).
105 The returned set of sources should be complete and close to minimal. If
106 config.removePatchOverlaps is True, only sources within each patch's "inner" bounding box
109 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
113 Filter sources to contain only those within the given box, defined in the coordinate system
114 defined by the given Wcs.
116 @param[in] sources input iterable of SourceRecords
117 @param[in] bbox bounding box with which to filter reference sources (Box2I or Box2D)
118 @param[in] wcs afw.image.Wcs that defines the coordinate system of bbox
120 @return an iterable of filtered reference sources
122 This is not a part of the required BaseReferencesTask interface; it's a convenience function
123 used in implementing fetchInBox that may be of use to subclasses.
126 for source
in sources:
127 pixel = wcs.skyToPixel(source.getCoord())
128 if boxD.contains(pixel):
132 coaddName = lsst.pex.config.Field(
133 doc =
"Coadd name: typically one of deep or goodSeeing.",
139 if (self.
coaddName ==
"chiSquared") != (self.filter
is None):
140 raise lsst.pex.config.FieldValidationError(
141 field=CoaddSrcReferencesConfig.coaddName,
143 msg=
"filter may be None if and only if coaddName is chiSquared"
148 A references task implementation that loads the coadd_src dataset directly from disk using
152 ConfigClass = CoaddSrcReferencesConfig
155 """Return the schema of the reference catalog"""
156 return butler.get(self.config.coaddName +
"Coadd_src_schema", immediate=
True).
getSchema()
159 """Return the WCS for reference sources. The given dataRef must include the tract in its dataId.
161 skyMap = dataRef.get(self.config.coaddName +
"Coadd_skyMap", immediate=
True)
162 return skyMap[dataRef.dataId[
"tract"]].
getWcs()
166 An implementation of BaseReferencesTask.fetchInPatches that loads 'coadd_src' catalogs
169 The given dataRef must include the tract in its dataId.
171 dataset = self.config.coaddName +
"Coadd_src"
172 tract = dataRef.dataId[
"tract"]
173 butler = dataRef.butlerSubset.butler
174 for patch
in patchList:
175 dataId = {
'tract': tract,
'patch':
"%d,%d" % patch.getIndex()}
176 if self.config.filter
is not None:
177 dataId[
'filter'] = self.config.filter
179 if not butler.datasetExists(dataset, dataId):
180 raise lsst.pipe.base.TaskError(
"Reference %s doesn't exist" % (dataId,))
181 self.log.info(
"Getting references in %s" % (dataId,))
182 catalog = butler.get(dataset, dataId, immediate=
True)
183 if self.config.removePatchOverlaps:
185 for source
in catalog:
186 if bbox.contains(source.getCentroid()):
189 for source
in catalog:
194 Return reference sources that overlap a region defined by a pixel-coordinate bounding box
195 and corresponding Wcs.
197 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key.
198 @param[in] bbox a afw.geom.Box2I or Box2D that defines the region in pixel coordinates
199 @param[in] wcs afw.image.Wcs that maps the bbox to sky coordinates
200 @param[in] pad a buffer to grow the bounding box by after catalogs have been loaded, but
201 before filtering them to include just the given bounding box.
203 @return an iterable of reference sources
205 skyMap = dataRef.get(self.config.coaddName +
"Coadd_skyMap", immediate=
True)
206 tract = skyMap[dataRef.dataId[
"tract"]]
208 self.log.info(
"Getting references in region with corners %s [degrees]" %
209 ", ".join(
"(%s)" % coord.getPosition(lsst.afw.geom.degrees)
for coord
in coordList))
210 patchList = tract.findPatchList(coordList)
def getSchema
Return the schema for the reference sources.
def getWcs
Return the WCS for reference sources.
Base class for forced photometry subtask that retrieves reference sources.
A references task implementation that loads the coadd_src dataset directly from disk using the butler...
def subset
Filter sources to contain only those within the given box, defined in the coordinate system defined b...
def fetchInBox
Return reference sources that overlap a region defined by a pixel-coordinate bounding box and corresp...
def fetchInBox
Return reference sources that overlap a region defined by a pixel-coordinate bounding box and corresp...
def fetchInPatches
Return reference sources that overlap a region defined by one or more SkyMap patches.
A floating-point coordinate rectangle geometry.
def fetchInPatches
An implementation of BaseReferencesTask.fetchInPatches that loads 'coadd_src' catalogs using the butl...