23 from __future__
import absolute_import, division, print_function
29 from .sourceSelector
import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
31 from functools
import reduce
35 sourceFluxType = pexConfig.Field(
36 doc=
"Type of source flux; typically one of Ap or Psf",
40 minSnr = pexConfig.Field(
42 doc=
"Minimum allowed signal-to-noise ratio for sources used for matching " 43 "(in the flux specified by sourceFluxType); <= 0 for no limit",
50 !Select sources that are useful for astrometry. 52 Good astrometry sources have high signal/noise, are non-blended, and 53 did not have certain "bad" flags set during source extraction. They need not 54 be PSF sources, just have reliable centroids. 56 ConfigClass = AstrometrySourceSelectorConfig
59 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
63 !Return a catalog of sources: a subset of sourceCat. 65 If sourceCat is cotiguous in memory, will use vectorized tests for ~100x 66 execution speed advantage over non-contiguous catalogs. This would be 67 even faster if we didn't have to check footprints for multiple peaks. 69 @param[in] sourceCat catalog of sources that may be sources 70 (an lsst.afw.table.SourceCatalog) 72 @return a pipeBase.Struct containing: 73 - sourceCat a catalog of sources 77 if sourceCat.isContiguous():
78 bad = reduce(
lambda x, y: np.logical_or(x, sourceCat.get(y)), self.config.badFlags,
False)
80 result = sourceCat[good & ~bad]
82 result = table.SourceCatalog(sourceCat.table)
83 for i, source
in enumerate(sourceCat):
86 return Struct(sourceCat=result)
88 def _getSchemaKeys(self, schema):
89 """Extract and save the necessary keys from schema with asKey.""" 98 self.
edgeKey = schema[
"base_PixelFlags_flag_edge"].asKey()
102 fluxPrefix =
"slot_%sFlux_" % (self.config.sourceFluxType,)
103 self.
fluxKey = schema[fluxPrefix +
"flux"].asKey()
107 def _isMultiple_vector(self, sourceCat):
108 """Return True for each source that is likely multiple sources.""" 111 for i, cat
in enumerate(sourceCat):
112 footprint = cat.getFootprint()
113 test[i] |= (footprint
is not None)
and (len(footprint.getPeaks()) > 1)
116 def _isMultiple(self, source):
117 """Return True if source is likely multiple sources.""" 120 footprint = source.getFootprint()
121 return footprint
is not None and len(footprint.getPeaks()) > 1
123 def _hasCentroid_vector(self, sourceCat):
124 """Return True for each source that has a valid centroid""" 125 def checkNonfiniteCentroid():
126 """Return True for sources with non-finite centroids.""" 128 assert ~checkNonfiniteCentroid().any(), \
129 "Centroids not finite for %d unflagged sources." % (checkNonfiniteCentroid().sum())
134 def _hasCentroid(self, source):
135 """Return True if the source has a valid centroid""" 136 assert np.all(np.isfinite(source.getCentroid())),
'Centroid not finite for source: %s' % source
137 return np.all(np.isfinite(source.getCentroidErr()))
and not source.getCentroidFlag()
139 def _goodSN_vector(self, sourceCat):
140 """Return True for each source that has Signal/Noise > config.minSnr.""" 141 if self.config.minSnr <= 0:
146 def _goodSN(self, source):
147 """Return True if source has Signal/Noise > config.minSnr.""" 148 return (self.config.minSnr <= 0
or 151 def _isUsable_vector(self, sourceCat):
153 Return True for each source that is usable for matching, even if it may 154 have a poor centroid. 156 For a source to be usable it must: 157 - have a valid centroid 159 - have a valid flux (of the type specified in this object's constructor) 160 - have adequate signal-to-noise 168 def _isUsable(self, source):
170 Return True if the source is usable for matching, even if it may have a 173 For a source to be usable it must: 174 - have a valid centroid 176 - have a valid flux (of the type specified in this object's constructor) 177 - have adequate signal-to-noise 184 def _isGood_vector(self, sourceCat):
186 Return True for each source that is usable for matching and likely has a 189 The additional tests for a good centroid, beyond isUsable, are: 190 - not interpolated in the center 200 def _isGood(self, source):
202 Return True if source is usable for matching and likely has a good centroid. 204 The additional tests for a good centroid, beyond isUsable, are: 205 - not interpolated in the center 212 and not source.get(self.
edgeKey)
215 sourceSelectorRegistry.register(
"astrometry", AstrometrySourceSelectorTask)
def _isGood_vector(self, sourceCat)
def __init__(self, args, kwargs)
def selectSources(self, sourceCat, matches=None)
def _hasCentroid_vector(self, sourceCat)
def _isUsable(self, source)
def _isMultiple(self, source)
def _isGood(self, source)
def _goodSN_vector(self, sourceCat)
def _isMultiple_vector(self, sourceCat)
def _getSchemaKeys(self, schema)
def _goodSN(self, source)
def _hasCentroid(self, source)
def _isUsable_vector(self, sourceCat)
Base class for source selectors.