113 """Return a selection of sources for Kernel candidates.
117 sourceCat : `lsst.afw.table.SourceCatalog`
118 Catalog of sources to select from.
119 This catalog must be contiguous in memory.
120 matches : `list` of `lsst.afw.table.ReferenceMatch`
121 A match vector as produced by meas_astrom.
122 exposure : `lsst.afw.image.Exposure` or None
123 The exposure the catalog was built from; used for debug display.
127 struct : `lsst.pipe.base.Struct`
128 The struct contains the following data:
130 - selected : `array` of `bool``
131 Boolean array of sources that were selected, same length as
140 raise RuntimeError(
"DiaCatalogSourceSelector requires matches")
142 mi = exposure.getMaskedImage()
144 if display
and displayExposure:
145 disp = afwDisplay.Display(frame=lsstDebug.frame)
146 disp.mtv(mi, title=
"Kernel candidates")
150 isGoodSource =
CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
153 selected = np.zeros(
len(sourceCat), dtype=bool)
155 if display
and displayExposure:
161 refSchema = matches[0][0].schema
162 rRefFluxField = measAlg.getRefFluxField(refSchema,
"r")
163 gRefFluxField = measAlg.getRefFluxField(refSchema,
"g")
164 for i, (ref, source, d)
in enumerate(matches):
166 if display
and displayExposure:
168 ctypes.append(afwDisplay.RED)
170 isStar =
not ref.get(
"resolved")
171 isVar =
not ref.get(
"photometric")
176 gMag = -2.5 * np.log10(ref.get(gRefFluxField))
177 rMag = -2.5 * np.log10(ref.get(rRefFluxField))
179 self.log.
warning(
"Cannot cut on color info; fields 'g' and 'r' do not exist")
183 isRightColor = (gMag-rMag) >= self.config.grMin
and (gMag-rMag) <= self.config.grMax
185 isRightType = (self.config.selectStar
and isStar)
or (self.config.selectGalaxy
and not isStar)
186 isRightVar = (self.config.includeVariable)
or (self.config.includeVariable
is isVar)
187 if isRightType
and isRightVar
and isRightColor:
189 if display
and displayExposure:
191 ctypes.append(afwDisplay.GREEN)
192 elif display
and displayExposure:
194 ctypes.append(afwDisplay.BLUE)
196 if display
and displayExposure:
197 disp = afwDisplay.Display(frame=lsstDebug.frame)
198 with disp.Buffering():
199 for (ref, source, d), symb, ctype
in zip(matches, symbs, ctypes):
200 disp.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
206 input(
"Continue? y[es] p[db] ")
208 return Struct(selected=selected)