30 """Set a flag for each source if it is in the innerBBox of a patch.
35 A sourceCatalog with pre-calculated centroids.
37 Information about a `SkyMap` `Patch`.
41 isPatchInner : array-like of `bool`
42 `
True`
for each source that has a centroid
43 in the inner region of a patch.
46 x = sources[
"slot_Centroid_x"]
47 y = sources[
"slot_Centroid_y"]
48 centroidFlag = sources[
"slot_Centroid_flag"]
52 innerFloatBBox =
Box2D(patchInfo.getInnerBBox())
53 inInner = innerFloatBBox.contains(x, y)
58 shrunkInnerFloatBBox =
Box2D(innerFloatBBox)
59 shrunkInnerFloatBBox.grow(-1)
60 inShrunkInner = shrunkInnerFloatBBox.contains(x, y)
63 isPatchInner = (centroidFlag & inShrunkInner) | (~centroidFlag & inInner)
68 """Set a flag for each source that the skyMap includes in tractInfo.
73 A sourceCatalog with pre-calculated centroids.
77 Sky tessellation object
81 isTractInner : array-like of `bool`
82 True if the skyMap.findTract method returns
83 the same tract
as tractInfo.
85 tractId = tractInfo.getId()
86 isTractInner = np.array([skyMap.findTract(s.getCoord()).getId() == tractId for s
in sources])
91 """Get a flag that marks pseudo sources.
93 Some categories of sources, for example sky objects,
94 are
not really detected sources
and should
not be considered primary
100 The catalog of sources
for which to identify
"pseudo"
102 pseudoFilterList : `list` of `str`
103 Names of filters which should never be primary
107 isPseudo : array-like of `bool`
108 True for each source that
is a pseudo source.
109 Note: to remove pseudo sources use `~isPseudo`.
112 isPseudo = np.zeros(len(sources), dtype=bool)
113 for filt
in pseudoFilterList:
115 pseudoFilterKey = schema.find(
"merge_peak_%s" % filt).getKey()
116 isPseudo |= sources[pseudoFilterKey]
118 log.warning(
"merge_peak is not set for pseudo-filter %s", filt)
123 """Get flags generated by the deblender
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.
141 A sourceCatalog that has already been deblended using
142 either meas_extensions_scarlet
or meas_deblender.
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"
163 nChildKey = "deblend_nChild"
164 nChild = sources[nChildKey]
165 parent = sources[
"parent"]
167 if "deblend_scarletFlux" in sources.schema:
172 nPeaks = sources[
"deblend_nPeaks"]
173 parentNChild = sources[
"deblend_parentNChild"]
178 fromBlend = parentNChild > 1
179 isIsolated = isLeaf & ((parent == 0) | parentNChild == 1)
180 isDeblendedSource = (fromBlend & isLeaf) | (isIsolated & (parent == 0))
181 isDeblendedModelSource = (parent != 0) & isLeaf
184 fromBlend = parent != 0
185 isIsolated = (nChild == 0) & (parent == 0)
186 isDeblendedSource = nChild == 0
187 isDeblendedModelSource =
None
188 return fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource
192 nChildKeyName =
Field(dtype=str, default=
"deprecated",
193 doc=
"Deprecated. This parameter is not used.")
194 pseudoFilterList =
ListField(dtype=str, default=[
'sky'],
195 doc=
"Names of filters which should never be primary")
199 """Add isPrimaryKey to a given schema.
205 isSingleFrame : `bool`
206 Flag specifying if task
is operating
with single frame imaging.
207 includeDeblend : `bool`
208 Include deblend information
in isPrimary
and
209 add isDeblendedSource field?
211 Keyword arguments passed to the task.
214 ConfigClass = SetPrimaryFlagsConfig
216 def __init__(self, schema, isSingleFrame=False, **kwargs):
217 Task.__init__(self, **kwargs)
222 primaryDoc = (
"true if source has no children and is in the inner region of a coadd patch "
223 "and is in the inner region of a coadd tract "
224 "and is not \"detected\" in a pseudo-filter (see config.pseudoFilterList)")
226 "detect_isPatchInner", type=
"Flag",
227 doc=
"true if source is in the inner region of a coadd patch",
230 "detect_isTractInner", type=
"Flag",
231 doc=
"true if source is in the inner region of a coadd tract",
234 primaryDoc =
"true if source has no children and is not a sky source"
236 "detect_isPrimary", type=
"Flag",
240 if "deblend_nChild" in schema.getNames():
243 "detect_isDeblendedSource", type=
"Flag",
244 doc=primaryDoc +
" and is either an unblended isolated source or a "
245 "deblended child from a parent with 'deblend_nChild' > 1")
247 "detect_fromBlend", type=
"Flag",
248 doc=
"This source is deblended from a parent with more than one child."
251 "detect_isIsolated", type=
"Flag",
252 doc=
"This source is not a part of a blend."
254 if "deblend_scarletFlux" in schema.getNames():
256 "detect_isDeblendedModelSource", type=
"Flag",
257 doc=primaryDoc +
" and is a deblended child")
261 def run(self, sources, skyMap=None, tractInfo=None, patchInfo=None):
262 """Set isPrimary and related flags on sources.
264 For coadded imaging, the `isPrimary` flag returns True when an object
265 has no children,
is in the inner region of a coadd patch,
is in the
266 inner region of a coadd trach,
and is not detected
in a pseudo-filter
267 (e.g., a sky_object).
268 For single frame imaging, the isPrimary flag returns
True when a
269 source has no children
and is not a sky source.
274 A sourceTable. Reads
in centroid fields
and an nChild field.
275 Writes
is-patch-inner,
is-tract-inner,
and is-primary flags.
277 Sky tessellation object
289 isPrimary = isTractInner & isPatchInner & ~isPseudo
296 if "sky_source" in sources.schema:
297 isSky = sources[
"sky_source"]
299 isSky = np.zeros(len(sources), dtype=bool)
304 fromBlend, isIsolated, isDeblendedSource, isDeblendedModelSource = result
310 isPrimary = isPrimary & isDeblendedSource
Defines the fields and offsets for a table.
A floating-point coordinate rectangle geometry.
def run(self, sources, skyMap=None, tractInfo=None, patchInfo=None)
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)