23 __all__ = [
"CatalogStarSelectorConfig",
"CatalogStarSelectorTask"]
27 from lsst.meas.algorithms
import BaseStarSelectorTask, starSelectorRegistry
28 from lsst.pipe.base
import Struct
34 fluxLim = pexConfig.RangeField(
35 doc=
"specify the minimum psfFlux for good Psf Candidates",
40 fluxMax = pexConfig.RangeField(
41 doc=
"specify the maximum psfFlux for good Psf Candidates (ignored if == 0)",
48 BaseStarSelectorTask.ConfigClass.setDefaults(self)
50 "base_PixelFlags_flag_edge",
51 "base_PixelFlags_flag_interpolatedCenter",
52 "base_PixelFlags_flag_saturatedCenter",
57 """A functor to check whether a source has any flags set that should cause it to be labeled bad.""" 59 def __init__(self, table, fluxLim, fluxMax, badFlags):
60 self.
keys = [table.getSchema().find(name).key
for name
in badFlags]
61 self.
keys.append(table.getCentroidFlagKey())
69 if self.
fluxLim is not None and source.getPsfFlux() < self.
fluxLim:
84 """!Select stars based on a reference catalog 86 @anchor CatalogStarSelectorTask_ 88 @section meas_astrom_catalogStarSelector_Contents Contents 90 - @ref meas_astrom_catalogStarSelector_Purpose 91 - @ref meas_astrom_catalogStarSelector_Initialize 92 - @ref meas_astrom_catalogStarSelector_IO 93 - @ref meas_astrom_catalogStarSelector_Config 94 - @ref meas_astrom_catalogStarSelector_Debug 96 @section meas_astrom_catalogStarSelector_Purpose Description 98 Select stars using a match list: select sources where the matching reference object is unresolved, 99 plus the source passes the following tests: 100 - no flag from config.badFlags is set 101 - psf flux >= config.fluxLim 102 - psf flux <= config.fluxMax (not checked if fluxMax == 0) 104 @section meas_astrom_catalogStarSelector_Initialize Task initialisation 106 @copydoc \_\_init\_\_ 108 @section meas_astrom_catalogStarSelector_IO Invoking the Task 110 Like all star selectors, the main method is `run`. Unlike most star selectors, 111 this one requires the `matches` argument (the `usesMatches` property is true). 113 @section meas_astrom_catalogStarSelector_Config Configuration parameters 115 See @ref CatalogStarSelectorConfig 117 @section meas_astrom_catalogStarSelector_Debug Debug variables 119 CatalogStarSelectorTask has a debug dictionary with the following keys: 122 <dd>bool; if True display debug information 124 <dd>bool; if True wait after displaying everything and wait for user input 127 For example, put something like: 131 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively 132 if name.endswith("catalogStarSelector"): 137 lsstDebug.Info = DebugInfo 139 into your `debug.py` file and run your task with the `--debug` flag. 141 ConfigClass = CatalogStarSelectorConfig
145 """!Return a list of PSF candidates that represent likely stars 147 A list of PSF candidates may be used by a PSF fitter to construct a PSF. 149 @param[in] exposure the exposure containing the sources 150 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 151 @param[in] matches a match vector as produced by meas_astrom; required 152 (defaults to None to match the StarSelector API and improve error handling) 154 @return an lsst.pipe.base.Struct containing: 155 - starCat catalog of selected stars (a subset of sourceCat) 159 display = debugInfo.display
160 pauseAtEnd = debugInfo.pauseAtEnd
163 raise RuntimeError(
"CatalogStarSelectorTask requires matches")
165 mi = exposure.getMaskedImage()
169 ds9.mtv(mi, frame=frame, title=
"PSF candidates")
171 isGoodSource =
CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
173 starCat = SourceCatalog(sourceCat.schema)
174 with ds9.Buffering():
175 for ref, source, d
in matches:
176 if not ref.get(
"resolved"):
177 if not isGoodSource(source):
178 symb, ctype =
"+", ds9.RED
180 starCat.append(source)
181 symb, ctype =
"+", ds9.GREEN
184 ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
185 size=4, frame=frame, ctype=ctype)
187 if display
and pauseAtEnd:
188 input(
"Continue? y[es] p[db] ")
195 starSelectorRegistry.register(
"catalog", CatalogStarSelectorTask)
def selectStars(self, exposure, sourceCat, matches=None)
Return a list of PSF candidates that represent likely stars.
def __call__(self, source)
def __init__(self, table, fluxLim, fluxMax, badFlags)
Select stars based on a reference catalog.