LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Classes | Functions
lsst.pipe.tasks.setPrimaryFlags Namespace Reference

Classes

class  SetPrimaryFlagsConfig
 
class  SetPrimaryFlagsTask
 

Functions

def getPatchInner (sources, patchInfo)
 
def getTractInner (sources, tractInfo, skyMap)
 
def getPseudoSources (sources, pseudoFilterList, schema, log)
 
def getDeblendPrimaryFlags (sources)
 

Function Documentation

◆ getDeblendPrimaryFlags()

def lsst.pipe.tasks.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 122 of file setPrimaryFlags.py.

122def getDeblendPrimaryFlags(sources):
123 """Get flags generated by the deblender
124
125 scarlet is different than meas_deblender in that it is not
126 (necessarily) flux conserving. For consistency in scarlet,
127 all of the parents with only a single child (isolated sources)
128 need to be deblended. This creates a question: which type
129 of isolated source should we make measurements on, the
130 undeblended "parent" or the deblended child?
131 For that reason we distinguish between a DeblendedSource,
132 which is a source that has no children and uses the
133 isolated parents, and a DeblendedModelSource, which uses
134 the scarlet models for both isolated and blended sources.
135 In the case of meas_deblender, DeblendedModelSource is
136 `None` because it is not contained in the output catalog.
137
138 Parameters
139 ----------
141 A sourceCatalog that has already been deblended using
142 either meas_extensions_scarlet or meas_deblender.
143
144 Returns
145 -------
146 fromBlend : array-like of `bool`
147 True for each source modeled by the deblender from a `Peak`
148 in a parent footprint that contained at least one other `Peak`.
149 While these models can be approximated as isolated,
150 and measurements are made on them as if that's the case,
151 we know deblending to introduce biases in the shape and centroid
152 of objects and it is important to know that the sources that these
153 models are based on are all bleneded in the true image.
154 isIsolated : array-like of `bool`
155 True for isolated sources, regardless of whether or not they
156 were modeled by the deblender.
157 isDeblendedSource : array-like of `bool`
158 True for each source that is a "DeblendedSource" as defined above.
159 isDeblendedModelSource : array-like of `bool`
160 True for each source that is a "DeblendedSourceModel"
161 as defined above.
162 """
163 nChildKey = "deblend_nChild"
164 nChild = sources[nChildKey]
165 parent = sources["parent"]
166
167 if "deblend_scarletFlux" in sources.schema:
168 # The number of peaks in the sources footprint.
169 # This (may be) different than nChild,
170 # the number of deblended sources in the catalog,
171 # because some peaks might have been culled during deblending.
172 nPeaks = sources["deblend_nPeaks"]
173 parentNChild = sources["deblend_parentNChild"]
174 # It is possible for a catalog to contain a hierarchy of sources,
175 # so we mark the leaves (end nodes of the hierarchy tree with no
176 # children).
177 isLeaf = nPeaks == 1
178 fromBlend = parentNChild > 1
179 isIsolated = isLeaf & ((parent == 0) | parentNChild == 1)
180 isDeblendedSource = (fromBlend & isLeaf) | (isIsolated & (parent == 0))
181 isDeblendedModelSource = (parent != 0) & isLeaf
182 else:
183 # Set the flags for meas_deblender
184 fromBlend = parent != 0
185 isIsolated = (nChild == 0) & (parent == 0)
186 isDeblendedSource = nChild == 0
187 isDeblendedModelSource = None
188 return fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource
189
190

◆ getPatchInner()

def lsst.pipe.tasks.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 29 of file setPrimaryFlags.py.

