22 from __future__
import absolute_import, division, print_function
32 from .
import algorithmsLib
33 from future.utils
import with_metaclass
35 __all__ = [
"BaseStarSelectorConfig",
"BaseStarSelectorTask",
"starSelectorRegistry"]
39 kernelSize = pexConfig.Field(
40 doc=
"size of the kernel to create",
44 borderWidth = pexConfig.Field(
45 doc=
"number of pixels to ignore around the edge of PSF candidate postage stamps",
49 badFlags = pexConfig.ListField(
50 doc=
"List of flags which cause a source to be rejected as bad",
53 "base_PixelFlags_flag_edge",
54 "base_PixelFlags_flag_interpolatedCenter",
55 "base_PixelFlags_flag_saturatedCenter",
56 "base_PixelFlags_flag_crCenter",
57 "base_PixelFlags_flag_bad",
58 "base_PixelFlags_flag_interpolated",
64 """!Base class for star selectors
66 Register all star selectors with the starSelectorRegistry using:
67 starSelectorRegistry.register(name, class)
71 ConfigClass = BaseStarSelectorConfig
72 _DefaultName =
"starSelector"
76 assert isinstance(schema, Schema)
77 pipeBase.Task.__init__(self, **kwds)
79 def run(self, exposure, sourceCat, matches=None, isStarField=None):
80 """!Select stars, make PSF candidates, and set a flag field True for stars in the input catalog
82 @param[in] exposure the exposure containing the sources
83 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog)
84 @param[in] matches astrometric matches; ignored by this star selector
85 (an lsst.afw.table.ReferenceMatchVector), or None. Some star selectors
86 will ignore this argument, others may require it. See the usesMatches class variable.
87 @param[in] isStarField name of flag field to set True for stars, or None to not set a field;
88 the field is left unchanged for non-stars
90 @return an lsst.pipe.base.Struct containing:
91 - starCat catalog of stars that were selected as stars and successfuly made into PSF candidates
92 (a subset of sourceCat whose records are shallow copies)
93 - psfCandidates list of PSF candidates (lsst.meas.algorithms.PsfCandidate)
95 selRes = self.
selectStars(exposure=exposure, sourceCat=sourceCat, matches=matches)
98 if isStarField
is not None:
99 isStarKey = sourceCat.schema[isStarField].asKey()
100 for star
in psfRes.goodStarCat:
101 star.set(isStarKey,
True)
103 return pipeBase.Struct(
104 starCat=psfRes.goodStarCat,
105 psfCandidates=psfRes.psfCandidates,
110 """!Return a catalog of stars: a subset of sourceCat whose records are shallow copies
112 @param[in] exposure the exposure containing the sources
113 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog)
114 @param[in] matches astrometric matches; ignored by this star selector
115 (an lsst.afw.table.ReferenceMatchVector), or None. Some star selectors
116 will ignore this argument, others may require it. See the usesMatches class variable.
118 @warning The returned catalog must have records that are shallow copies
119 (fortunately this is the default behavior when you add a record from one catalog to another);
120 otherwise the run method cannot set the isStarField flag in the original source catalog.
122 @return a pipeBase.Struct containing:
123 - starCat a catalog of stars (a subset of sourceCat whose records are shallow copies)
125 raise NotImplementedError(
"BaseStarSelectorTask is abstract, subclasses must override this method")
128 """!Make a list of PSF candidates from a star catalog
130 @param[in] exposure the exposure containing the sources
131 @param[in] starCat catalog of stars (an lsst.afw.table.SourceCatalog),
132 e.g. as returned by the run or selectStars method
134 @return an lsst.pipe.base.Struct with fields:
135 - psfCandidates list of PSF candidates (lsst.meas.algorithms.PsfCandidate)
136 - goodStarCat catalog of stars that were successfully made into PSF candidates (a subset of starCat)
140 psfCandidateList = []
144 psfCandidate = algorithmsLib.makePsfCandidate(star, exposure)
150 psfCandidate.setBorderWidth(self.config.borderWidth)
151 psfCandidate.setWidth(self.config.kernelSize + 2*self.config.borderWidth)
152 psfCandidate.setHeight(self.config.kernelSize + 2*self.config.borderWidth)
155 im = psfCandidate.getMaskedImage().getImage()
156 except Exception
as err:
157 self.log.debug(
"Failed to make a psfCandidate from star %d: %s", star.getId(), err)
161 if not np.isfinite(vmax):
163 psfCandidateList.append(psfCandidate)
164 goodStarCat.append(star)
166 return pipeBase.Struct(
167 psfCandidates=psfCandidateList,
168 goodStarCat=goodStarCat,
172 starSelectorRegistry = pexConfig.makeRegistry(
173 doc=
"A registry of star selectors (subclasses of BaseStarSelectorTask)",
def run
Select stars, make PSF candidates, and set a flag field True for stars in the input catalog...
def makePsfCandidates
Make a list of PSF candidates from a star catalog.
Base class for star selectors.
def selectStars
Return a catalog of stars: a subset of sourceCat whose records are shallow copies.
SortedCatalogT< SourceRecord > SourceCatalog
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.