26 from lsst.pipe.base
import Struct
29 import lsst.meas.algorithms
as measAlg
31 __all__ = [
"DiaCatalogSourceSelectorConfig",
"DiaCatalogSourceSelectorTask"]
36 fluxLim = pexConfig.Field(
37 doc=
"specify the minimum psfFlux for good Kernel Candidates",
40 check=
lambda x: x >= 0.0,
42 fluxMax = pexConfig.Field(
43 doc=
"specify the maximum psfFlux for good Kernel Candidates (ignored if == 0)",
46 check=
lambda x: x >= 0.0,
49 selectStar = pexConfig.Field(
50 doc=
"Select objects that are flagged as stars",
54 selectGalaxy = pexConfig.Field(
55 doc=
"Select objects that are flagged as galaxies",
59 includeVariable = pexConfig.Field(
60 doc=
"Include objects that are known to be variable",
64 grMin = pexConfig.Field(
65 doc=
"Minimum g-r color for selection (inclusive)",
69 grMax = pexConfig.Field(
70 doc=
"Maximum g-r color for selection (inclusive)",
76 measAlg.BaseStarSelectorConfig.setDefaults(self)
78 "base_PixelFlags_flag_edge",
79 "base_PixelFlags_flag_interpolatedCenter",
80 "base_PixelFlags_flag_saturatedCenter",
86 """A functor to check whether a source has any flags set that should cause it to be labeled bad.""" 88 def __init__(self, table, fluxLim, fluxMax, badFlags):
89 self.
keys = [table.getSchema().find(name).key
for name
in badFlags]
97 if self.
fluxLim is not None and source.getPsfFlux() < self.
fluxLim:
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 """Select sources for Kernel candidates 172 @param[in] exposure the exposure containing the sources 173 @param[in] sourceCat catalog of sources that may be stars (an lsst.afw.table.SourceCatalog) 174 @param[in] matches a match vector as produced by meas_astrom; required 175 (defaults to None to match the StarSelector API and improve error handling) 177 @return an lsst.pipe.base.Struct containing: 178 - starCat a list of sources to be used as kernel candidates 186 raise RuntimeError(
"DiaCatalogSourceSelector requires matches")
188 mi = exposure.getMaskedImage()
192 ds9.mtv(mi, title=
"Kernel candidates", frame=lsstDebug.frame)
196 isGoodSource =
CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
201 starCat = SourceCatalog(sourceCat.schema)
203 if display
and displayExposure:
209 refSchema = matches[0][0].schema
210 rRefFluxField = measAlg.getRefFluxField(refSchema,
"r") 211 gRefFluxField = measAlg.getRefFluxField(refSchema, "g")
212 for ref, source, d
in matches:
213 if not isGoodSource(source):
214 if display
and displayExposure:
216 ctypes.append(ds9.RED)
218 isStar =
not ref.get(
"resolved")
219 isVar =
not ref.get(
"photometric")
224 gMag = -2.5 * np.log10(ref.get(gRefFluxField))
225 rMag = -2.5 * np.log10(ref.get(rRefFluxField))
227 self.log.warn(
"Cannot cut on color info; fields 'g' and 'r' do not exist") 231 isRightColor = (gMag-rMag) >= self.config.grMin
and (gMag-rMag) <= self.config.grMax
233 isRightType = (self.config.selectStar
and isStar)
or (self.config.selectGalaxy
and not isStar)
234 isRightVar = (self.config.includeVariable)
or (self.config.includeVariable
is isVar)
235 if isRightType
and isRightVar
and isRightColor:
236 starCat.append(source)
237 if display
and displayExposure:
239 ctypes.append(ds9.GREEN)
240 elif display
and displayExposure:
242 ctypes.append(ds9.BLUE)
244 if display
and displayExposure:
245 with ds9.Buffering():
246 for (ref, source, d), symb, ctype
in zip(matches, symbs, ctypes):
247 if display
and displayExposure:
248 ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
249 size=4, ctype=ctype, frame=lsstDebug.frame)
254 input(
"Continue? y[es] p[db] ")
261 measAlg.starSelectorRegistry.register(
"diacatalog", DiaCatalogSourceSelectorTask)
Select sources for Kernel candidates.
def selectStars(self, exposure, sourceCat, matches=None)
def __init__(self, table, fluxLim, fluxMax, badFlags)
def __call__(self, source)