27 from .sourceSelector
import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
32 sourceFluxType = pexConfig.Field(
33 doc=
"Type of source flux; typically one of Ap or Psf",
37 minSnr = pexConfig.Field(
39 doc=
"Minimum allowed signal-to-noise ratio for sources used for matching "
40 "(in the flux specified by sourceFluxType); <= 0 for no limit",
43 excludePixelFlags = pexConfig.Field(
45 doc=
"Exclude objects that have saturated, interpolated, or edge "
46 "pixels using PixelFlags. For matchOptimisticB set this to False "
47 "to recover previous matcher selector behavior.",
52 @pexConfig.registerConfigurable("matcher", sourceSelectorRegistry)
54 """Select sources that are useful for matching.
56 Good matching sources have high signal/noise, are non-blended. They need not
57 be PSF sources, just have reliable centroids.
59 Distinguished from astrometrySourceSelector because it is more lenient
60 (i.e. not checking footprints or bad flags).
62 ConfigClass = MatcherSourceSelectorConfig
65 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
68 """Return a selection of sources that are useful for matching.
72 sourceCat : `lsst.afw.table.SourceCatalog`
73 Catalog of sources to select from.
74 This catalog must be contiguous in memory.
75 matches : `list` of `lsst.afw.table.ReferenceMatch` or None
76 Ignored in this SourceSelector.
77 exposure : `lsst.afw.image.Exposure` or None
78 The exposure the catalog was built from; used for debug display.
82 struct : `lsst.pipe.base.Struct`
83 The struct contains the following data:
85 - selected : `array` of `bool``
86 Boolean array of sources that were selected, same length as
92 if self.config.excludePixelFlags:
93 good = good & self.
_isGood_isGood(sourceCat)
94 return Struct(selected=good)
96 def _getSchemaKeys(self, schema):
97 """Extract and save the necessary keys from schema with asKey.
104 fluxPrefix =
"slot_%sFlux_" % (self.config.sourceFluxType,)
106 self.
fluxKeyfluxKey = schema[fluxPrefix +
"instFlux"].asKey()
108 self.
fluxErrKeyfluxErrKey = schema[fluxPrefix +
"instFluxErr"].asKey()
110 self.
edgeKeyedgeKey = schema[
"base_PixelFlags_flag_edge"].asKey()
112 self.
saturatedKeysaturatedKey = schema[
"base_PixelFlags_flag_saturated"].asKey()
114 def _isParent(self, sourceCat):
115 """Return True for each source that is the parent source.
117 test = (sourceCat.get(self.
parentKeyparentKey) == 0)
120 def _hasCentroid(self, sourceCat):
121 """Return True for each source that has a valid centroid
123 return np.isfinite(sourceCat.get(self.
centroidXKeycentroidXKey)) \
124 & np.isfinite(sourceCat.get(self.
centroidYKeycentroidYKey)) \
127 def _goodSN(self, sourceCat):
128 """Return True for each source that has Signal/Noise > config.minSnr.
130 if self.config.minSnr <= 0:
133 with np.errstate(invalid=
"ignore"):
134 return sourceCat.get(self.
fluxKeyfluxKey)/sourceCat.get(self.
fluxErrKeyfluxErrKey) > self.config.minSnr
136 def _isUsable(self, sourceCat):
138 Return True for each source that is usable for matching, even if it may
139 have a poor centroid.
141 For a source to be usable it must:
142 - have a valid centroid
144 - have a valid instFlux (of the type specified in this object's constructor)
145 - have adequate signal-to-noise
149 & self.
_goodSN_goodSN(sourceCat) \
152 def _isGood(self, sourceCat):
154 Return True for each source that is usable for matching, even if it may
155 have a poor centroid.
157 For a source to be usable it must:
158 - Not be on a CCD edge.
159 - Not have an interpolated pixel within 3x3 around their centroid.
160 - Not have a saturated pixel in their footprint.
162 return ~sourceCat.get(self.
edgeKeyedgeKey) & \
def selectSources(self, sourceCat, matches=None, exposure=None)
def _goodSN(self, sourceCat)
def _hasCentroid(self, sourceCat)
def __init__(self, *args, **kwargs)
def _isParent(self, sourceCat)
def _getSchemaKeys(self, schema)
def _isGood(self, sourceCat)
def _isUsable(self, sourceCat)