LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask Class Reference
Inheritance diagram for lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask:

Public Member Functions

 __init__ (self, schema, **kwargs)
 
 run (self, coadd_object_cat, ccd_inputs, source_table_handle_dict=None, finalized_source_table_handle_dict=None)
 

Public Attributes

 schema
 

Static Public Attributes

 ConfigClass = PropagateSourceFlagsConfig
 

Protected Member Functions

 _get_source_table_column_names (self, x_column, y_column, flags)
 

Detailed Description

Task to propagate source flags to coadd objects.

Flagged sources may come from a mix of two different types of source catalogs.
The source_table catalogs from ``CalibrateTask`` contain flags for the first
round of astromety/photometry/psf fits.
The finalized_source_table catalogs from ``FinalizeCalibrationTask`` contain
flags from the second round of psf fitting.

Definition at line 95 of file propagateSourceFlags.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask.__init__ ( self,
schema,
** kwargs )

Definition at line 106 of file propagateSourceFlags.py.

106 def __init__(self, schema, **kwargs):
107 pipeBase.Task.__init__(self, **kwargs)
108
109 self.schema = schema
110 for f in self.config.source_flags:
111 self.schema.addField(f, type="Flag", doc="Propagated from sources")
112 for f in self.config.finalized_source_flags:
113 self.schema.addField(f, type="Flag", doc="Propagated from finalized sources")
114

Member Function Documentation

◆ _get_source_table_column_names()

lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask._get_source_table_column_names ( self,
x_column,
y_column,
flags )
protected
Get the list of source table columns from the config.

Parameters
----------
x_column : `str`
    Name of column with x centroid.
y_column : `str`
    Name of column with y centroid.
flags : `list` [`str`]
    List of flags to retrieve.

Returns
-------
columns : [`list`] [`str`]
    Columns to read.

Definition at line 243 of file propagateSourceFlags.py.

243 def _get_source_table_column_names(self, x_column, y_column, flags):
244 """Get the list of source table columns from the config.
245
246 Parameters
247 ----------
248 x_column : `str`
249 Name of column with x centroid.
250 y_column : `str`
251 Name of column with y centroid.
252 flags : `list` [`str`]
253 List of flags to retrieve.
254
255 Returns
256 -------
257 columns : [`list`] [`str`]
258 Columns to read.
259 """
260 columns = ["visit", "detector",
261 x_column, y_column]
262 columns.extend(flags)
263
264 return columns

◆ run()

lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask.run ( self,
coadd_object_cat,
ccd_inputs,
source_table_handle_dict = None,
finalized_source_table_handle_dict = None )
Propagate flags from single-frame sources to coadd objects.

Flags are only propagated if a configurable percentage of the sources
are matched to the coadd objects.  This task will match both "plain"
source flags and "finalized" source flags.

Parameters
----------
coadd_object_cat : `lsst.afw.table.SourceCatalog`
    Table of coadd objects.
ccd_inputs : `lsst.afw.table.ExposureCatalog`
    Table of single-frame inputs to coadd.
source_table_handle_dict : `dict` [`int`: `lsst.daf.butler.DeferredDatasetHandle`]
    Dict for sourceTable_visit handles (key is visit).  May be None if
    ``config.source_flags`` has no entries.
finalized_source_table_handle_dict : `dict` [`int`:
                                             `lsst.daf.butler.DeferredDatasetHandle`]
    Dict for finalized_src_table handles (key is visit).  May be None if
    ``config.finalized_source_flags`` has no entries.

Definition at line 115 of file propagateSourceFlags.py.

