LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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