LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions
lsst.meas.algorithms.setPrimaryFlags Namespace Reference

Classes

class  SetPrimaryFlagsConfig
 
class  SetPrimaryFlagsTask
 

Functions

 getPatchInner (sources, patchInfo)
 
 getTractInner (sources, tractInfo, skyMap)
 
 getDeblendPrimaryFlags (sources)
 

Function Documentation

◆ getDeblendPrimaryFlags()

lsst.meas.algorithms.setPrimaryFlags.getDeblendPrimaryFlags ( sources)
Get flags generated by the deblender.

scarlet is different than meas_deblender in that it is not
(necessarily) flux conserving. For consistency in scarlet,
all of the parents with only a single child (isolated sources)
need to be deblended. This creates a question: which type
of isolated source should we make measurements on, the
undeblended "parent" or the deblended child?
For that reason we distinguish between a DeblendedSource,
which is a source that has no children and uses the
isolated parents, and a DeblendedModelSource, which uses
the scarlet models for both isolated and blended sources.
In the case of meas_deblender, DeblendedModelSource is
`None` because it is not contained in the output catalog.

Parameters
----------
sources : `lsst.afw.table.SourceCatalog`
    A sourceCatalog that has already been deblended using
    either meas_extensions_scarlet or meas_deblender.

Returns
-------
fromBlend : array-like of `bool`
    True for each source modeled by the deblender from a `Peak`
    in a parent footprint that contained at least one other `Peak`.
    While these models can be approximated as isolated,
    and measurements are made on them as if that's the case,
    we know deblending to introduce biases in the shape and centroid
    of objects and it is important to know that the sources that these
    models are based on are all bleneded in the true image.
isIsolated : array-like of `bool`
    True for isolated sources, regardless of whether or not they
    were modeled by the deblender.
isDeblendedSource : array-like of `bool`
    True for each source that is a "DeblendedSource" as defined above.
isDeblendedModelSource : array-like of `bool`
    True for each source that is a "DeblendedSourceModel"
    as defined above.

Definition at line 247 of file setPrimaryFlags.py.

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 # The number of peaks in the sources footprint.
294 # This (may be) different than nChild,
295 # the number of deblended sources in the catalog,
296 # because some peaks might have been culled during deblending.
297 nPeaks = sources["deblend_nPeaks"]
298 parentNChild = sources["deblend_parentNChild"]
299 # It is possible for a catalog to contain a hierarchy of sources,
300 # so we mark the leaves (end nodes of the hierarchy tree with no
301 # children).
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 # Set the flags for meas_deblender
309 fromBlend = parent != 0
310 isIsolated = (nChild == 0) & (parent == 0)
311 isDeblendedSource = nChild == 0
312 isDeblendedModelSource = None
313 return fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource

◆ getPatchInner()

lsst.meas.algorithms.setPrimaryFlags.getPatchInner ( sources,
patchInfo )
Set a flag for each source if it is in the innerBBox of a patch.

Parameters
----------
sources : `lsst.afw.table.SourceCatalog`
    A sourceCatalog with pre-calculated centroids.
patchInfo : `lsst.skymap.PatchInfo`
    Information about a `SkyMap` `Patch`.

Returns
-------
isPatchInner : array-like of `bool`
    `True` for each source that has a centroid
    in the inner region of a patch.

Definition at line 186 of file setPrimaryFlags.py.

186def getPatchInner(sources, patchInfo):
187 """Set a flag for each source if it is in the innerBBox of a patch.
188
189 Parameters
190 ----------
191 sources : `lsst.afw.table.SourceCatalog`
192 A sourceCatalog with pre-calculated centroids.
193 patchInfo : `lsst.skymap.PatchInfo`
194 Information about a `SkyMap` `Patch`.
195
196 Returns
197 -------
198 isPatchInner : array-like of `bool`
199 `True` for each source that has a centroid
200 in the inner region of a patch.
201 """
202 # Extract the centroid position for all the sources
203 x = sources["slot_Centroid_x"]
204 y = sources["slot_Centroid_y"]
205 centroidFlag = sources["slot_Centroid_flag"]
206
207 # set inner flags for each source and set primary flags for
208 # sources with no children (or all sources if deblend info not available)
209 innerFloatBBox = Box2D(patchInfo.getInnerBBox())
210 inInner = innerFloatBBox.contains(x, y)
211
212 # When the centroider fails, we can still fall back to the peak,
213 # but we don't trust that quite as much -
214 # so we use a slightly smaller box for the patch comparison.
215 shrunkInnerFloatBBox = Box2D(innerFloatBBox)
216 shrunkInnerFloatBBox.grow(-1)
217 inShrunkInner = shrunkInnerFloatBBox.contains(x, y)
218
219 # Flag sources contained in the inner region of a patch
220 isPatchInner = (centroidFlag & inShrunkInner) | (~centroidFlag & inInner)
221 return isPatchInner
222
223

◆ getTractInner()

lsst.meas.algorithms.setPrimaryFlags.getTractInner ( sources,
tractInfo,
skyMap )
Set a flag for each source that the skyMap includes in tractInfo.

Parameters
----------
sources : `lsst.afw.table.SourceCatalog`
    A sourceCatalog with pre-calculated centroids.
tractInfo : `lsst.skymap.TractInfo`
    Tract object
skyMap : `lsst.skymap.BaseSkyMap`
    Sky tessellation object

Returns
-------
isTractInner : array-like of `bool`
    True if the skyMap.findTract method returns
    the same tract as tractInfo.

Definition at line 224 of file setPrimaryFlags.py.

224def getTractInner(sources, tractInfo, skyMap):
225 """Set a flag for each source that the skyMap includes in tractInfo.
226
227 Parameters
228 ----------
229 sources : `lsst.afw.table.SourceCatalog`
230 A sourceCatalog with pre-calculated centroids.
231 tractInfo : `lsst.skymap.TractInfo`
232 Tract object
233 skyMap : `lsst.skymap.BaseSkyMap`
234 Sky tessellation object
235
236 Returns
237 -------
238 isTractInner : array-like of `bool`
239 True if the skyMap.findTract method returns
240 the same tract as tractInfo.
241 """
242 tractId = tractInfo.getId()
243 isTractInner = np.array([skyMap.findTract(s.getCoord()).getId() == tractId for s in sources])
244 return isTractInner
245
246