23 from __future__
import absolute_import, division, print_function
25 __all__ = [
"BaseStarSelectorConfig",
"BaseStarSelectorTask",
"starSelectorRegistry"]
31 from lsst.afw.table
import SourceCatalog, Schema
32 import lsst.afw.math
as afwMath
33 import lsst.pex.config
as pexConfig
34 import lsst.pipe.base
as pipeBase
35 from .
import makePsfCandidate
36 from future.utils
import with_metaclass
40 kernelSize = pexConfig.Field(
41 doc=
"size of the kernel to create",
45 borderWidth = pexConfig.Field(
46 doc=
"number of pixels to ignore around the edge of PSF candidate postage stamps",
50 badFlags = pexConfig.ListField(
51 doc=
"List of flags which cause a source to be rejected as bad",
54 "base_PixelFlags_flag_edge",
55 "base_PixelFlags_flag_interpolatedCenter",
56 "base_PixelFlags_flag_saturatedCenter",
57 "base_PixelFlags_flag_crCenter",
58 "base_PixelFlags_flag_bad",
59 "base_PixelFlags_flag_interpolated",
65 """!Base class for star selectors 67 Register all star selectors with the starSelectorRegistry using: 68 starSelectorRegistry.register(name, class) 72 ConfigClass = BaseStarSelectorConfig
73 _DefaultName =
"starSelector" 77 assert isinstance(schema, Schema)
78 pipeBase.Task.__init__(self, **kwds)
80 def run(self, exposure, sourceCat, matches=None, isStarField=None):
81 """!Select stars, make PSF candidates, and set a flag field True for stars in the input catalog 83 @param[in] exposure the exposure containing the sources 84 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 85 @param[in] matches astrometric matches; ignored by this star selector 86 (an lsst.afw.table.ReferenceMatchVector), or None. Some star selectors 87 will ignore this argument, others may require it. See the usesMatches class variable. 88 @param[in] isStarField name of flag field to set True for stars, or None to not set a field; 89 the field is left unchanged for non-stars 91 @return an lsst.pipe.base.Struct containing: 92 - starCat catalog of stars that were selected as stars and successfuly made into PSF candidates 93 (a subset of sourceCat whose records are shallow copies) 94 - psfCandidates list of PSF candidates (lsst.meas.algorithms.PsfCandidate) 96 selRes = self.
selectStars(exposure=exposure, sourceCat=sourceCat, matches=matches)
99 if isStarField
is not None:
100 isStarKey = sourceCat.schema[isStarField].asKey()
101 for star
in psfRes.goodStarCat:
102 star.set(isStarKey,
True)
104 return pipeBase.Struct(
105 starCat=psfRes.goodStarCat,
106 psfCandidates=psfRes.psfCandidates,
111 """!Return a catalog of stars: a subset of sourceCat whose records are shallow copies 113 @param[in] exposure the exposure containing the sources 114 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 115 @param[in] matches astrometric matches; ignored by this star selector 116 (an lsst.afw.table.ReferenceMatchVector), or None. Some star selectors 117 will ignore this argument, others may require it. See the usesMatches class variable. 119 @warning The returned catalog must have records that are shallow copies 120 (fortunately this is the default behavior when you add a record from one catalog to another); 121 otherwise the run method cannot set the isStarField flag in the original source catalog. 123 @return a pipeBase.Struct containing: 124 - starCat a catalog of stars (a subset of sourceCat whose records are shallow copies) 126 raise NotImplementedError(
"BaseStarSelectorTask is abstract, subclasses must override this method")
129 """!Make a list of PSF candidates from a star catalog 131 @param[in] exposure the exposure containing the sources 132 @param[in] starCat catalog of stars (an lsst.afw.table.SourceCatalog), 133 e.g. as returned by the run or selectStars method 135 @return an lsst.pipe.base.Struct with fields: 136 - psfCandidates list of PSF candidates (lsst.meas.algorithms.PsfCandidate) 137 - goodStarCat catalog of stars that were successfully made into PSF candidates (a subset of starCat) 139 goodStarCat = SourceCatalog(starCat.schema)
141 psfCandidateList = []
151 psfCandidate.setBorderWidth(self.config.borderWidth)
152 psfCandidate.setWidth(self.config.kernelSize + 2*self.config.borderWidth)
153 psfCandidate.setHeight(self.config.kernelSize + 2*self.config.borderWidth)
156 im = psfCandidate.getMaskedImage().getImage()
157 except Exception
as err:
158 self.log.debug(
"Failed to make a psfCandidate from star %d: %s", star.getId(), err)
161 vmax = afwMath.makeStatistics(im, afwMath.MAX).getValue()
162 if not np.isfinite(vmax):
164 psfCandidateList.append(psfCandidate)
165 goodStarCat.append(star)
167 return pipeBase.Struct(
168 psfCandidates=psfCandidateList,
169 goodStarCat=goodStarCat,
173 starSelectorRegistry = pexConfig.makeRegistry(
174 doc=
"A registry of star selectors (subclasses of BaseStarSelectorTask)",
def selectStars(self, exposure, sourceCat, matches=None)
Return a catalog of stars: a subset of sourceCat whose records are shallow copies.
Base class for star selectors.
def makePsfCandidates(self, exposure, starCat)
Make a list of PSF candidates from a star catalog.
def __init__(self, schema, kwds)
std::shared_ptr< PsfCandidate< PixelT > > makePsfCandidate(boost::shared_ptr< afw::table::SourceRecord > const &source, boost::shared_ptr< afw::image::Exposure< PixelT > > image)
Return a PsfCandidate of the right sort.
def run(self, exposure, sourceCat, matches=None, isStarField=None)
Select stars, make PSF candidates, and set a flag field True for stars in the input catalog...