24 from __future__
import absolute_import, division, print_function
26 from lsst.pex.config
import Config, Field, ListField
27 from lsst.pipe.base
import Task
28 from lsst.afw.geom
import Box2D
32 nChildKeyName = Field(dtype=str, default=
"deblend_nChild",
33 doc=
"Name of field in schema with number of deblended children")
34 pseudoFilterList = ListField(dtype=str, default=[
'sky'],
35 doc=
"Names of filters which should never be primary")
39 ConfigClass = SetPrimaryFlagsConfig
42 Task.__init__(self, **kwargs)
45 "detect_isPatchInner", type=
"Flag",
46 doc=
"true if source is in the inner region of a coadd patch",
49 "detect_isTractInner", type=
"Flag",
50 doc=
"true if source is in the inner region of a coadd tract",
53 "detect_isPrimary", type=
"Flag",
54 doc=
"true if source has no children and is in the inner region of a coadd patch " 55 +
"and is in the inner region of a coadd tract " 56 "and is not \"detected\" in a pseudo-filter (see config.pseudoFilterList)",
59 def run(self, sources, skyMap, tractInfo, patchInfo, includeDeblend=True):
60 """Set is-primary and related flags on sources 62 @param[in,out] sources a SourceTable 63 - reads centroid fields and an nChild field 64 - writes is-patch-inner, is-tract-inner and is-primary flags 65 @param[in] skyMap sky tessellation object (subclass of lsst.skymap.BaseSkyMap) 66 @param[in] tractInfo tract object (subclass of lsst.skymap.TractInfo) 67 @param[in] patchInfo patch object (subclass of lsst.skymap.PatchInfo) 68 @param[in] includeDeblend include deblend information in isPrimary? 72 nChildKey = self.
schema.find(self.config.nChildKeyName).key
76 innerFloatBBox = Box2D(patchInfo.getInnerBBox())
82 shrunkInnerFloatBBox = Box2D(innerFloatBBox)
83 shrunkInnerFloatBBox.grow(-1)
86 for filt
in self.config.pseudoFilterList:
88 pseudoFilterKeys.append(self.
schema.find(
"merge_peak_%s" % filt).getKey())
90 self.log.warn(
"merge_peak is not set for pseudo-filter %s" % filt)
92 tractId = tractInfo.getId()
93 for source
in sources:
94 centroidPos = source.getCentroid()
95 if numpy.any(numpy.isnan(centroidPos)):
97 if source.getCentroidFlag():
99 isPatchInner = shrunkInnerFloatBBox.contains(centroidPos)
101 isPatchInner = innerFloatBBox.contains(centroidPos)
104 skyPos = source.getCoord()
105 sourceInnerTractId = skyMap.findTract(skyPos).getId()
106 isTractInner = sourceInnerTractId == tractId
109 if nChildKey
is None or source.get(nChildKey) == 0:
110 for pseudoFilterKey
in pseudoFilterKeys:
111 if source.get(pseudoFilterKey):
117 source.setFlag(self.
isPrimaryKey, isPatchInner
and isTractInner
and not isPseudo)
def __init__(self, schema, kwargs)
def run(self, sources, skyMap, tractInfo, patchInfo, includeDeblend=True)