22__all__ = [
"SetPrimaryFlagsConfig",
"SetPrimaryFlagsTask"]
31 """Set a flag for each source if it is in the innerBBox of a patch.
36 A sourceCatalog with pre-calculated centroids.
38 Information about a `SkyMap` `Patch`.
42 isPatchInner : array-like of `bool`
43 `
True`
for each source that has a centroid
44 in the inner region of a patch.
47 x = sources[
"slot_Centroid_x"]
48 y = sources[
"slot_Centroid_y"]
49 centroidFlag = sources[
"slot_Centroid_flag"]
53 innerFloatBBox =
Box2D(patchInfo.getInnerBBox())
54 inInner = innerFloatBBox.contains(x, y)
59 shrunkInnerFloatBBox =
Box2D(innerFloatBBox)
60 shrunkInnerFloatBBox.grow(-1)
61 inShrunkInner = shrunkInnerFloatBBox.contains(x, y)
64 isPatchInner = (centroidFlag & inShrunkInner) | (~centroidFlag & inInner)
69 """Set a flag for each source that the skyMap includes in tractInfo.
74 A sourceCatalog with pre-calculated centroids.
78 Sky tessellation object
82 isTractInner : array-like of `bool`
83 True if the skyMap.findTract method returns
84 the same tract
as tractInfo.
86 tractId = tractInfo.getId()
87 isTractInner = np.array([skyMap.findTract(s.getCoord()).getId() == tractId for s
in sources])
92 """Get a flag that marks pseudo sources.
94 Some categories of sources, for example sky objects,
95 are
not really detected sources
and should
not be considered primary
101 The catalog of sources
for which to identify
"pseudo"
103 pseudoFilterList : `list` of `str`
104 Names of filters which should never be primary
108 isPseudo : array-like of `bool`
109 True for each source that
is a pseudo source.
110 Note: to remove pseudo sources use `~isPseudo`.
113 isPseudo = np.zeros(len(sources), dtype=bool)
114 for filt
in pseudoFilterList:
116 pseudoFilterKey = schema.find(
"merge_peak_%s" % filt).getKey()
117 isPseudo |= sources[pseudoFilterKey]
119 log.warning(
"merge_peak is not set for pseudo-filter %s", filt)
124 """Get flags generated by the deblender
126 scarlet is different than meas_deblender
in that it
is not
127 (necessarily) flux conserving. For consistency
in scarlet,
128 all of the parents
with only a single child (isolated sources)
129 need to be deblended. This creates a question: which type
130 of isolated source should we make measurements on, the
131 undeblended
"parent" or the deblended child?
132 For that reason we distinguish between a DeblendedSource,
133 which
is a source that has no children
and uses the
134 isolated parents,
and a DeblendedModelSource, which uses
135 the scarlet models
for both isolated
and blended sources.
136 In the case of meas_deblender, DeblendedModelSource
is
137 `
None` because it
is not contained
in the output catalog.
142 A sourceCatalog that has already been deblended using
143 either meas_extensions_scarlet
or meas_deblender.
147 fromBlend : array-like of `bool`
148 True for each source modeled by the deblender
from a `Peak`
149 in a parent footprint that contained at least one other `Peak`.
150 While these models can be approximated
as isolated,
151 and measurements are made on them
as if that
's the case,
152 we know deblending to introduce biases in the shape
and centroid
153 of objects
and it
is important to know that the sources that these
154 models are based on are all bleneded
in the true image.
155 isIsolated : array-like of `bool`
156 True for isolated sources, regardless of whether
or not they
157 were modeled by the deblender.
158 isDeblendedSource : array-like of `bool`
159 True for each source that
is a
"DeblendedSource" as defined above.
160 isDeblendedModelSource : array-like of `bool`
161 True for each source that
is a
"DeblendedSourceModel"
164 nChildKey = "deblend_nChild"
165 nChild = sources[nChildKey]
166 parent = sources[
"parent"]
168 if "deblend_scarletFlux" in sources.schema:
173 nPeaks = sources[
"deblend_nPeaks"]
174 parentNChild = sources[
"deblend_parentNChild"]
179 fromBlend = parentNChild > 1
180 isIsolated = isLeaf & ((parent == 0) | parentNChild == 1)
181 isDeblendedSource = (fromBlend & isLeaf) | (isIsolated & (parent == 0))
182 isDeblendedModelSource = (parent != 0) & isLeaf
185 fromBlend = parent != 0
186 isIsolated = (nChild == 0) & (parent == 0)
187 isDeblendedSource = nChild == 0
188 isDeblendedModelSource =
None
189 return fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource
193 nChildKeyName =
Field(dtype=str, default=
"deprecated",
194 doc=
"Deprecated. This parameter is not used.")
195 pseudoFilterList =
ListField(dtype=str, default=[
'sky'],
196 doc=
"Names of filters which should never be primary")
200 """Add isPrimaryKey to a given schema.
206 isSingleFrame : `bool`
207 Flag specifying if task
is operating
with single frame imaging.
208 includeDeblend : `bool`
209 Include deblend information
in isPrimary
and
210 add isDeblendedSource field?
212 Keyword arguments passed to the task.
215 ConfigClass = SetPrimaryFlagsConfig
217 def __init__(self, schema, isSingleFrame=False, **kwargs):
218 Task.__init__(self, **kwargs)
223 primaryDoc = (
"true if source has no children and is in the inner region of a coadd patch "
224 "and is in the inner region of a coadd tract "
225 "and is not \"detected\" in a pseudo-filter (see config.pseudoFilterList)")
227 "detect_isPatchInner", type=
"Flag",
228 doc=
"true if source is in the inner region of a coadd patch",
231 "detect_isTractInner", type=
"Flag",
232 doc=
"true if source is in the inner region of a coadd tract",
235 primaryDoc =
"true if source has no children and is not a sky source"
237 "detect_isPrimary", type=
"Flag",
241 if "deblend_nChild" in schema.getNames():
244 "detect_isDeblendedSource", type=
"Flag",
245 doc=primaryDoc +
" and is either an unblended isolated source or a "
246 "deblended child from a parent with 'deblend_nChild' > 1")
248 "detect_fromBlend", type=
"Flag",
249 doc=
"This source is deblended from a parent with more than one child."
252 "detect_isIsolated", type=
"Flag",
253 doc=
"This source is not a part of a blend."
255 if "deblend_scarletFlux" in schema.getNames():
257 "detect_isDeblendedModelSource", type=
"Flag",
258 doc=primaryDoc +
" and is a deblended child")
262 def run(self, sources, skyMap=None, tractInfo=None, patchInfo=None):
263 """Set isPrimary and related flags on sources.
265 For coadded imaging, the `isPrimary` flag returns True when an object
266 has no children,
is in the inner region of a coadd patch,
is in the
267 inner region of a coadd trach,
and is not detected
in a pseudo-filter
268 (e.g., a sky_object).
269 For single frame imaging, the isPrimary flag returns
True when a
270 source has no children
and is not a sky source.
275 A sourceTable. Reads
in centroid fields
and an nChild field.
276 Writes
is-patch-inner,
is-tract-inner,
and is-primary flags.
278 Sky tessellation object
290 isPrimary = isTractInner & isPatchInner & ~isPseudo
297 if "sky_source" in sources.schema:
298 isSky = sources[
"sky_source"]
300 isSky = np.zeros(len(sources), dtype=bool)
305 fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource = result
311 isPrimary = isPrimary & isDeblendedSource
Defines the fields and offsets for a table.
A floating-point coordinate rectangle geometry.
def __init__(self, schema, isSingleFrame=False, **kwargs)
def getDeblendPrimaryFlags(sources)
def getPatchInner(sources, patchInfo)
def getTractInner(sources, tractInfo, skyMap)
def getPseudoSources(sources, pseudoFilterList, schema, log)