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.getPsfFlux() < self.
fluxLim:
110 @pexConfig.registerConfigurable(
"diaCatalog", measAlg.sourceSelectorRegistry)
112 """!Select sources for Kernel candidates 114 @anchor DiaCatalogSourceSelectorTask_ 116 @section ip_diffim_diaCatalogSourceSelector_Contents Contents 118 - @ref ip_diffim_diaCatalogSourceSelector_Purpose 119 - @ref ip_diffim_diaCatalogSourceSelector_Initialize 120 - @ref ip_diffim_diaCatalogSourceSelector_IO 121 - @ref ip_diffim_diaCatalogSourceSelector_Config 122 - @ref ip_diffim_diaCatalogSourceSelector_Debug 124 @section ip_diffim_diaCatalogSourceSelector_Purpose Description 126 A naive star selector based on second moments. Use with caution. 128 @section ip_diffim_diaCatalogSourceSelector_Initialize Task initialisation 130 @copydoc \_\_init\_\_ 132 @section ip_diffim_diaCatalogSourceSelector_IO Invoking the Task 134 Like all star selectors, the main method is `run`. 136 @section ip_diffim_diaCatalogSourceSelector_Config Configuration parameters 138 See @ref DiaCatalogSourceSelectorConfig 140 @section ip_diffim_diaCatalogSourceSelector_Debug Debug variables 142 DiaCatalogSourceSelectorTask has a debug dictionary with the following keys: 145 <dd>bool; if True display debug information 147 <dd>bool; if True display exposure 149 <dd>bool; if True wait after displaying everything and wait for user input 152 For example, put something like: 156 di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively 157 if name.endswith("catalogStarSelector"): 162 lsstDebug.Info = DebugInfo 164 into your `debug.py` file and run your task with the `--debug` flag. 166 ConfigClass = DiaCatalogSourceSelectorConfig
170 """Return a selection of sources for Kernel candidates. 174 sourceCat : `lsst.afw.table.SourceCatalog` 175 Catalog of sources to select from. 176 This catalog must be contiguous in memory. 177 matches : `list` of `lsst.afw.table.ReferenceMatch` 178 A match vector as produced by meas_astrom. 179 exposure : `lsst.afw.image.Exposure` or None 180 The exposure the catalog was built from; used for debug display. 184 struct : `lsst.pipe.base.Struct` 185 The struct contains the following data: 187 - selected : `array` of `bool`` 188 Boolean array of sources that were selected, same length as 197 raise RuntimeError(
"DiaCatalogSourceSelector requires matches")
199 mi = exposure.getMaskedImage()
203 ds9.mtv(mi, title=
"Kernel candidates", frame=lsstDebug.frame)
207 isGoodSource =
CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
210 selected = np.zeros(len(sourceCat), dtype=bool)
212 if display
and displayExposure:
218 refSchema = matches[0][0].schema
219 rRefFluxField = measAlg.getRefFluxField(refSchema,
"r") 220 gRefFluxField = measAlg.getRefFluxField(refSchema, "g")
221 for i, (ref, source, d)
in enumerate(matches):
222 if not isGoodSource(source):
223 if display
and displayExposure:
225 ctypes.append(ds9.RED)
227 isStar =
not ref.get(
"resolved")
228 isVar =
not ref.get(
"photometric")
233 gMag = -2.5 * np.log10(ref.get(gRefFluxField))
234 rMag = -2.5 * np.log10(ref.get(rRefFluxField))
236 self.log.warn(
"Cannot cut on color info; fields 'g' and 'r' do not exist") 240 isRightColor = (gMag-rMag) >= self.config.grMin
and (gMag-rMag) <= self.config.grMax
242 isRightType = (self.config.selectStar
and isStar)
or (self.config.selectGalaxy
and not isStar)
243 isRightVar = (self.config.includeVariable)
or (self.config.includeVariable
is isVar)
244 if isRightType
and isRightVar
and isRightColor:
246 if display
and displayExposure:
248 ctypes.append(ds9.GREEN)
249 elif display
and displayExposure:
251 ctypes.append(ds9.BLUE)
253 if display
and displayExposure:
254 with ds9.Buffering():
255 for (ref, source, d), symb, ctype
in zip(matches, symbs, ctypes):
256 if display
and displayExposure:
257 ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
258 size=4, ctype=ctype, frame=lsstDebug.frame)
263 input(
"Continue? y[es] p[db] ")
265 return Struct(selected=selected)
Select sources for Kernel candidates.
def selectSources(self, sourceCat, matches=None, exposure=None)
def __init__(self, table, fluxLim, fluxMax, badFlags)
def __call__(self, source)