97 def __init__(self, *, dataIds, refCats, name, **kwargs):
98 pipeBase.Task.__init__(self, **kwargs)
99 refConfig = self.config.refObjLoader
106 if self.config.doReferenceSelection:
107 self.makeSubtask(
'referenceSelector')
113 bboxToSpherePadding=None):
114 """Get a multi-band reference catalog by specifying a bounding box and WCS.
116 The catalog will be in `numpy.ndarray`, with positions proper-motion
117 corrected to "epoch" (if specified, and if the reference catalog has
118 proper motions); sources cut on a reference selector (if
119 "config.doReferenceSelection = True"); and color-terms applied (if
120 "config.doApplyColorTerms = True").
122 The format of the reference catalog will be of the format:
124 dtype = [('ra', 'np.float64'),
125 ('dec', 'np.float64'),
126 ('refMag', 'np.float32', (len(filterList), )),
127 ('refMagErr', 'np.float32', (len(filterList), ))]
129 Reference magnitudes (AB) and errors will be NaN for non-detections
134 bbox : `lsst.geom.Box2I`
135 Box which bounds a region in pixel space.
136 wcs : `lsst.afw.geom.SkyWcs`
137 Wcs object defining the pixel to sky (and reverse) transform for
139 filterList : `List` [ `str` ]
140 List of camera physicalFilter names to retrieve magnitudes.
141 epoch : `astropy.time.Time`, optional
142 Epoch to which to correct proper motion and parallax
143 (if available), or `None` to not apply such corrections.
144 bboxToSpherePadding : `int`, optional
145 Padding to account for translating a set of corners into a
146 spherical (convex) boundary that is certain to encompass the
147 entire area covered by the bbox.
151 refCat : `numpy.ndarray`
156 center = wcs.pixelToSky(bbox.getCenter())
161 bboxToSpherePadding=bboxToSpherePadding)
163 if not skyBox.refCat.isContiguous():
164 refCat = skyBox.refCat.copy(deep=
True)
166 refCat = skyBox.refCat
171 catalogFormat='numpy'):
172 """Get a multi-band reference catalog by specifying a center and radius.
174 The catalog will be in `numpy.ndarray`, with positions proper-motion
175 corrected to "epoch" (if specified, and if the reference catalog has
176 proper motions); sources cut on a reference selector (if
177 "config.doReferenceSelection = True"); and color-terms applied (if
178 "config.doApplyColorTerms = True").
180 The format of the reference catalog will be of the format:
182 dtype = [('ra', 'np.float64'),
183 ('dec', 'np.float64'),
184 ('refMag', 'np.float32', (len(filterList), )),
185 ('refMagErr', 'np.float32', (len(filterList), ))]
187 Reference magnitudes (AB) and errors will be NaN for non-detections
192 center : `lsst.geom.SpherePoint`
193 Point defining the center of the circular region.
194 radius : `lsst.geom.Angle`
195 Defines the angular radius of the circular region.
196 filterList : `List` [ `str` ]
197 List of camera physicalFilter names to retrieve magnitudes.
198 epoch : `astropy.time.Time`, optional
199 Epoch to which to correct proper motion and parallax
200 (if available), or `None` to not apply such corrections.
204 refCat : `numpy.ndarray`
211 skyCircle = self.
refObjLoader.loadSkyCircle(center, radius,
215 if not skyCircle.refCat.isContiguous():
216 refCat = skyCircle.refCat.copy(deep=
True)
218 refCat = skyCircle.refCat
223 """Format a reference afw table into the final format.
225 This method applies reference selections and color terms as specified
230 refCat : `lsst.afw.table.SourceCatalog`
231 Reference catalog in afw format.
232 filterList : `list` [`str`]
233 List of camera physicalFilter names to apply color terms.
237 refCat : `numpy.ndarray`
240 if self.config.doReferenceSelection:
241 goodSources = self.referenceSelector.selectSources(refCat)
242 selected = goodSources.selected
244 selected = np.ones(len(refCat), dtype=bool)
246 npRefCat = np.zeros(np.sum(selected), dtype=[(
'ra',
'f8'),
248 (
'refMag',
'f4', (len(filterList), )),
249 (
'refMagErr',
'f4', (len(filterList), ))])
251 if npRefCat.size == 0:
258 npRefCat[
'ra'] = np.rad2deg(refCat[
'coord_ra'][selected])
259 npRefCat[
'dec'] = np.rad2deg(refCat[
'coord_dec'][selected])
262 npRefCat[
'refMag'][:, :] = np.nan
263 npRefCat[
'refMagErr'][:, :] = np.nan
265 if self.config.doApplyColorTerms:
269 if fluxField
is None:
273 self.log.debug(
"Applying color terms for filterName='%s'", filterName)
275 colorterm = self.config.colorterms.getColorterm(filterName, refCatName, doRaise=
True)
277 refMag, refMagErr = colorterm.getCorrectedMagnitudes(refCat)
283 good, = np.where((np.nan_to_num(refMag[selected], nan=99.0) < 90.0)
284 & (np.nan_to_num(refMagErr[selected], nan=99.0) < 90.0)
285 & (np.nan_to_num(refMagErr[selected]) > 0.0))
287 npRefCat[
'refMag'][good, i] = refMag[selected][good]
288 npRefCat[
'refMagErr'][good, i] = refMagErr[selected][good]
294 good, = np.where((np.nan_to_num(refCat[fluxField][selected]) > 0.0)
295 & (np.nan_to_num(refCat[fluxField+
'Err'][selected]) > 0.0))
296 refMag = (refCat[fluxField][selected][good]*units.nJy).to_value(units.ABmag)
297 refMagErr = abMagErrFromFluxErr(refCat[fluxField+
'Err'][selected][good],
298 refCat[fluxField][selected][good])
299 npRefCat[
'refMag'][good, i] = refMag
300 npRefCat[
'refMagErr'][good, i] = refMagErr
305 """Determine the flux field names for a reference catalog.
307 This method sets self._fluxFields, self._referenceFilter.
311 center : `lsst.geom.SpherePoint`
312 The center around which to load test sources.
313 filterList : `list` [`str`]
314 List of camera physicalFilter names.
318 foundReferenceFilter =
False
323 configTemp = LoadReferenceObjectsConfig()
324 configIntersection = {k: getattr(self.
refObjLoader.config, k)
326 if (k
in configTemp.keys()
and k !=
"connections")}
328 configIntersection[
'requireProperMotion'] =
False
329 configTemp.update(**configIntersection)
333 for filterName
in filterList:
334 if self.config.refObjLoader.anyFilterMapsToThis
is not None:
335 refFilterName = self.config.refObjLoader.anyFilterMapsToThis
337 refFilterName = self.config.refObjLoader.filterMap.get(filterName)
338 if refFilterName
is None:
342 foundReferenceFilter =
True
345 except RuntimeError
as err:
348 if 'not find flux' in err.args[0]:
357 if not foundReferenceFilter:
358 raise RuntimeError(
"Could not find any valid flux field(s) %s" %
359 (
", ".join(filterList)))
366 for filterName
in filterList:
369 if self.config.refObjLoader.anyFilterMapsToThis
is not None:
370 refFilterName = self.config.refObjLoader.anyFilterMapsToThis
372 refFilterName = self.config.refObjLoader.filterMap.get(filterName)
374 if refFilterName
is not None:
376 fluxField = getRefFluxField(results.schema, filterName=refFilterName)
381 if fluxField
is None:
382 self.log.warning(
'No reference flux field for camera filter %s', filterName)