LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
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