LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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.

122 def 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  ----------
140  sources : `lsst.afw.table.SourceCatalog`
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.

29 def getPatchInner(sources, patchInfo):
30  """Set a flag for each source if it is in the innerBBox of a patch.
31 
32  Parameters
33  ----------
34  sources : `lsst.afw.table.SourceCatalog`
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.

90 def 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  ----------
99  sources : `lsst.afw.table.SourceCatalog`
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.

67 def getTractInner(sources, tractInfo, skyMap):
68  """Set a flag for each source that the skyMap includes in tractInfo.
69 
70  Parameters
71  ----------
72  sources : `lsst.afw.table.SourceCatalog`
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)