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
61 def __init__(self, butler=None, schema=None, **kwargs):
62 """!Initialize the task.
64 BaseReferencesTask and its subclasses take two keyword arguments beyond the usual Task arguments:
65 - schema: the Schema of the reference catalog
66 - butler: a butler that will allow the task to load its Schema from disk.
67 At least one of these arguments must be present; if both are, schema takes precedence.
69 lsst.pipe.base.Task.__init__(self, **kwargs)
73 Return the schema for the reference sources.
75 Must be available even before any data has been processed.
77 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
81 Return the WCS for reference sources. The given dataRef must include the tract in its dataId.
83 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
87 Return reference sources that overlap a region defined by a pixel-coordinate bounding box
88 and corresponding Wcs.
90 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key.
91 @param[in] bbox a afw.geom.Box2I or Box2D that defines the region in pixel coordinates
92 @param[in] wcs afw.image.Wcs that maps the bbox to sky coordinates
94 @return an iterable of reference sources
96 It is not required that the returned object be a SourceCatalog; it may be any Python iterable
97 containing SourceRecords (including a lazy iterator).
99 The returned set of sources should be complete and close to minimal.
101 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
105 Return reference sources that overlap a region defined by one or more SkyMap patches.
107 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key.
108 @param[in] patchList list of skymap.PatchInfo instances for which to fetch reference sources
110 @return an iterable of reference sources
112 It is not required that the returned object be a SourceCatalog; it may be any Python sequence
113 containing SourceRecords (including a lazy iterator).
115 The returned set of sources should be complete and close to minimal. If
116 config.removePatchOverlaps is True, only sources within each patch's "inner" bounding box
119 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
123 Filter sources to contain only those within the given box, defined in the coordinate system
124 defined by the given Wcs.
126 @param[in] sources input iterable of SourceRecords
127 @param[in] bbox bounding box with which to filter reference sources (Box2I or Box2D)
128 @param[in] wcs afw.image.Wcs that defines the coordinate system of bbox
130 Instead of filtering sources directly via their positions, we filter based on the positions
131 of parent objects, then include or discard all children based on their parent's status. This
132 is necessary to support ReplaceWithNoise in measurement, which requires all child sources have
133 their parent present.
135 @return an iterable of filtered reference sources
137 This is not a part of the required BaseReferencesTask interface; it's a convenience function
138 used in implementing fetchInBox that may be of use to subclasses.
144 catalog.extend(sources)
146 for parent
in catalog.getChildren(0):
147 pixel = wcs.skyToPixel(parent.getCoord())
148 if boxD.contains(pixel):
150 for child
in catalog.getChildren(parent.getId()):
155 coaddName = lsst.pex.config.Field(
156 doc =
"Coadd name: typically one of deep or goodSeeing.",
162 if (self.
coaddName ==
"chiSquared") != (self.filter
is None):
163 raise lsst.pex.config.FieldValidationError(
164 field=CoaddSrcReferencesConfig.coaddName,
166 msg=
"filter may be None if and only if coaddName is chiSquared"
171 A references task implementation that loads the coadd_datasetSuffix dataset directly from
172 disk using the butler.
175 ConfigClass = CoaddSrcReferencesConfig
176 datasetSuffix =
"src"
178 def __init__(self, butler=None, schema=None, **kwargs):
179 """! Initialize the task.
180 Additional keyword arguments (forwarded to BaseReferencesTask.__init__):
181 - schema: the schema of the detection catalogs used as input to this one
182 - butler: a butler used to read the input schema from disk, if schema is None
183 The task will set its own self.schema attribute to the schema of the output merged catalog.
185 BaseReferencesTask.__init__(self, butler=butler, schema=schema, **kwargs)
187 assert butler
is not None,
"No butler nor schema provided"
193 """Return the WCS for reference sources. The given dataRef must include the tract in its dataId.
195 skyMap = dataRef.get(self.config.coaddName +
"Coadd_skyMap", immediate=
True)
196 return skyMap[dataRef.dataId[
"tract"]].
getWcs()
200 An implementation of BaseReferencesTask.fetchInPatches that loads 'coadd_' + datasetSuffix
201 catalogs using the butler.
203 The given dataRef must include the tract in its dataId.
206 tract = dataRef.dataId[
"tract"]
207 butler = dataRef.butlerSubset.butler
208 for patch
in patchList:
209 dataId = {
'tract': tract,
'patch':
"%d,%d" % patch.getIndex()}
210 if self.config.filter
is not None:
211 dataId[
'filter'] = self.config.filter
213 if not butler.datasetExists(dataset, dataId):
214 raise lsst.pipe.base.TaskError(
"Reference %s doesn't exist" % (dataId,))
215 self.log.info(
"Getting references in %s" % (dataId,))
216 catalog = butler.get(dataset, dataId, immediate=
True)
217 if self.config.removePatchOverlaps:
219 for source
in catalog:
220 if bbox.contains(source.getCentroid()):
223 for source
in catalog:
228 Return reference sources that overlap a region defined by a pixel-coordinate bounding box
229 and corresponding Wcs.
231 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key.
232 @param[in] bbox a afw.geom.Box2I or Box2D that defines the region in pixel coordinates
233 @param[in] wcs afw.image.Wcs that maps the bbox to sky coordinates
234 @param[in] pad a buffer to grow the bounding box by after catalogs have been loaded, but
235 before filtering them to include just the given bounding box.
237 @return an iterable of reference sources
239 skyMap = dataRef.get(self.config.coaddName +
"Coadd_skyMap", immediate=
True)
240 tract = skyMap[dataRef.dataId[
"tract"]]
242 self.log.info(
"Getting references in region with corners %s [degrees]" %
243 ", ".join(
"(%s)" % coord.getPosition(lsst.afw.geom.degrees)
for coord
in coordList))
244 patchList = tract.findPatchList(coordList)
255 if self.filter
is not None:
256 raise lsst.pex.config.FieldValidationError(field=MultiBandReferencesConfig.filter, config=self,
257 msg=
"Filter should not be set for the multiband processing scheme")
259 BaseReferencesTask.ConfigClass.validate(self)
263 """Loads references from the multiband processing scheme"""
264 ConfigClass = MultiBandReferencesConfig
265 datasetSuffix =
"ref"
def getSchema
Return the schema for the reference sources.
def __init__
Initialize the task.
def __init__
Initialize the task.
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_datasetSuffix dataset directly from disk using ...
def subset
Filter sources to contain only those within the given box, defined in the coordinate system defined b...
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
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_' + datasetSuffix catalogs u...