23 from __future__
import absolute_import, division, print_function
25 __all__ = [
"BaseSourceSelectorConfig",
"BaseSourceSelectorTask",
"sourceSelectorRegistry"]
29 import lsst.afw.table
as afwTable
30 import lsst.pex.config
as pexConfig
31 import lsst.pipe.base
as pipeBase
32 from future.utils
import with_metaclass
36 badFlags = pexConfig.ListField(
37 doc=
"List of flags which cause a source to be rejected as bad",
40 "base_PixelFlags_flag_edge",
41 "base_PixelFlags_flag_interpolatedCenter",
42 "base_PixelFlags_flag_saturatedCenter",
43 "base_PixelFlags_flag_crCenter",
44 "base_PixelFlags_flag_bad",
45 "base_PixelFlags_flag_interpolated",
51 """!Base class for source selectors
53 Register all source selectors with the sourceSelectorRegistry using:
54 sourceSelectorRegistry.register(name, class)
57 ConfigClass = BaseSourceSelectorConfig
58 _DefaultName =
"sourceSelector"
61 """!Initialize a source selector."""
62 pipeBase.Task.__init__(self, **kwargs)
64 def run(self, sourceCat, maskedImage=None, **kwargs):
65 """!Select sources and return them.
67 @param[in] sourceCat catalog of sources that may be sources (an lsst.afw.table.SourceCatalog)
68 @param[in] maskedImage the maskedImage containing the sources, for plotting.
70 @return an lsst.pipe.base.Struct containing:
71 - sourceCat catalog of sources that were selected
73 return self.
selectSources(maskedImage=maskedImage, sourceCat=sourceCat, **kwargs)
77 """!Return a catalog of sources: a subset of sourceCat.
79 @param[in] sourceCat catalog of sources that may be sources (an lsst.afw.table.SourceCatalog)
81 @return a pipeBase.Struct containing:
82 - sourceCat a catalog of sources
86 result = afwTable.SourceCatalog(sourceCat.table)
87 for source
in sourceCat:
88 if not self.
_isBad(source):
90 return pipeBase.Struct(sourceCat=result)
92 def _isBad(self, source):
93 """Return True if any of config.badFlags are set for this source."""
94 return any(source.get(flag)
for flag
in self.config.badFlags)
97 sourceSelectorRegistry = pexConfig.makeRegistry(
98 doc=
"A registry of source selectors (subclasses of BaseSourceSelectorTask)",
def __init__
Initialize a source selector.
def selectSources
Return a catalog of sources: a subset of sourceCat.
def run
Select sources and return them.
Base class for source selectors.