23__all__ = [
"MakePsfCandidatesConfig",
"MakePsfCandidatesTask"]
32from .
import makePsfCandidate
36 kernelSize = pexConfig.Field[int](
37 doc=
"Size of the postage stamp in pixels (excluding the border) around each star that is extracted "
38 "for fitting. Should be odd and preferably at least 25.",
41 borderWidth = pexConfig.Field[int](
42 doc=
"Number of pixels to ignore around the edge of PSF candidate postage stamps",
48 """Create PSF candidates given an input catalog.
50 ConfigClass = MakePsfCandidatesConfig
51 _DefaultName = "makePsfCandidates"
53 def run(self, starCat, exposure, psfCandidateField=None):
54 """Make a list of PSF candidates from a star catalog.
59 Catalog of stars, as returned by
60 ``lsst.meas.algorithms.starSelector.run()``.
62 The exposure containing the sources.
63 psfCandidateField : `str`, optional
64 Name of flag field to set
True for PSF candidates,
or None to
not
65 set a field; the field
is left unchanged
for non-candidates.
69 struct : `lsst.pipe.base.Struct`
70 Results struct containing:
72 - ``psfCandidates`` : List of PSF candidates
74 - ``goodStarCat`` : Subset of ``starCat`` that was successfully made
80 if psfCandidateField
is not None:
81 isStarKey = starCat.schema[psfCandidateField].asKey()
82 for star
in psfResult.goodStarCat:
83 star.set(isStarKey,
True)
87 def makePsfCandidates(self, starCat, exposure):
88 """Make a list of PSF candidates from a star catalog.
93 Catalog of stars, as returned by
94 ``lsst.meas.algorithms.starSelector.run()``.
96 The exposure containing the sources.
100 struct : `lsst.pipe.base.Struct`
101 Results struct containing:
103 - ``psfCandidates`` : List of PSF candidates
105 - ``goodStarCat`` : Subset of ``starCat`` that was successfully made
108 goodStarCat = SourceCatalog(starCat.schema)
110 psfCandidateList = []
113 psfCandidate = makePsfCandidate(star, exposure)
119 psfCandidate.setBorderWidth(self.config.borderWidth)
120 psfCandidate.setWidth(self.config.kernelSize + 2*self.config.borderWidth)
121 psfCandidate.setHeight(self.config.kernelSize + 2*self.config.borderWidth)
124 im = psfCandidate.getMaskedImage().getImage()
126 self.log.warning(
"Could not get stamp for psfCandidate with source id=%s: %s",
127 star.getId(), psfCandidate)
130 self.log.error(
"%s raised making psfCandidate from source id=%s: %s",
131 e.__class__.__name__, star.getId(), psfCandidate)
132 self.log.error(
"psfCandidate exception: %s", e)
135 vmax = afwMath.makeStatistics(im, afwMath.MAX).getValue()
136 if not np.isfinite(vmax):
138 psfCandidateList.append(psfCandidate)
139 goodStarCat.append(star)
141 return pipeBase.Struct(
142 psfCandidates=psfCandidateList,
143 goodStarCat=goodStarCat,
Class stored in SpatialCells for spatial Psf fitting.
run(self, starCat, exposure, psfCandidateField=None)
makePsfCandidates(self, starCat, exposure)