24 Subtasks for creating the reference catalogs used in forced measurement. 31 __all__ = (
"BaseReferencesTask",
"CoaddSrcReferencesTask")
35 removePatchOverlaps = lsst.pex.config.Field(
36 doc=
"Only include reference sources for each patch that lie within the patch's inner bbox",
40 filter = lsst.pex.config.Field(
41 doc=
"Bandpass for reference sources; None indicates chi-squared detections.",
49 Base class for forced photometry subtask that retrieves reference sources. 51 BaseReferencesTask defines the required API for the references task, which includes: 53 - fetchInPatches(butler, tract, filter, patchList) 54 - fetchInBox(self, butler, tract, filter, bbox, wcs) 55 - the removePatchOverlaps config option 57 It also provides the subset() method, which may be of use to derived classes when 58 reimplementing fetchInBox. 61 ConfigClass = BaseReferencesConfig
63 def __init__(self, butler=None, schema=None, **kwargs):
64 """!Initialize the task. 66 BaseReferencesTask and its subclasses take two keyword arguments beyond the usual Task arguments: 67 - schema: the Schema of the reference catalog 68 - butler: a butler that will allow the task to load its Schema from disk. 69 At least one of these arguments must be present; if both are, schema takes precedence. 71 lsst.pipe.base.Task.__init__(self, **kwargs)
75 Return the schema for the reference sources. 77 Must be available even before any data has been processed. 79 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
83 Return the WCS for reference sources. The given dataRef must include the tract in its dataId. 85 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
89 Return reference sources that overlap a region defined by a pixel-coordinate bounding box 90 and corresponding Wcs. 92 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key. 93 @param[in] bbox a geom.Box2I or Box2D that defines the region in pixel coordinates 94 @param[in] wcs afw.image.Wcs that maps the bbox to sky coordinates 96 @return an iterable of reference sources 98 It is not required that the returned object be a SourceCatalog; it may be any Python iterable 99 containing SourceRecords (including a lazy iterator). 101 The returned set of sources should be complete and close to minimal. 103 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
107 Return reference sources that overlap a region defined by one or more SkyMap patches. 109 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key. 110 @param[in] patchList list of skymap.PatchInfo instances for which to fetch reference sources 112 @return an iterable of reference sources 114 It is not required that the returned object be a SourceCatalog; it may be any Python sequence 115 containing SourceRecords (including a lazy iterator). 117 The returned set of sources should be complete and close to minimal. If 118 config.removePatchOverlaps is True, only sources within each patch's "inner" bounding box 121 raise NotImplementedError(
"BaseReferencesTask is pure abstract, and cannot be used directly.")
125 Filter sources to contain only those within the given box, defined in the coordinate system 126 defined by the given Wcs. 128 @param[in] sources input iterable of SourceRecords 129 @param[in] bbox bounding box with which to filter reference sources (Box2I or Box2D) 130 @param[in] wcs afw.image.Wcs that defines the coordinate system of bbox 132 Instead of filtering sources directly via their positions, we filter based on the positions 133 of parent objects, then include or discard all children based on their parent's status. This 134 is necessary to support ReplaceWithNoise in measurement, which requires all child sources have 135 their parent present. 137 @return an iterable of filtered reference sources 139 This is not a part of the required BaseReferencesTask interface; it's a convenience function 140 used in implementing fetchInBox that may be of use to subclasses. 146 catalog.extend(sources)
150 parentSources = catalog.getChildren(0)
151 skyCoordList = [source.getCoord()
for source
in parentSources]
152 pixelPosList = wcs.skyToPixel(skyCoordList)
153 for parent, pixel
in zip(parentSources, pixelPosList):
154 if boxD.contains(pixel):
156 for child
in catalog.getChildren(parent.getId()):
161 coaddName = lsst.pex.config.Field(
162 doc=
"Coadd name: typically one of deep or goodSeeing.",
166 skipMissing = lsst.pex.config.Field(
167 doc=
"Silently skip patches where the reference catalog does not exist.",
173 if (self.
coaddName ==
"chiSquared") != (self.filter
is None):
174 raise lsst.pex.config.FieldValidationError(
175 field=CoaddSrcReferencesConfig.coaddName,
177 msg=
"filter may be None if and only if coaddName is chiSquared" 183 A references task implementation that loads the coadd_datasetSuffix dataset directly from 184 disk using the butler. 187 ConfigClass = CoaddSrcReferencesConfig
188 datasetSuffix =
"src" 190 def __init__(self, butler=None, schema=None, **kwargs):
191 """! Initialize the task. 192 Additional keyword arguments (forwarded to BaseReferencesTask.__init__): 193 - schema: the schema of the detection catalogs used as input to this one 194 - butler: a butler used to read the input schema from disk, if schema is None 195 The task will set its own self.schema attribute to the schema of the output merged catalog. 197 BaseReferencesTask.__init__(self, butler=butler, schema=schema, **kwargs)
199 assert butler
is not None,
"No butler nor schema provided" 200 schema = butler.get(
"{}Coadd_{}_schema".format(self.config.coaddName, self.
datasetSuffix),
205 """Return the WCS for reference sources. The given dataRef must include the tract in its dataId. 207 skyMap = dataRef.get(self.config.coaddName +
"Coadd_skyMap", immediate=
True)
208 return skyMap[dataRef.dataId[
"tract"]].
getWcs()
212 An implementation of BaseReferencesTask.fetchInPatches that loads 'coadd_' + datasetSuffix 213 catalogs using the butler. 215 The given dataRef must include the tract in its dataId. 217 dataset =
"{}Coadd_{}".format(self.config.coaddName, self.
datasetSuffix)
218 tract = dataRef.dataId[
"tract"]
219 butler = dataRef.butlerSubset.butler
220 for patch
in patchList:
221 dataId = {
'tract': tract,
'patch':
"%d,%d" % patch.getIndex()}
222 if self.config.filter
is not None:
223 dataId[
'filter'] = self.config.filter
225 if not butler.datasetExists(dataset, dataId):
226 if self.config.skipMissing:
228 raise lsst.pipe.base.TaskError(
"Reference %s doesn't exist" % (dataId,))
229 self.log.info(
"Getting references in %s" % (dataId,))
230 catalog = butler.get(dataset, dataId, immediate=
True)
231 if self.config.removePatchOverlaps:
233 for source
in catalog:
234 if bbox.contains(source.getCentroid()):
237 for source
in catalog:
242 Return reference sources that overlap a region defined by a pixel-coordinate bounding box 243 and corresponding Wcs. 245 @param[in] dataRef ButlerDataRef; the implied data ID must contain the 'tract' key. 246 @param[in] bbox a geom.Box2I or Box2D that defines the region in pixel coordinates 247 @param[in] wcs afw.image.Wcs that maps the bbox to sky coordinates 248 @param[in] pad a buffer to grow the bounding box by after catalogs have been loaded, but 249 before filtering them to include just the given bounding box. 251 @return an iterable of reference sources 253 skyMap = dataRef.get(self.config.coaddName +
"Coadd_skyMap", immediate=
True)
254 tract = skyMap[dataRef.dataId[
"tract"]]
255 coordList = [wcs.pixelToSky(corner)
for corner
in lsst.geom.Box2D(bbox).getCorners()]
256 self.log.info(
"Getting references in region with corners %s [degrees]" %
257 ", ".join(
"(%s)" % (coord.getPosition(lsst.geom.degrees),)
for coord
in coordList))
258 patchList = tract.findPatchList(coordList)
269 if self.filter
is not None:
270 raise lsst.pex.config.FieldValidationError(
271 field=MultiBandReferencesConfig.filter,
273 msg=
"Filter should not be set for the multiband processing scheme")
275 BaseReferencesTask.ConfigClass.validate(self)
279 """Loads references from the multiband processing scheme""" 280 ConfigClass = MultiBandReferencesConfig
281 datasetSuffix =
"ref"
def fetchInBox(self, dataRef, bbox, wcs, pad=0)
Return reference sources that overlap a region defined by a pixel-coordinate bounding box and corresp...
def getSchema(self, butler)
Return the schema for the reference sources.
def getWcs(self, dataRef)
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 fetchInBox(self, dataRef, bbox, wcs)
Return reference sources that overlap a region defined by a pixel-coordinate bounding box and corresp...
def fetchInPatches(self, dataRef, patchList)
An implementation of BaseReferencesTask.fetchInPatches that loads 'coadd_' + datasetSuffix catalogs u...
def __init__(self, butler=None, schema=None, kwargs)
Initialize the task.
def __init__(self, butler=None, schema=None, kwargs)
Initialize the task.
static Key< RecordId > getParentKey()
def getWcs(self, dataRef)
def fetchInPatches(self, dataRef, patchList)
Return reference sources that overlap a region defined by one or more SkyMap patches.
def subset(self, sources, bbox, wcs)
Filter sources to contain only those within the given box, defined in the coordinate system defined b...