LSST Applications g0265f82a02+d6b5cd48b5,g02d81e74bb+80768bd682,g04242d3e92+8eaa23c173,g06b2ea86fd+734f9505a2,g2079a07aa2+14824f138e,g212a7c68fe+5f4fc2ea00,g2305ad1205+293ab1327e,g2bbee38e9b+d6b5cd48b5,g337abbeb29+d6b5cd48b5,g3ddfee87b4+8eaa23c173,g487adcacf7+abec5a19c5,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+97ef3b4495,g5a732f18d5+66d966b544,g5d7b63bc56+636c3c3fd8,g64a986408d+80768bd682,g858d7b2824+80768bd682,g8a8a8dda67+a6fc98d2e7,g99cad8db69+6282a5f541,g9ddcbc5298+d4bad12328,ga1e77700b3+246acaaf9c,ga8c6da7877+9e3c062e8e,gb0e22166c9+3863383f4c,gb6a65358fc+d6b5cd48b5,gba4ed39666+9664299f35,gbb8dafda3b+60f904e7bc,gc120e1dc64+1bf26d0180,gc28159a63d+d6b5cd48b5,gcf0d15dbbd+8eaa23c173,gd2a12a3803+f8351bc914,gdaeeff99f8+a38ce5ea23,ge79ae78c31+d6b5cd48b5,gee10cc3b42+a6fc98d2e7,gf1cff7945b+80768bd682,v24.1.5.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | List of all members
lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask Class Reference
Inheritance diagram for lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask:

Public Member Functions

 __init__ (self, schema, **kwargs)
 
 run (self, butler, coaddSources, ccdInputs, coaddWcs, visitCatalogs=None, wcsUpdates=None)
 

Static Public Member Functions

 getCcdInputs (coaddExposure)
 

Public Attributes

 schema
 

Static Public Attributes

 ConfigClass = PropagateVisitFlagsConfig
 

Protected Attributes

 _keys
 

Detailed Description

Task to propagate flags from single-frame measurements to coadd measurements.

Parameters
----------
schema : `lsst.afw.table.Schema`
    The input schema for the reference source catalog, used to initialize
    the output schema.
**kwargs
    Additional keyword arguments.

Notes
-----
We want to be able to set a flag for sources on the coadds using flags
that were determined from the individual visits.  A common example is sources
that were used for PSF determination, since we do not do any PSF determination
on the coadd but use the individual visits.  This requires matching the coadd
source catalog to each of the catalogs from the inputs (see
PropagateVisitFlagsConfig.matchRadius), and thresholding on the number of
times a source is flagged on the input catalog.

An important consideration in this is that the flagging of sources in the
individual visits can be somewhat stochastic, e.g., the same stars may not
always be used for PSF determination because the field of view moves slightly
between visits, or the seeing changed.  We there threshold on the relative
occurrence of the flag in the visits (see PropagateVisitFlagsConfig.flags).
Flagging a source that is always flagged in inputs corresponds to a threshold
of 1, while flagging a source that is flagged in any of the input corresponds
to a threshold of 0.  But neither of these extrema are really useful in
practise.

Setting the threshold too high means that sources that are not consistently
flagged (e.g., due to chip gaps) will not have the flag propagated.  Setting
that threshold too low means that random sources which are falsely flagged in
the inputs will start to dominate.  If in doubt, we suggest making this
threshold relatively low, but not zero (e.g., 0.1 to 0.2 or so).  The more
confidence in the quality of the flagging, the lower the threshold can be.
The relative occurrence accounts for the edge of the field-of-view of the
camera, but does not include chip gaps, bad or saturated pixels, etc.

Initialization

Beyond the usual Task initialization, PropagateVisitFlagsTask also requires
a schema for the catalog that is being constructed.

The 'run' method (described below) is the entry-point for operations.  The
'getCcdInputs' staticmethod is provided as a convenience for retrieving the
'ccdInputs' (CCD inputs table) from an Exposure.

.. code-block :: none

    # Requires:
    # * butler: data butler, for retrieving the CCD catalogs
    # * coaddCatalog: catalog of source measurements on the coadd (lsst.afw.table.SourceCatalog)
    # * coaddExposure: coadd (lsst.afw.image.Exposure)
    from lsst.pipe.tasks.propagateVisitFlags import PropagateVisitFlagsTask, PropagateVisitFlagsConfig
    config = PropagateVisitFlagsConfig()
    config.flags["calib_psf_used"] = 0.3 # Relative threshold for this flag
    config.matchRadius = 0.5 # Matching radius in arcsec
    task = PropagateVisitFlagsTask(coaddCatalog.schema, config=config)
    ccdInputs = task.getCcdInputs(coaddExposure)
    task.run(butler, coaddCatalog, ccdInputs, coaddExposure.getWcs())