29def getPatchInner(sources, patchInfo):
30 """Set a flag for each source if it is in the innerBBox of a patch.
31
32 Parameters
33 ----------
35 A sourceCatalog with pre-calculated centroids.
36 patchInfo : `lsst.skymap.PatchInfo`
37 Information about a `SkyMap` `Patch`.
38
39 Returns
40 --------
41 isPatchInner : array-like of `bool`
42 `True` for each source that has a centroid
43 in the inner region of a patch.
44 """
45 # Extract the centroid position for all the sources
46 x = sources["slot_Centroid_x"]
47 y = sources["slot_Centroid_y"]
48 centroidFlag = sources["slot_Centroid_flag"]
49
50 # set inner flags for each source and set primary flags for
51 # sources with no children (or all sources if deblend info not available)
52 innerFloatBBox = Box2D(patchInfo.getInnerBBox())
53 inInner = innerFloatBBox.contains(x, y)
54
55 # When the centroider fails, we can still fall back to the peak,
56 # but we don't trust that quite as much -
57 # so we use a slightly smaller box for the patch comparison.
58 shrunkInnerFloatBBox = Box2D(innerFloatBBox)
59 shrunkInnerFloatBBox.grow(-1)
60 inShrunkInner = shrunkInnerFloatBBox.contains(x, y)
61
62 # Flag sources contained in the inner region of a patch
63 isPatchInner = (centroidFlag & inShrunkInner) | (~centroidFlag & inInner)
64 return isPatchInner
65
66
def getPatchInner(sources, patchInfo)

◆ getPseudoSources()

def lsst.pipe.tasks.setPrimaryFlags.getPseudoSources (   sources,
  pseudoFilterList,
  schema,
  log 
)
Get a flag that marks pseudo sources.

Some categories of sources, for example sky objects,
are not really detected sources and should not be considered primary
sources.

Parameters
----------
sources : `lsst.afw.table.SourceCatalog`
    The catalog of sources for which to identify "pseudo"
    (e.g. sky) objects.
pseudoFilterList : `list` of `str`
    Names of filters which should never be primary

Returns
-------
isPseudo : array-like of `bool`
    True for each source that is a pseudo source.
    Note: to remove pseudo sources use `~isPseudo`.

Definition at line 90 of file setPrimaryFlags.py.

90def getPseudoSources(sources, pseudoFilterList, schema, log):
91 """Get a flag that marks pseudo sources.
92
93 Some categories of sources, for example sky objects,
94 are not really detected sources and should not be considered primary
95 sources.
96
97 Parameters
98 ----------
100 The catalog of sources for which to identify "pseudo"
101 (e.g. sky) objects.
102 pseudoFilterList : `list` of `str`
103 Names of filters which should never be primary
104
105 Returns
106 -------
107 isPseudo : array-like of `bool`
108 True for each source that is a pseudo source.
109 Note: to remove pseudo sources use `~isPseudo`.
110 """
111 # Filter out sources that should never be primary
112 isPseudo = np.zeros(len(sources), dtype=bool)
113 for filt in pseudoFilterList:
114 try:
115 pseudoFilterKey = schema.find("merge_peak_%s" % filt).getKey()
116 isPseudo |= sources[pseudoFilterKey]
117 except KeyError:
118 log.warning("merge_peak is not set for pseudo-filter %s", filt)
119 return isPseudo
120
121
def getPseudoSources(sources, pseudoFilterList, schema, log)

◆ getTractInner()

def lsst.pipe.tasks.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 67 of file setPrimaryFlags.py.

67def getTractInner(sources, tractInfo, skyMap):
68 """Set a flag for each source that the skyMap includes in tractInfo.
69
70 Parameters
71 ----------
73 A sourceCatalog with pre-calculated centroids.
74 tractInfo : `lsst.skymap.TractInfo`
75 Tract object
76 skyMap : `lsst.skymap.BaseSkyMap`
77 Sky tessellation object
78
79 Returns
80 -------
81 isTractInner : array-like of `bool`
82 True if the skyMap.findTract method returns
83 the same tract as tractInfo.
84 """
85 tractId = tractInfo.getId()
86 isTractInner = np.array([skyMap.findTract(s.getCoord()).getId() == tractId for s in sources])
87 return isTractInner
88
89
def getTractInner(sources, tractInfo, skyMap)