23"""Select sources that are useful for astrometry.
25Such sources have good signal-to-noise, are well centroided, not blended,
26and not flagged with a handful of "bad" flags.
29__all__ = [
"AstrometrySourceSelectorConfig",
"AstrometrySourceSelectorTask"]
35from .sourceSelector
import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
37from functools
import reduce
41 badFlags = pexConfig.ListField(
42 doc=
"List of flags which cause a source to be rejected as bad",
45 "base_PixelFlags_flag_edge",
46 "base_PixelFlags_flag_interpolatedCenter",
47 "base_PixelFlags_flag_saturatedCenter",
48 "base_PixelFlags_flag_crCenter",
49 "base_PixelFlags_flag_bad",
52 sourceFluxType = pexConfig.Field(
53 doc=
"Type of source flux; typically one of Ap or Psf",
57 minSnr = pexConfig.Field(
59 doc=
"Minimum allowed signal-to-noise ratio for sources used for matching "
60 "(in the flux specified by sourceFluxType); <= 0 for no limit",
65@pexConfig.registerConfigurable("astrometry", sourceSelectorRegistry)
67 """Select sources that are useful for astrometry.
69 Good astrometry sources have high signal/noise, are non-blended, and
70 did
not have certain
"bad" flags set during source extraction. They need
not
71 be PSF sources, just have reliable centroids.
73 ConfigClass = AstrometrySourceSelectorConfig
76 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
79 """Return a selection of sources that are useful for astrometry.
84 Catalog of sources to select from.
85 This catalog must be contiguous
in memory.
87 Ignored
in this SourceSelector.
89 The exposure the catalog was built
from; used
for debug display.
93 struct : `lsst.pipe.base.Struct`
94 The struct contains the following data:
97 Boolean array of sources that were selected, same length
as
98 sourceCat. (`numpy.ndarray` of `bool`)
102 bad = reduce(lambda x, y: np.logical_or(x, sourceCat.get(y)), self.config.badFlags,
False)
104 return Struct(selected=good & ~bad)
106 def _getSchemaKeys(self, schema):
107 """Extract and save the necessary keys from schema with asKey.
118 except NotFoundError:
121 self.
edgeKey = schema[
"base_PixelFlags_flag_edge"].asKey()
125 fluxPrefix =
"slot_%sFlux_" % (self.config.sourceFluxType,)
130 def _isMultiple(self, sourceCat):
131 """Return True for each source that is likely multiple sources.
135 for i, cat
in enumerate(sourceCat):
136 footprint = cat.getFootprint()
137 test[i] |= (footprint
is not None)
and (len(footprint.getPeaks()) > 1)
140 def _hasCentroid(self, sourceCat):
141 """Return True for each source that has a valid centroid
143 def checkNonfiniteCentroid():
144 """Return True for sources with non-finite centroids.
146 return ~np.isfinite(sourceCat.get(self.
centroidXKey)) | \
148 assert ~checkNonfiniteCentroid().any(), \
149 "Centroids not finite for %d unflagged sources." % (checkNonfiniteCentroid().sum())
154 def _goodSN(self, sourceCat):
155 """Return True for each source that has Signal/Noise > config.minSnr.
157 if self.config.minSnr <= 0:
160 with np.errstate(invalid=
"ignore"):
163 def _isUsable(self, sourceCat):
164 """Return True for each source that is usable for matching, even if it may
165 have a poor centroid.
167 For a source to be usable it must:
168 - have a valid centroid
170 - have a valid flux (of the type specified
in this object
's constructor)
171 - have adequate signal-to-noise
179 def _isPrimary(self, sourceCat):
180 """Return True if this is a primary source.
185 return np.ones(len(sourceCat), dtype=bool)
187 def _isGood(self, sourceCat):
188 """Return True for each source that is usable for matching and likely has a
191 The additional tests for a good centroid, beyond isUsable, are:
192 -
not interpolated
in the center
203 def _isBadFlagged(self, source):
204 """Return True if any of config.badFlags are set for this source.
206 return any(source.get(flag)
for flag
in self.config.badFlags)
def _hasCentroid(self, sourceCat)
def _isUsable(self, sourceCat)
def __init__(self, *args, **kwargs)
def selectSources(self, sourceCat, matches=None, exposure=None)
def _isMultiple(self, sourceCat)
def _isGood(self, sourceCat)
def _getSchemaKeys(self, schema)
def _isPrimary(self, sourceCat)
def _goodSN(self, sourceCat)