30 nChildKeyName = Field(dtype=str, default=
"deblend_nChild",
31 doc=
"Name of field in schema with number of deblended children")
32 pseudoFilterList = ListField(dtype=str, default=[
'sky'],
33 doc=
"Names of filters which should never be primary")
37 """Add isPrimaryKey to a given schema.
41 schema : `lsst.afw.table.Schema`
43 isSingleFrame : `bool`
44 Flag specifying if task is operating with single frame imaging.
46 Keyword arguments passed to the task.
49 ConfigClass = SetPrimaryFlagsConfig
51 def __init__(self, schema, isSingleFrame=False, **kwargs):
52 Task.__init__(self, **kwargs)
56 primaryDoc = (
"true if source has no children and is in the inner region of a coadd patch "
57 "and is in the inner region of a coadd tract "
58 "and is not \"detected\" in a pseudo-filter (see config.pseudoFilterList)")
60 "detect_isPatchInner", type=
"Flag",
61 doc=
"true if source is in the inner region of a coadd patch",
64 "detect_isTractInner", type=
"Flag",
65 doc=
"true if source is in the inner region of a coadd tract",
68 primaryDoc =
"true if source has no children and is not a sky source"
70 "detect_isPrimary", type=
"Flag",
74 def run(self, sources, skyMap=None, tractInfo=None, patchInfo=None,
76 """Set is-patch-inner, is-tract-inner and is-primary flags on sources.
77 For coadded imaging, the is-primary flag returns True when an object
78 has no children, is in the inner region of a coadd patch, is in the
79 inner region of a coadd trach, and is not detected in a pseudo-filter
81 For single frame imaging, the is-primary flag returns True when a
82 source has no children and is not a sky source.
86 sources : `lsst.afw.table.SourceCatalog`
87 A sourceTable. Reads in centroid fields and an nChild field.
88 Writes is-patch-inner, is-tract-inner, and is-primary flags.
89 skyMap : `lsst.skymap.BaseSkyMap`
90 Sky tessellation object
91 tractInfo : `lsst.skymap.TractInfo`
93 patchInfo : `lsst.skymap.PatchInfo`
95 includeDeblend : `bool`
96 Include deblend information in isPrimary?
100 nChildKey = self.
schema.find(self.config.nChildKeyName).key
106 innerFloatBBox =
Box2D(patchInfo.getInnerBBox())
112 shrunkInnerFloatBBox =
Box2D(innerFloatBBox)
113 shrunkInnerFloatBBox.grow(-1)
115 pseudoFilterKeys = []
116 for filt
in self.config.pseudoFilterList:
118 pseudoFilterKeys.append(self.
schema.find(
"merge_peak_%s" % filt).getKey())
120 self.log.warn(
"merge_peak is not set for pseudo-filter %s" % filt)
122 tractId = tractInfo.getId()
123 for source
in sources:
124 centroidPos = source.getCentroid()
125 if numpy.any(numpy.isnan(centroidPos)):
127 if source.getCentroidFlag():
129 isPatchInner = shrunkInnerFloatBBox.contains(centroidPos)
131 isPatchInner = innerFloatBBox.contains(centroidPos)
134 skyPos = source.getCoord()
135 sourceInnerTractId = skyMap.findTract(skyPos).getId()
136 isTractInner = sourceInnerTractId == tractId
139 if nChildKey
is None or source.get(nChildKey) == 0:
140 for pseudoFilterKey
in pseudoFilterKeys:
141 if source.get(pseudoFilterKey):
147 source.setFlag(self.
isPrimaryKey, isPatchInner
and isTractInner
and not isPseudo)
151 hasSkySources =
True if "sky_source" in sources.schema
else False
152 for source
in sources:
153 hasNoChildren =
True if nChildKey
is None or source.get(nChildKey) == 0
else False
156 if source[
"sky_source"]:
158 source.setFlag(self.
isPrimaryKey, hasNoChildren
and not isSkySource)