112 def selectSources(self, sourceCat, matches=None, exposure=None):
113 """Return a selection of sources for Kernel candidates.
114
115 Parameters
116 ----------
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.
124
125 Returns
126 -------
127 struct : `lsst.pipe.base.Struct`
128 The struct contains the following data:
129
130 - selected : `array` of `bool``
131 Boolean array of sources that were selected, same length as
132 sourceCat.
133 """
134 import lsstDebug
138
139 if matches is None:
140 raise RuntimeError("DiaCatalogSourceSelector requires matches")
141
142 mi = exposure.getMaskedImage()
143
144 if display and displayExposure:
145 disp = afwDisplay.Display(frame=lsstDebug.frame)
146 disp.mtv(mi, title="Kernel candidates")
147
148
149
150 isGoodSource = CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
151
152
153 selected = np.zeros(len(sourceCat), dtype=bool)
154
155 if display and displayExposure:
156 symbs = []
157 ctypes = []
158
159 doColorCut = True
160
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):
165 if not isGoodSource(source):
166 if display and displayExposure:
167 symbs.append("+")
168 ctypes.append(afwDisplay.RED)
169 else:
170 isStar = not ref.get("resolved")
171 isVar = not ref.get("photometric")
172 gMag = None
173 rMag = None
174 if doColorCut:
175 try:
176 gMag = -2.5 * np.log10(ref.get(gRefFluxField))
177 rMag = -2.5 * np.log10(ref.get(rRefFluxField))
178 except KeyError:
179 self.log.warning("Cannot cut on color info; fields 'g' and 'r' do not exist")
180 doColorCut = False
181 isRightColor = True
182 else:
183 isRightColor = (gMag-rMag) >= self.config.grMin and (gMag-rMag) <= self.config.grMax
184
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:
188 selected[i] = True
189 if display and displayExposure:
190 symbs.append("+")
191 ctypes.append(afwDisplay.GREEN)
192 elif display and displayExposure:
193 symbs.append("o")
194 ctypes.append(afwDisplay.BLUE)
195
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(),
201 size=4, ctype=ctype)
202
203 if display:
204 lsstDebug.frame += 1
205 if pauseAtEnd:
206 input("Continue? y[es] p[db] ")
207
208 return Struct(selected=selected)