22"""Select sources that are useful for astrometry.
24Such sources have good signal-to-noise, are well centroided, not blended,
25and not flagged with a handful of "bad" flags.
28__all__ = [
"AstrometrySourceSelectorConfig",
"AstrometrySourceSelectorTask"]
30from deprecated.sphinx
import deprecated
36from .sourceSelector
import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
38from functools
import reduce
42 badFlags = pexConfig.ListField(
43 doc=
"List of flags which cause a source to be rejected as bad",
46 "base_PixelFlags_flag_edge",
47 "base_PixelFlags_flag_interpolatedCenter",
48 "base_PixelFlags_flag_saturatedCenter",
49 "base_PixelFlags_flag_crCenter",
50 "base_PixelFlags_flag_bad",
53 sourceFluxType = pexConfig.Field(
54 doc=
"Type of source flux; typically one of Ap or Psf",
58 minSnr = pexConfig.Field(
60 doc=
"Minimum allowed signal-to-noise ratio for sources used for matching "
61 "(in the flux specified by sourceFluxType); <= 0 for no limit",
67@deprecated(reason=(
"This Task has been replaced by an appropriately configured ScienceSourceSelector."
68 " See `AstrometryConfig.setDefaults` in meas_astrom for an example config that was "
69 "made to closely match this Task. Will be removed after v27."),
70 version=
"v27.0", category=FutureWarning)
71@pexConfig.registerConfigurable("astrometry", sourceSelectorRegistry)
73 """Select sources that are useful for astrometry.
75 Good astrometry sources have high signal/noise, are non-blended, and
76 did not have certain "bad" flags set during source extraction. They need not
77 be PSF sources, just have reliable centroids.
79 ConfigClass = AstrometrySourceSelectorConfig
82 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
85 """Return a selection of sources that are useful for astrometry.
89 sourceCat : `lsst.afw.table.SourceCatalog`
90 Catalog of sources to select from.
91 This catalog must be contiguous in memory.
92 matches : `list` of `lsst.afw.table.ReferenceMatch` or None
93 Ignored in this SourceSelector.
94 exposure : `lsst.afw.image.Exposure` or None
95 The exposure the catalog was built from; used for debug display.
99 struct : `lsst.pipe.base.Struct`
100 The struct contains the following data:
103 Boolean array of sources that were selected, same length as
104 sourceCat. (`numpy.ndarray` of `bool`)
108 bad = reduce(
lambda x, y: np.logical_or(x, sourceCat[y]), self.config.badFlags,
False)
110 return Struct(selected=good & ~bad)
113 """Extract and save the necessary keys from schema with asKey.
124 except NotFoundError:
127 self.
edgeKey = schema[
"base_PixelFlags_flag_edge"].asKey()
131 fluxPrefix =
"slot_%sFlux_" % (self.config.sourceFluxType,)
137 """Return True for each source that is likely multiple sources.
141 for i, cat
in enumerate(sourceCat):
142 footprint = cat.getFootprint()
143 test[i] |= (footprint
is not None)
and (len(footprint.getPeaks()) > 1)
147 """Return True for each source that has a valid centroid
149 def checkNonfiniteCentroid():
150 """Return True for sources with non-finite centroids.
154 assert ~checkNonfiniteCentroid().any(), \
155 "Centroids not finite for %d unflagged sources." % (checkNonfiniteCentroid().sum())
161 """Return True for each source that has Signal/Noise > config.minSnr.
163 if self.config.minSnr <= 0:
166 with np.errstate(invalid=
"ignore"):
170 """Return True for each source that is usable for matching, even if it may
171 have a poor centroid.
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
186 """Return True if this is a primary source.
191 return np.ones(len(sourceCat), dtype=bool)
194 """Return True for each source that is usable for matching and likely has a
197 The additional tests for a good centroid, beyond isUsable, are:
198 - not interpolated in the center
210 """Return True if any of config.badFlags are set for this source.
212 return any(source[flag]
for flag
in self.config.badFlags)
_isBadFlagged(self, source)
selectSources(self, sourceCat, matches=None, exposure=None)
_isPrimary(self, sourceCat)
_hasCentroid(self, sourceCat)
_isUsable(self, sourceCat)
_getSchemaKeys(self, schema)
__init__(self, *args, **kwargs)
_isMultiple(self, sourceCat)