23 from __future__
import absolute_import, division, print_function
29 from .sourceSelector
import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
34 sourceFluxType = pexConfig.Field(
35 doc=
"Type of source flux; typically one of Ap or Psf",
39 minSnr = pexConfig.Field(
41 doc=
"Minimum allowed signal-to-noise ratio for sources used for matching " 42 "(in the flux specified by sourceFluxType); <= 0 for no limit",
49 !Select sources that are useful for matching. 51 Good matching sources have high signal/noise, are non-blended. They need not 52 be PSF sources, just have reliable centroids. 54 ConfigClass = MatcherSourceSelectorConfig
57 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
61 !Return a catalog of sources: a subset of sourceCat. 63 If sourceCat is cotiguous in memory, will use vectorized tests for ~100x 64 execution speed advantage over non-contiguous catalogs. This would be 65 even faster if we didn't have to check footprints for multiple peaks. 67 @param[in] sourceCat catalog of sources that may be sources 68 (an lsst.afw.table.SourceCatalog) 70 @return a pipeBase.Struct containing: 71 - sourceCat a catalog of sources 75 if sourceCat.isContiguous():
77 result = sourceCat[good]
79 result = table.SourceCatalog(sourceCat.table)
80 for i, source
in enumerate(sourceCat):
83 return Struct(sourceCat=result)
85 def _getSchemaKeys(self, schema):
86 """Extract and save the necessary keys from schema with asKey.""" 92 fluxPrefix =
"slot_%sFlux_" % (self.config.sourceFluxType,)
94 self.
fluxKey = schema[fluxPrefix +
"flux"].asKey()
98 def _isParent_vector(self, sourceCat):
99 """Return True for each source that is the parent source.""" 100 test = (sourceCat.get(self.
parentKey) == 0)
103 def _isParent(self, source):
104 """Return True if source is the parent source.""" 109 def _hasCentroid_vector(self, sourceCat):
110 """Return True for each source that has a valid centroid""" 115 def _hasCentroid(self, source):
116 """Return True if the source has a valid centroid""" 117 centroid = source.getCentroid()
118 return np.all(np.isfinite(centroid))
and not source.getCentroidFlag()
120 def _goodSN_vector(self, sourceCat):
121 """Return True for each source that has Signal/Noise > config.minSnr.""" 122 if self.config.minSnr <= 0:
125 with np.errstate(invalid=
"ignore"):
128 def _goodSN(self, source):
129 """Return True if source has Signal/Noise > config.minSnr.""" 130 return (self.config.minSnr <= 0
or 133 def _isUsable_vector(self, sourceCat):
135 Return True for each source that is usable for matching, even if it may 136 have a poor centroid. 138 For a source to be usable it must: 139 - have a valid centroid 141 - have a valid flux (of the type specified in this object's constructor) 142 - have adequate signal-to-noise 149 def _isUsable(self, source):
151 Return True if the source is usable for matching, even if it may have a 154 For a source to be usable it must: 155 - have a valid centroid 157 - have a valid flux (of the type specified in this object's constructor) 158 - have adequate signal-to-noise 168 !Select sources that are useful for matching. 170 Good matching sources have high signal/noise, are non-blended. They need not 171 be PSF sources, just have reliable centroids. This inherited class adds 172 the removal of saturated, interpolated, and edge_key objects to the set of 173 bad flags. It is a temporary addition designed preserve the source selction 174 used in matchOptimisticB. Once matchPessimisticB is adopted as the default 175 source selector the class will be removed and the saturated, interpoalted, and 176 edge_key flags will be added to the matcherSourceSelector class. 178 TODO: Once DM-10399 is complete an RFC will be filed to make matchPessimisticB 179 the default matcher this class will replace matcherSourceSelector with this source 180 selector resulting in only one matcherSourceSeletor. The ticket describing 181 this work is DM-10800. 183 def _getSchemaKeys(self, schema):
184 """Extract and save the necessary keys from schema with asKey.""" 185 MatcherSourceSelectorTask._getSchemaKeys(self, schema)
187 self.
edgeKey = schema[
"base_PixelFlags_flag_edge"].asKey()
191 def _isUsable_vector(self, sourceCat):
193 Return True for each source that is usable for matching, even if it may 194 have a poor centroid. 196 For a source to be usable it must: 197 - have a valid centroid 199 - have a valid flux (of the type specified in this object's constructor) 200 - have adequate signal-to-noise 202 result = MatcherSourceSelectorTask._isUsable_vector(self, sourceCat)
205 & ~sourceCat.get(self.
edgeKey) \
209 def _isUsable(self, source):
211 Return True if the source is usable for matching, even if it may have a 214 For a source to be usable it must: 215 - have a valid centroid 217 - have a valid flux (of the type specified in this object's constructor) 218 - have adequate signal-to-noise 220 result = MatcherSourceSelectorTask._isUsable(self, source)
223 and not source.get(self.
edgeKey) \
228 sourceSelectorRegistry.register(
"matcher", MatcherSourceSelectorTask)
229 sourceSelectorRegistry.register(
"matcherPessimistic",
230 MatcherPessimisticSourceSelectorTask)
def selectSources(self, sourceCat, matches=None)
def _goodSN_vector(self, sourceCat)
def _isParent(self, source)
def _goodSN(self, source)
def _hasCentroid_vector(self, sourceCat)
def _hasCentroid(self, source)
def _isUsable(self, source)
def __init__(self, args, kwargs)
def _isUsable_vector(self, sourceCat)
def _isParent_vector(self, sourceCat)
def _getSchemaKeys(self, schema)
Base class for source selectors.