Definition at line 48 of file propagateVisitFlags.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask.__init__ ( self,
schema,
** kwargs )

Definition at line 114 of file propagateVisitFlags.py.

114 def __init__(self, schema, **kwargs):
115 Task.__init__(self, **kwargs)
116 self.schema = schema
117 self._keys = dict((f, self.schema.addField(f, type="Flag", doc="Propagated from visits")) for
118 f in self.config.flags)
119

Member Function Documentation

◆ getCcdInputs()

lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask.getCcdInputs ( coaddExposure)
static
Convenience method to retrieve the CCD inputs table from a coadd exposure.

Parameters
----------
coaddExposure : `lsst.afw.image.Exposure`
    The exposure we need to retrieve the CCD inputs table from.

Returns
-------
ccdInputs : ``
    CCD inputs table from a coadd exposure.

Definition at line 121 of file propagateVisitFlags.py.

121 def getCcdInputs(coaddExposure):
122 """Convenience method to retrieve the CCD inputs table from a coadd exposure.
123
124 Parameters
125 ----------
126 coaddExposure : `lsst.afw.image.Exposure`
127 The exposure we need to retrieve the CCD inputs table from.
128
129 Returns
130 -------
131 ccdInputs : ``
132 CCD inputs table from a coadd exposure.
133 """
134 return coaddExposure.getInfo().getCoaddInputs().ccds
135

◆ run()

lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask.run ( self,
butler,
coaddSources,
ccdInputs,
coaddWcs,
visitCatalogs = None,
wcsUpdates = None )
Propagate flags from individual visit measurements to coadd.

This requires matching the coadd source catalog to each of the catalogs
from the inputs, and thresholding on the number of times a source is
flagged on the input catalog.  The threshold is made on the relative
occurrence of the flag in each source.  Flagging a source that is always
flagged in inputs corresponds to a threshold of 1, while flagging a
source that is flagged in any of the input corresponds to a threshold of
0.  But neither of these extrema are really useful in practise.

Setting the threshold too high means that sources that are not consistently
flagged (e.g., due to chip gaps) will not have the flag propagated.  Setting
that threshold too low means that random sources which are falsely flagged in
the inputs will start to dominate.  If in doubt, we suggest making this threshold
relatively low, but not zero (e.g., 0.1 to 0.2 or so).  The more confidence in
the quality of the flagging, the lower the threshold can be.

The relative occurrence accounts for the edge of the field-of-view of
the camera, but does not include chip gaps, bad or saturated pixels, etc.

Parameters
----------
butler : `Unknown`
    Data butler, for retrieving the input source catalogs.
coaddSources : `lsst.afw.image.SourceCatalog`
    Source catalog from the coadd.
ccdInputs : `lsst.afw.table.ExposureCatalog`
    Table of CCDs that contribute to the coadd.
coaddWcs : `lsst.afw.geom.SkyWcs`
    Wcs for coadd.
visitCatalogs : `list` of `lsst.afw.image.SourceCatalog`, optional
    List of loaded source catalogs for each input ccd in
    the coadd. If provided this is used instead of this
    method loading in the catalogs itself.
wcsUpdates : `list` of `lsst.afw.geom.SkyWcs`, optional
    If visitCatalogs is a list of ccd catalogs, this
    should be a list of updated wcs to apply.

Raises
------
ValueError
    Raised if any of the following occur:
    - A list of wcs updates for each catalog is not supplied in the wcsUpdates parameter
    and ccdInputs is a list of src catalogs.
    - The visitCatalogs and ccdInput parameters are both `None`.

Definition at line 136 of file propagateVisitFlags.py.

