22 from __future__
import absolute_import, division, print_function
24 __all__ = [
"CatalogStarSelectorConfig",
"CatalogStarSelectorTask"]
26 from builtins
import input
27 from builtins
import object
29 from lsst.afw.table
import SourceCatalog
30 from lsst.meas.algorithms
import BaseStarSelectorTask, starSelectorRegistry
31 from lsst.pipe.base
import Struct
32 import lsst.pex.config
as pexConfig
33 import lsst.afw.display.ds9
as ds9
37 fluxLim = pexConfig.RangeField(
38 doc=
"specify the minimum psfFlux for good Psf Candidates",
43 fluxMax = pexConfig.RangeField(
44 doc=
"specify the maximum psfFlux for good Psf Candidates (ignored if == 0)",
51 BaseStarSelectorTask.ConfigClass.setDefaults(self)
53 "base_PixelFlags_flag_edge",
54 "base_PixelFlags_flag_interpolatedCenter",
55 "base_PixelFlags_flag_saturatedCenter",
60 """A functor to check whether a source has any flags set that should cause it to be labeled bad.""" 62 def __init__(self, table, fluxLim, fluxMax, badFlags):
63 self.
keys = [table.getSchema().find(name).key
for name
in badFlags]
64 self.
keys.append(table.getCentroidFlagKey())
72 if self.
fluxLim is not None and source.getPsfFlux() < self.
fluxLim:
87 """!Select stars based on a reference catalog 89 @anchor CatalogStarSelectorTask_ 91 @section meas_astrom_catalogStarSelector_Contents Contents 93 - @ref meas_astrom_catalogStarSelector_Purpose 94 - @ref meas_astrom_catalogStarSelector_Initialize 95 - @ref meas_astrom_catalogStarSelector_IO 96 - @ref meas_astrom_catalogStarSelector_Config 97 - @ref meas_astrom_catalogStarSelector_Debug 99 @section meas_astrom_catalogStarSelector_Purpose Description 101 Select stars using a match list: select sources where the matching reference object is unresolved, 102 plus the source passes the following tests: 103 - no flag from config.badFlags is set 104 - psf flux >= config.fluxLim 105 - psf flux <= config.fluxMax (not checked if fluxMax == 0) 107 @section meas_astrom_catalogStarSelector_Initialize Task initialisation 109 @copydoc \_\_init\_\_ 111 @section meas_astrom_catalogStarSelector_IO Invoking the Task 113 Like all star selectors, the main method is `run`. Unlike most star selectors, 114 this one requires the `matches` argument (the `usesMatches` property is true). 116 @section meas_astrom_catalogStarSelector_Config Configuration parameters 118 See @ref CatalogStarSelectorConfig 120 @section meas_astrom_catalogStarSelector_Debug Debug variables 122 CatalogStarSelectorTask has a debug dictionary with the following keys: 125 <dd>bool; if True display debug information 127 <dd>bool; if True wait after displaying everything and wait for user input 130 For example, put something like: 134 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively 135 if name.endswith("catalogStarSelector"): 140 lsstDebug.Info = DebugInfo 142 into your `debug.py` file and run your task with the `--debug` flag. 144 ConfigClass = CatalogStarSelectorConfig
148 """!Return a list of PSF candidates that represent likely stars 150 A list of PSF candidates may be used by a PSF fitter to construct a PSF. 152 @param[in] exposure the exposure containing the sources 153 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 154 @param[in] matches a match vector as produced by meas_astrom; required 155 (defaults to None to match the StarSelector API and improve error handling) 157 @return an lsst.pipe.base.Struct containing: 158 - starCat catalog of selected stars (a subset of sourceCat) 161 debugInfo = lsstDebug.Info(__name__)
162 display = debugInfo.display
163 pauseAtEnd = debugInfo.pauseAtEnd
166 raise RuntimeError(
"CatalogStarSelectorTask requires matches")
168 mi = exposure.getMaskedImage()
172 ds9.mtv(mi, frame=frame, title=
"PSF candidates")
174 isGoodSource =
CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
176 starCat = SourceCatalog(sourceCat.schema)
177 with ds9.Buffering():
178 for ref, source, d
in matches:
179 if not ref.get(
"resolved"):
180 if not isGoodSource(source):
181 symb, ctype =
"+", ds9.RED
183 starCat.append(source)
184 symb, ctype =
"+", ds9.GREEN
187 ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
188 size=4, frame=frame, ctype=ctype)
190 if display
and pauseAtEnd:
191 input(
"Continue? y[es] p[db] ")
198 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.