116 source_table_handle_dict=None, finalized_source_table_handle_dict=None):
117 """Propagate flags from single-frame sources to coadd objects.
118
119 Flags are only propagated if a configurable percentage of the sources
120 are matched to the coadd objects. This task will match both "plain"
121 source flags and "finalized" source flags.
122
123 Parameters
124 ----------
125 coadd_object_cat : `lsst.afw.table.SourceCatalog`
126 Table of coadd objects.
127 ccd_inputs : `lsst.afw.table.ExposureCatalog`
128 Table of single-frame inputs to coadd.
129 source_table_handle_dict : `dict` [`int`: `lsst.daf.butler.DeferredDatasetHandle`]
130 Dict for sourceTable_visit handles (key is visit). May be None if
131 ``config.source_flags`` has no entries.
132 finalized_source_table_handle_dict : `dict` [`int`:
133 `lsst.daf.butler.DeferredDatasetHandle`]
134 Dict for finalized_src_table handles (key is visit). May be None if
135 ``config.finalized_source_flags`` has no entries.
136 """
137 if len(self.config.source_flags) == 0 and len(self.config.finalized_source_flags) == 0:
138 return
139
140 source_columns = self._get_source_table_column_names(
141 self.config.x_column,
142 self.config.y_column,
143 self.config.source_flags.keys()
144 )
145 finalized_columns = self._get_source_table_column_names(
146 self.config.finalized_x_column,
147 self.config.finalized_y_column,
148 self.config.finalized_source_flags.keys(),
149 )
150
151 # We need the number of overlaps of individual detectors for each coadd source.
152 # The following code is slow and inefficient, but can be made simpler in the future
153 # case of cell-based coadds and so optimizing usage in afw is not a priority.
154 num_overlaps = np.zeros(len(coadd_object_cat), dtype=np.int32)
155 for i, obj in enumerate(coadd_object_cat):
156 num_overlaps[i] = len(ccd_inputs.subsetContaining(obj.getCoord(), True))
157
158 visits = np.unique(ccd_inputs["visit"])
159
160 matcher = Matcher(np.rad2deg(coadd_object_cat["coord_ra"]),
161 np.rad2deg(coadd_object_cat["coord_dec"]))
162
163 source_flag_counts = {f: np.zeros(len(coadd_object_cat), dtype=np.int32)
164 for f in self.config.source_flags}
165 finalized_source_flag_counts = {f: np.zeros(len(coadd_object_cat), dtype=np.int32)
166 for f in self.config.finalized_source_flags}
167
168 handles_list = [source_table_handle_dict, finalized_source_table_handle_dict]
169 columns_list = [source_columns, finalized_columns]
170 counts_list = [source_flag_counts, finalized_source_flag_counts]
171 x_column_list = [self.config.x_column, self.config.finalized_x_column]
172 y_column_list = [self.config.y_column, self.config.finalized_y_column]
173 name_list = ["sources", "finalized_sources"]
174
175 for handle_dict, columns, flag_counts, x_col, y_col, name in zip(handles_list,
176 columns_list,
177 counts_list,
178 x_column_list,
179 y_column_list,
180 name_list):
181 if handle_dict is not None and len(columns) > 0:
182 for visit in visits:
183 if visit not in handle_dict:
184 self.log.info("Visit %d not in input handle dict for %s", visit, name)
185 continue
186 handle = handle_dict[visit]
187 df = handle.get(parameters={"columns": columns})
188
189 # Loop over all ccd_inputs rows for this visit.
190 for row in ccd_inputs[ccd_inputs["visit"] == visit]:
191 detector = row["ccd"]
192 wcs = row.getWcs()
193 if wcs is None:
194 self.log.info("No WCS for visit %d detector %d, so can't match sources to "
195 "propagate flags. Skipping...", visit, detector)
196 continue
197
198 df_det = df[df["detector"] == detector]
199
200 if len(df_det) == 0:
201 continue
202
203 ra, dec = wcs.pixelToSkyArray(df_det[x_col].values,
204 df_det[y_col].values,
205 degrees=True)
206
207 try:
208 # The output from the matcher links
209 # coadd_object_cat[i1] <-> df_det[i2]
210 # All objects within the match radius are matched.
211 idx, i1, i2, d = matcher.query_radius(
212 ra,
213 dec,
214 self.config.match_radius/3600.,
215 return_indices=True
216 )
217 except IndexError:
218 # No matches. Workaround a bug in older version of smatch.
219 self.log.info("Visit %d has no overlapping objects", visit)
220 continue
221
222 if len(i1) == 0:
223 # No matches (usually because detector does not overlap patch).
224 self.log.info("Visit %d has no overlapping objects", visit)
225 continue
226
227 for flag in flag_counts:
228 flag_values = df_det[flag].values
229 flag_counts[flag][i1] += flag_values[i2].astype(np.int32)
230
231 for flag in source_flag_counts:
232 thresh = num_overlaps*self.config.source_flags[flag]
233 object_flag = (source_flag_counts[flag] > thresh)
234 coadd_object_cat[flag] = object_flag
235 self.log.info("Propagated %d sources with flag %s", object_flag.sum(), flag)
236
237 for flag in finalized_source_flag_counts:
238 thresh = num_overlaps*self.config.finalized_source_flags[flag]
239 object_flag = (finalized_source_flag_counts[flag] > thresh)
240 coadd_object_cat[flag] = object_flag
241 self.log.info("Propagated %d finalized sources with flag %s", object_flag.sum(), flag)
242

Member Data Documentation

◆ ConfigClass

lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask.ConfigClass = PropagateSourceFlagsConfig
static

Definition at line 104 of file propagateSourceFlags.py.

◆ schema

lsst.pipe.tasks.propagateSourceFlags.PropagateSourceFlagsTask.schema

Definition at line 109 of file propagateSourceFlags.py.


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