136 def run(self, butler, coaddSources, ccdInputs, coaddWcs, visitCatalogs=None, wcsUpdates=None):
137 """Propagate flags from individual visit measurements to coadd.
138
139 This requires matching the coadd source catalog to each of the catalogs
140 from the inputs, and thresholding on the number of times a source is
141 flagged on the input catalog. The threshold is made on the relative
142 occurrence of the flag in each source. Flagging a source that is always
143 flagged in inputs corresponds to a threshold of 1, while flagging a
144 source that is flagged in any of the input corresponds to a threshold of
145 0. But neither of these extrema are really useful in practise.
146
147 Setting the threshold too high means that sources that are not consistently
148 flagged (e.g., due to chip gaps) will not have the flag propagated. Setting
149 that threshold too low means that random sources which are falsely flagged in
150 the inputs will start to dominate. If in doubt, we suggest making this threshold
151 relatively low, but not zero (e.g., 0.1 to 0.2 or so). The more confidence in
152 the quality of the flagging, the lower the threshold can be.
153
154 The relative occurrence accounts for the edge of the field-of-view of
155 the camera, but does not include chip gaps, bad or saturated pixels, etc.
156
157 Parameters
158 ----------
159 butler : `Unknown`
160 Data butler, for retrieving the input source catalogs.
161 coaddSources : `lsst.afw.image.SourceCatalog`
162 Source catalog from the coadd.
163 ccdInputs : `lsst.afw.table.ExposureCatalog`
164 Table of CCDs that contribute to the coadd.
165 coaddWcs : `lsst.afw.geom.SkyWcs`
166 Wcs for coadd.
167 visitCatalogs : `list` of `lsst.afw.image.SourceCatalog`, optional
168 List of loaded source catalogs for each input ccd in
169 the coadd. If provided this is used instead of this
170 method loading in the catalogs itself.
171 wcsUpdates : `list` of `lsst.afw.geom.SkyWcs`, optional
172 If visitCatalogs is a list of ccd catalogs, this
173 should be a list of updated wcs to apply.
174
175 Raises
176 ------
177 ValueError
178 Raised if any of the following occur:
179 - A list of wcs updates for each catalog is not supplied in the wcsUpdates parameter
180 and ccdInputs is a list of src catalogs.
181 - The visitCatalogs and ccdInput parameters are both `None`.
182 """
183 if len(self.config.flags) == 0:
184 return
185
186 flags = self._keys.keys()
187 counts = dict((f, numpy.zeros(len(coaddSources), dtype=int)) for f in flags)
188 indices = numpy.array([s.getId() for s in coaddSources]) # Allowing for non-contiguous data
189 radius = self.config.matchRadius*geom.arcseconds
190
191 def processCcd(ccdSources, wcsUpdate):
192 for sourceRecord in ccdSources:
193 sourceRecord.updateCoord(wcsUpdate)
194 for flag in flags:
195 # We assume that the flags will be relatively rare, so it is more efficient to match
196 # against a subset of the input catalog for each flag than it is to match once against
197 # the entire catalog. It would be best to have built a kd-tree on coaddSources and
198 # keep reusing that for the matching, but we don't have a suitable implementation.
200 mc.findOnlyClosest = False
201 matches = afwTable.matchRaDec(coaddSources, ccdSources[ccdSources.get(flag)], radius, mc)
202 for m in matches:
203 index = (numpy.where(indices == m.first.getId()))[0][0]
204 counts[flag][index] += 1
205
206 if visitCatalogs is not None:
207 if wcsUpdates is None:
208 raise pexExceptions.ValueError("If ccdInputs is a list of src catalogs, a list of wcs"
209 " updates for each catalog must be supplied in the "
210 "wcsUpdates parameter")
211 for i, ccdSource in enumerate(visitCatalogs):
212 processCcd(ccdSource, wcsUpdates[i])
213 else:
214 if ccdInputs is None:
215 raise pexExceptions.ValueError("The visitCatalogs and ccdInput parameters can't both be None")
216 visitKey = ccdInputs.schema.find("visit").key
217 ccdKey = ccdInputs.schema.find("ccd").key
218
219 self.log.info("Propagating flags %s from inputs", flags)
220
221 # Accumulate counts of flags being set
222 for ccdRecord in ccdInputs:
223 v = ccdRecord.get(visitKey)
224 c = ccdRecord.get(ccdKey)
225 dataId = {"visit": int(v), self.config.ccdName: int(c)}
226 ccdSources = butler.get("src", dataId=dataId)
227 processCcd(ccdSources, ccdRecord.getWcs())
228
229 # Apply threshold
230 for f in flags:
231 key = self._keys[f]
232 for s, num in zip(coaddSources, counts[f]):
233 numOverlaps = len(ccdInputs.subsetContaining(s.getCentroid(), coaddWcs, True))
234 s.setFlag(key, bool(num > numOverlaps*self.config.flags[f]))
235 self.log.info("Propagated %d sources with flag %s", sum(s.get(key) for s in coaddSources), f)
Pass parameters to algorithms that match list of sources.
Definition Match.h:45
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, lsst::geom::Angle radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
Definition Match.cc:158

Member Data Documentation

◆ _keys

lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask._keys
protected

Definition at line 117 of file propagateVisitFlags.py.

◆ ConfigClass

lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask.ConfigClass = PropagateVisitFlagsConfig
static

Definition at line 112 of file propagateVisitFlags.py.

◆ schema

lsst.pipe.tasks.propagateVisitFlags.PropagateVisitFlagsTask.schema

Definition at line 116 of file propagateVisitFlags.py.


The documentation for this class was generated from the following file: