247def getDeblendPrimaryFlags(sources):
248 """Get flags generated by the deblender.
249
250 scarlet is different than meas_deblender in that it is not
251 (necessarily) flux conserving. For consistency in scarlet,
252 all of the parents with only a single child (isolated sources)
253 need to be deblended. This creates a question: which type
254 of isolated source should we make measurements on, the
255 undeblended "parent" or the deblended child?
256 For that reason we distinguish between a DeblendedSource,
257 which is a source that has no children and uses the
258 isolated parents, and a DeblendedModelSource, which uses
259 the scarlet models for both isolated and blended sources.
260 In the case of meas_deblender, DeblendedModelSource is
261 `None` because it is not contained in the output catalog.
262
263 Parameters
264 ----------
265 sources : `lsst.afw.table.SourceCatalog`
266 A sourceCatalog that has already been deblended using
267 either meas_extensions_scarlet or meas_deblender.
268
269 Returns
270 -------
271 fromBlend : array-like of `bool`
272 True for each source modeled by the deblender from a `Peak`
273 in a parent footprint that contained at least one other `Peak`.
274 While these models can be approximated as isolated,
275 and measurements are made on them as if that's the case,
276 we know deblending to introduce biases in the shape and centroid
277 of objects and it is important to know that the sources that these
278 models are based on are all bleneded in the true image.
279 isIsolated : array-like of `bool`
280 True for isolated sources, regardless of whether or not they
281 were modeled by the deblender.
282 isDeblendedSource : array-like of `bool`
283 True for each source that is a "DeblendedSource" as defined above.
284 isDeblendedModelSource : array-like of `bool`
285 True for each source that is a "DeblendedSourceModel"
286 as defined above.
287 """
288 nChildKey = "deblend_nChild"
289 nChild = sources[nChildKey]
290 parent = sources["parent"]
291
292 if "deblend_scarletFlux" in sources.schema:
293
294
295
296
297 nPeaks = sources["deblend_nPeaks"]
298 parentNChild = sources["deblend_parentNChild"]
299
300
301
302 isLeaf = nPeaks == 1
303 fromBlend = parentNChild > 1
304 isIsolated = isLeaf & ((parent == 0) | parentNChild == 1)
305 isDeblendedSource = (fromBlend & isLeaf) | (isIsolated & (parent == 0))
306 isDeblendedModelSource = (parent != 0) & isLeaf
307 else:
308
309 fromBlend = parent != 0
310 isIsolated = (nChild == 0) & (parent == 0)
311 isDeblendedSource = nChild == 0
312 isDeblendedModelSource = None
313 return fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource