LSST Applications g0d97872fb5+4fd969bb9d,g1653933729+34a971ddd9,g28da252d5a+072f89fe25,g2bbee38e9b+a99b0ab4cd,g2bc492864f+a99b0ab4cd,g2ca4be77d2+c0e3b27cd8,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+a99b0ab4cd,g35bb328faa+34a971ddd9,g3a166c0a6a+a99b0ab4cd,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+9ed5ed841a,g569e0e2b34+cb4faa46ad,g5a97de2502+520531a62c,g717e5f8c0f+29153700a5,g7ede599f99+367733290c,g80478fca09+17051a22cc,g82479be7b0+f2f1ea0a87,g858d7b2824+29153700a5,g8b782ad322+29153700a5,g8cd86fa7b1+05420e7f7d,g9125e01d80+34a971ddd9,ga5288a1d22+e7f674aaf3,gae0086650b+34a971ddd9,gae74b0b5c6+45ef5cdc51,gb58c049af0+ace264a4f2,gc28159a63d+a99b0ab4cd,gcf0d15dbbd+8051a81198,gda6a2b7d83+8051a81198,gdaeeff99f8+7774323b41,gdf4d240d4a+34a971ddd9,ge2409df99d+cb167bac99,ge33fd446bb+29153700a5,ge79ae78c31+a99b0ab4cd,gf0baf85859+890af219f9,gf5289d68f6+9faa5c5784,w.2024.36
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Attributes | List of all members
lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask Class Reference
Inheritance diagram for lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask:

Public Member Functions

 __init__ (self, schema, **kwargs)
 
 run (self, *exposure, catalog)
 

Public Attributes

 flux_name
 
 err_name
 
 flag_name
 
 schema
 

Static Public Attributes

 ConfigClass = NormalizedCalibrationFluxConfig
 

Protected Member Functions

 _measure_aperture_correction (self, exposure, catalog)
 

Static Protected Attributes

str _DefaultName = "normalizedCalibrationFlux"
 

Detailed Description

Task to measure the normalized calibration flux.

Parameters
----------
schema : `lsst.afw.table.Schema`
    Schema for the input table; will be modified in place.
**kwargs : `dict`
    Additional kwargs to pass to lsst.pipe.base.Task.__init__()

Definition at line 93 of file normalizedCalibrationFlux.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.__init__ ( self,
schema,
** kwargs )

Definition at line 106 of file normalizedCalibrationFlux.py.

106 def __init__(self, schema, **kwargs):
107 lsst.pipe.base.Task.__init__(self, **kwargs)
108
109 if self.config.do_measure_ap_corr:
110 self.makeSubtask(
111 "measure_ap_corr",
112 schema=schema,
113 namesToCorrect=[self.config.raw_calibflux_name],
114 )
115
116 name = self.config.normalized_calibflux_name
117 self.flux_name = name + "_instFlux"
118 if self.flux_name not in schema:
119 schema.addField(
120 self.flux_name,
121 type=float,
122 doc=f"Normalized calibration flux from {self.config.raw_calibflux_name}.",
123 )
124 self.err_name = name + "_instFluxErr"
125 if self.err_name not in schema:
126 schema.addField(
127 self.err_name,
128 type=float,
129 doc=f"Normalized calibration flux error from {self.config.raw_calibflux_name}.",
130 )
131 self.flag_name = name + "_flag"
132 if self.flag_name not in schema:
133 schema.addField(
134 self.flag_name,
135 type="Flag",
136 doc=f"Normalized calibration flux failure flag from {self.config.raw_calibflux_name}.",
137 )
138
139 if self.config.do_set_calib_slot:
140 schema.getAliasMap().set("slot_CalibFlux", name)
141
142 self.makeSubtask("fallback_source_selector")
143
144 self.schema = schema
145

Member Function Documentation

◆ _measure_aperture_correction()

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask._measure_aperture_correction ( self,
exposure,
catalog )
protected
Internal method to do the aperture correction measurement.

This measures the aperture correction with the regular task,
and if that fails does a fallback median estimate.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Exposure the normalized calibration flux is measured on.
    This is only used for the bounding box.
catalog : `lsst.afw.table.SourceCatalog`
    SourceCatalog containing measurements to be used to compute
    normalized calibration flux.

Returns
-------
ap_corr_field : `lsst.afw.math.ChebyshevBoundedField`
    Aperture correction field to normalize the calibration flux.
ap_corr_err_field : `lsst.afw.math.ChebyshevBoundedField`
    Aperture correction to adjust the calibration flux error.

Definition at line 237 of file normalizedCalibrationFlux.py.

237 def _measure_aperture_correction(self, exposure, catalog):
238 """Internal method to do the aperture correction measurement.
239
240 This measures the aperture correction with the regular task,
241 and if that fails does a fallback median estimate.
242
243 Parameters
244 ----------
245 exposure : `lsst.afw.image.Exposure`
246 Exposure the normalized calibration flux is measured on.
247 This is only used for the bounding box.
248 catalog : `lsst.afw.table.SourceCatalog`
249 SourceCatalog containing measurements to be used to compute
250 normalized calibration flux.
251
252 Returns
253 -------
254 ap_corr_field : `lsst.afw.math.ChebyshevBoundedField`
255 Aperture correction field to normalize the calibration flux.
256 ap_corr_err_field : `lsst.afw.math.ChebyshevBoundedField`
257 Aperture correction to adjust the calibration flux error.
258 """
259 raw_name = self.config.raw_calibflux_name
260
261 try:
262 ap_corr_map = self.measure_ap_corr.run(
263 exposure=exposure,
264 catalog=catalog,
265 ).apCorrMap
266
267 ap_corr_field = ap_corr_map.get(raw_name + "_instFlux")
268 except MeasureApCorrError:
269 self.log.warning("Failed to measure full aperture correction for %s", raw_name)
270
271 sel = self.fallback_source_selector.run(catalog, exposure=exposure).selected
272 sel &= (~catalog[self.config.raw_calibflux_name + "_flag"]
273 & ~catalog[self.config.measure_ap_corr.refFluxName + "_flag"])
274
275 n_sel = sel.sum()
276
277 if n_sel == 0:
278 # This is a fatal error.
279 raise RuntimeError("There are no valid stars to compute normalized calibration fluxes.")
280 self.log.info("Measuring normalized flux correction with %d stars from fallback selector.",
281 n_sel)
282
283 ratio = np.median(
284 catalog[self.config.measure_ap_corr.refFluxName + "_instFlux"][sel]
285 / catalog[self.config.raw_calibflux_name + "_instFlux"][sel]
286 )
287
288 ap_corr_field = ChebyshevBoundedField(
289 exposure.getBBox(),
290 np.array([[ratio]]),
291 )
292
293 if catalog.isContiguous():
294 catalog["apcorr_" + raw_name + "_used"] = sel
295 else:
296 for i, row in enumerate(catalog):
297 row["apcorr_" + raw_name + "_used"] = sel[i]
298
299 # We are always setting the error field to 0, because we do not
300 # have a good model for aperture correction uncertainties.
301 ap_corr_err_field = ChebyshevBoundedField(
302 exposure.getBBox(),
303 np.array([[0.0]]),
304 )
305
306 return ap_corr_field, ap_corr_err_field

◆ run()

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.run ( self,
* exposure,
catalog )
Measure the Normalized calibration flux.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Exposure the normalized calibration flux is measured on.
catalog : `lsst.afw.table.SourceCatalog`
    SourceCatalog containing measurements to be used to compute
    normalized calibration fluxes.  The catalog is modified in-place.

Returns
-------
Struct : `lsst.pipe.base.Struct`
    Contains the following:

    ``ap_corr_map``
        aperture correction map (`lsst.afw.image.ApCorrMap`)
        that contains two entries for the raw flux field:
        - flux field (e.g. config.{raw_calibflux_name}_instFlux): 2d model
        - flux sigma field (e.g. config.{raw_calibflux_name}_instFluxErr): 0 field

Definition at line 146 of file normalizedCalibrationFlux.py.

146 def run(self, *, exposure, catalog):
147 """Measure the Normalized calibration flux.
148
149 Parameters
150 ----------
151 exposure : `lsst.afw.image.Exposure`
152 Exposure the normalized calibration flux is measured on.
153 catalog : `lsst.afw.table.SourceCatalog`
154 SourceCatalog containing measurements to be used to compute
155 normalized calibration fluxes. The catalog is modified in-place.
156
157 Returns
158 -------
159 Struct : `lsst.pipe.base.Struct`
160 Contains the following:
161
162 ``ap_corr_map``
163 aperture correction map (`lsst.afw.image.ApCorrMap`)
164 that contains two entries for the raw flux field:
165 - flux field (e.g. config.{raw_calibflux_name}_instFlux): 2d model
166 - flux sigma field (e.g. config.{raw_calibflux_name}_instFluxErr): 0 field
167 """
168 self.log.info("Measuring normalized calibration flux from %s", self.config.raw_calibflux_name)
169
170 raw_name = self.config.raw_calibflux_name
171 raw_flux_name = raw_name + "_instFlux"
172 raw_fluxerr_name = raw_name + "_instFluxErr"
173 norm_name = self.config.normalized_calibflux_name
174
175 if self.config.do_measure_ap_corr:
176 ap_corr_field, ap_corr_err_field = self._measure_aperture_correction(exposure, catalog)
177 else:
178 use_identity = False
179 ap_corr_map = exposure.info.getApCorrMap()
180 if ap_corr_map is None:
181 self.log.warning(
182 "Exposure does not have a valid normalization map; using identity normalization.",
183 )
184 use_identity = True
185 else:
186 ap_corr_field = ap_corr_map.get(raw_flux_name)
187 ap_corr_err_field = ap_corr_map.get(raw_fluxerr_name)
188 if not ap_corr_field or not ap_corr_err_field:
189 self.log.warning(
190 "Exposure aperture correction map is missing %s/%s for normalization; "
191 "using identity normalization.",
192 raw_flux_name,
193 raw_fluxerr_name,
194 )
195 use_identity = True
196
197 if use_identity:
198 ap_corr_field = ChebyshevBoundedField(exposure.getBBox(), np.array([[1.0]]))
199 ap_corr_err_field = ChebyshevBoundedField(exposure.getBBox(), np.array([[0.0]]))
200
201 corrections = ap_corr_field.evaluate(
202 catalog["slot_Centroid_x"],
203 catalog["slot_Centroid_y"],
204 )
205
206 input_flux_name = raw_flux_name
207 input_fluxerr_name = raw_fluxerr_name
208 input_flag_name = raw_name + "_flag"
209 output_flux_name = norm_name + "_instFlux"
210 output_fluxerr_name = norm_name + "_instFluxErr"
211 output_flag_name = norm_name + "_flag"
212
213 if catalog.isContiguous():
214 catalog[output_flux_name] = catalog[input_flux_name] * corrections
215 catalog[output_fluxerr_name] = catalog[input_fluxerr_name] * corrections
216
217 output_flag = catalog[input_flag_name].copy()
218 output_flag[corrections <= 0.0] = True
219 catalog[output_flag_name] = output_flag
220 else:
221 # If the catalog is not contiguous we must go row-by-row.
222 for i, row in enumerate(catalog):
223 row[output_flux_name] = row[input_flux_name] * corrections[i]
224 row[output_fluxerr_name] = row[input_fluxerr_name] * corrections[i]
225
226 if row[input_flag_name] or corrections[i] <= 0.0:
227 row[output_flag_name] = True
228
229 ap_corr_map = ApCorrMap()
230 ap_corr_map[raw_flux_name] = ap_corr_field
231 ap_corr_map[raw_fluxerr_name] = ap_corr_err_field
232
233 return lsst.pipe.base.Struct(
234 ap_corr_map=ap_corr_map,
235 )
236

Member Data Documentation

◆ _DefaultName

str lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask._DefaultName = "normalizedCalibrationFlux"
staticprotected

Definition at line 104 of file normalizedCalibrationFlux.py.

◆ ConfigClass

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.ConfigClass = NormalizedCalibrationFluxConfig
static

Definition at line 103 of file normalizedCalibrationFlux.py.

◆ err_name

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.err_name

Definition at line 124 of file normalizedCalibrationFlux.py.

◆ flag_name

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.flag_name

Definition at line 131 of file normalizedCalibrationFlux.py.

◆ flux_name

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.flux_name

Definition at line 117 of file normalizedCalibrationFlux.py.

◆ schema

lsst.meas.algorithms.normalizedCalibrationFlux.NormalizedCalibrationFluxTask.schema

Definition at line 144 of file normalizedCalibrationFlux.py.


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