24 __all__ = [
"BaseStarSelectorConfig",
"BaseStarSelectorTask",
"starSelectorRegistry"]
34 from .
import makePsfCandidate
38 kernelSize = pexConfig.Field(
39 doc=
"size of the kernel to create",
43 borderWidth = pexConfig.Field(
44 doc=
"number of pixels to ignore around the edge of PSF candidate postage stamps",
48 badFlags = pexConfig.ListField(
49 doc=
"List of flags which cause a source to be rejected as bad",
52 "base_PixelFlags_flag_edge",
53 "base_PixelFlags_flag_interpolatedCenter",
54 "base_PixelFlags_flag_saturatedCenter",
55 "base_PixelFlags_flag_crCenter",
56 "base_PixelFlags_flag_bad",
57 "base_PixelFlags_flag_interpolated",
63 """!Base class for star selectors 65 Register all star selectors with the starSelectorRegistry using: 66 starSelectorRegistry.register(name, class) 70 ConfigClass = BaseStarSelectorConfig
71 _DefaultName =
"starSelector" 75 assert isinstance(schema, Schema)
76 pipeBase.Task.__init__(self, **kwds)
78 def run(self, exposure, sourceCat, matches=None, isStarField=None):
79 """!Select stars, make PSF candidates, and set a flag field True for stars in the input catalog 81 @param[in] exposure the exposure containing the sources 82 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 83 @param[in] matches astrometric matches; ignored by this star selector 84 (an lsst.afw.table.ReferenceMatchVector), or None. Some star selectors 85 will ignore this argument, others may require it. See the usesMatches class variable. 86 @param[in] isStarField name of flag field to set True for stars, or None to not set a field; 87 the field is left unchanged for non-stars 89 @return an lsst.pipe.base.Struct containing: 90 - starCat catalog of stars that were selected as stars and successfuly made into PSF candidates 91 (a subset of sourceCat whose records are shallow copies) 92 - psfCandidates list of PSF candidates (lsst.meas.algorithms.PsfCandidate) 94 selRes = self.
selectStars(exposure=exposure, sourceCat=sourceCat, matches=matches)
97 if isStarField
is not None:
98 isStarKey = sourceCat.schema[isStarField].asKey()
99 for star
in psfRes.goodStarCat:
100 star.set(isStarKey,
True)
102 return pipeBase.Struct(
103 starCat=psfRes.goodStarCat,
104 psfCandidates=psfRes.psfCandidates,
109 """!Return a catalog of stars: a subset of sourceCat whose records are shallow copies 111 @param[in] exposure the exposure containing the sources 112 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 113 @param[in] matches astrometric matches; ignored by this star selector 114 (an lsst.afw.table.ReferenceMatchVector), or None. Some star selectors 115 will ignore this argument, others may require it. See the usesMatches class variable. 117 @warning The returned catalog must have records that are shallow copies 118 (fortunately this is the default behavior when you add a record from one catalog to another); 119 otherwise the run method cannot set the isStarField flag in the original source catalog. 121 @return a pipeBase.Struct containing: 122 - starCat a catalog of stars (a subset of sourceCat whose records are shallow copies) 124 raise NotImplementedError(
"BaseStarSelectorTask is abstract, subclasses must override this method")
127 """!Make a list of PSF candidates from a star catalog 129 @param[in] exposure the exposure containing the sources 130 @param[in] starCat catalog of stars (an lsst.afw.table.SourceCatalog), 131 e.g. as returned by the run or selectStars method 133 @return an lsst.pipe.base.Struct with fields: 134 - psfCandidates list of PSF candidates (lsst.meas.algorithms.PsfCandidate) 135 - goodStarCat catalog of stars that were successfully made into PSF candidates (a subset of starCat) 137 goodStarCat = SourceCatalog(starCat.schema)
139 psfCandidateList = []
149 psfCandidate.setBorderWidth(self.config.borderWidth)
150 psfCandidate.setWidth(self.config.kernelSize + 2*self.config.borderWidth)
151 psfCandidate.setHeight(self.config.kernelSize + 2*self.config.borderWidth)
154 im = psfCandidate.getMaskedImage().getImage()
155 except Exception
as err:
156 self.log.debug(
"Failed to make a psfCandidate from star %d: %s", star.getId(), err)
160 if not np.isfinite(vmax):
162 psfCandidateList.append(psfCandidate)
163 goodStarCat.append(star)
165 return pipeBase.Struct(
166 psfCandidates=psfCandidateList,
167 goodStarCat=goodStarCat,
171 starSelectorRegistry = pexConfig.makeRegistry(
172 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.
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
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...