25 from lsst.pipe.base
import Struct
28 import lsst.meas.algorithms
as measAlg
30 __all__ = [
"DiaCatalogSourceSelectorConfig",
"DiaCatalogSourceSelectorTask"]
35 fluxLim = pexConfig.Field(
36 doc=
"specify the minimum psfFlux for good Kernel Candidates",
39 check=
lambda x: x >= 0.0,
41 fluxMax = pexConfig.Field(
42 doc=
"specify the maximum psfFlux for good Kernel Candidates (ignored if == 0)",
45 check=
lambda x: x >= 0.0,
48 selectStar = pexConfig.Field(
49 doc=
"Select objects that are flagged as stars",
53 selectGalaxy = pexConfig.Field(
54 doc=
"Select objects that are flagged as galaxies",
58 includeVariable = pexConfig.Field(
59 doc=
"Include objects that are known to be variable",
63 grMin = pexConfig.Field(
64 doc=
"Minimum g-r color for selection (inclusive)",
68 grMax = pexConfig.Field(
69 doc=
"Maximum g-r color for selection (inclusive)",
75 measAlg.BaseStarSelectorConfig.setDefaults(self)
77 "base_PixelFlags_flag_edge",
78 "base_PixelFlags_flag_interpolatedCenter",
79 "base_PixelFlags_flag_saturatedCenter",
85 """A functor to check whether a source has any flags set that should cause it to be labeled bad.""" 87 def __init__(self, table, fluxLim, fluxMax, badFlags):
88 self.
keys = [table.getSchema().find(name).key
for name
in badFlags]
96 if self.
fluxLim is not None and source.getPsfInstFlux() < self.
fluxLim:
103 @pexConfig.registerConfigurable(
"diaCatalog", measAlg.sourceSelectorRegistry)
105 """A task that selects sources for Kernel candidates. 107 A naive star selector based on second moments. Use with caution. 113 DiaCatalogSourceSelectorTask has a debug dictionary with the following keys: 116 if True display debug information 117 displayExposure : `bool` 118 if True display exposure 120 if True wait after displaying everything and wait for user input 124 For example, put something like: 130 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively 131 if name.endswith("diaCatalogSourceSelector"): 136 lsstDebug.Info = DebugInfo 138 into your `debug.py` file and run your task with the `--debug` flag. 140 ConfigClass = DiaCatalogSourceSelectorConfig
144 """Return a selection of sources for Kernel candidates. 148 sourceCat : `lsst.afw.table.SourceCatalog` 149 Catalog of sources to select from. 150 This catalog must be contiguous in memory. 151 matches : `list` of `lsst.afw.table.ReferenceMatch` 152 A match vector as produced by meas_astrom. 153 exposure : `lsst.afw.image.Exposure` or None 154 The exposure the catalog was built from; used for debug display. 158 struct : `lsst.pipe.base.Struct` 159 The struct contains the following data: 161 - selected : `array` of `bool`` 162 Boolean array of sources that were selected, same length as 171 raise RuntimeError(
"DiaCatalogSourceSelector requires matches")
173 mi = exposure.getMaskedImage()
177 ds9.mtv(mi, title=
"Kernel candidates", frame=lsstDebug.frame)
181 isGoodSource =
CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
184 selected = np.zeros(len(sourceCat), dtype=bool)
186 if display
and displayExposure:
192 refSchema = matches[0][0].schema
193 rRefFluxField = measAlg.getRefFluxField(refSchema,
"r") 194 gRefFluxField = measAlg.getRefFluxField(refSchema, "g")
195 for i, (ref, source, d)
in enumerate(matches):
196 if not isGoodSource(source):
197 if display
and displayExposure:
199 ctypes.append(ds9.RED)
201 isStar =
not ref.get(
"resolved")
202 isVar =
not ref.get(
"photometric")
207 gMag = -2.5 * np.log10(ref.get(gRefFluxField))
208 rMag = -2.5 * np.log10(ref.get(rRefFluxField))
210 self.log.warn(
"Cannot cut on color info; fields 'g' and 'r' do not exist") 214 isRightColor = (gMag-rMag) >= self.config.grMin
and (gMag-rMag) <= self.config.grMax
216 isRightType = (self.config.selectStar
and isStar)
or (self.config.selectGalaxy
and not isStar)
217 isRightVar = (self.config.includeVariable)
or (self.config.includeVariable
is isVar)
218 if isRightType
and isRightVar
and isRightColor:
220 if display
and displayExposure:
222 ctypes.append(ds9.GREEN)
223 elif display
and displayExposure:
225 ctypes.append(ds9.BLUE)
227 if display
and displayExposure:
228 with ds9.Buffering():
229 for (ref, source, d), symb, ctype
in zip(matches, symbs, ctypes):
230 if display
and displayExposure:
231 ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
232 size=4, ctype=ctype, frame=lsstDebug.frame)
237 input(
"Continue? y[es] p[db] ")
239 return Struct(selected=selected)
def selectSources(self, sourceCat, matches=None, exposure=None)
def __init__(self, table, fluxLim, fluxMax, badFlags)
def __call__(self, source)