99 def __init__(self, *, dataIds, refCats, name, **kwargs):
100 pipeBase.Task.__init__(self, **kwargs)
101 refConfig = self.config.refObjLoader
108 if self.config.doReferenceSelection:
109 self.makeSubtask(
'referenceSelector')
115 bboxToSpherePadding=None):
116 """Get a multi-band reference catalog by specifying a bounding box and WCS.
118 The catalog will be in `numpy.ndarray`, with positions proper-motion
119 corrected to "epoch" (if specified, and if the reference catalog has
120 proper motions); sources cut on a reference selector (if
121 "config.doReferenceSelection = True"); and color-terms applied (if
122 "config.doApplyColorTerms = True").
124 The format of the reference catalog will be of the format:
126 dtype = [('ra', 'np.float64'),
127 ('dec', 'np.float64'),
128 ('refMag', 'np.float32', (len(filterList), )),
129 ('refMagErr', 'np.float32', (len(filterList), ))]
131 Reference magnitudes (AB) and errors will be 99 for non-detections
136 bbox : `lsst.geom.Box2I`
137 Box which bounds a region in pixel space.
138 wcs : `lsst.afw.geom.SkyWcs`
139 Wcs object defining the pixel to sky (and reverse) transform for
141 filterList : `List` [ `str` ]
142 List of camera physicalFilter names to retrieve magnitudes.
143 epoch : `astropy.time.Time`, optional
144 Epoch to which to correct proper motion and parallax
145 (if available), or `None` to not apply such corrections.
146 bboxToSpherePadding : `int`, optional
147 Padding to account for translating a set of corners into a
148 spherical (convex) boundary that is certain to encompass the
149 entire area covered by the bbox.
153 refCat : `numpy.ndarray`
158 center = wcs.pixelToSky(bbox.getCenter())
163 bboxToSpherePadding=bboxToSpherePadding)
165 if not skyBox.refCat.isContiguous():
166 refCat = skyBox.refCat.copy(deep=
True)
168 refCat = skyBox.refCat
173 catalogFormat='numpy'):
174 """Get a multi-band reference catalog by specifying a center and radius.
176 The catalog will be in `numpy.ndarray`, with positions proper-motion
177 corrected to "epoch" (if specified, and if the reference catalog has
178 proper motions); sources cut on a reference selector (if
179 "config.doReferenceSelection = True"); and color-terms applied (if
180 "config.doApplyColorTerms = True").
182 The format of the reference catalog will be of the format:
184 dtype = [('ra', 'np.float64'),
185 ('dec', 'np.float64'),
186 ('refMag', 'np.float32', (len(filterList), )),
187 ('refMagErr', 'np.float32', (len(filterList), ))]
189 Reference magnitudes (AB) and errors will be 99 for non-detections
194 center : `lsst.geom.SpherePoint`
195 Point defining the center of the circular region.
196 radius : `lsst.geom.Angle`
197 Defines the angular radius of the circular region.
198 filterList : `List` [ `str` ]
199 List of camera physicalFilter names to retrieve magnitudes.
200 epoch : `astropy.time.Time`, optional
201 Epoch to which to correct proper motion and parallax
202 (if available), or `None` to not apply such corrections.
206 refCat : `numpy.ndarray`
213 skyCircle = self.
refObjLoader.loadSkyCircle(center, radius,
217 if not skyCircle.refCat.isContiguous():
218 refCat = skyCircle.refCat.copy(deep=
True)
220 refCat = skyCircle.refCat
225 """Format a reference afw table into the final format.
227 This method applies reference selections and color terms as specified
232 refCat : `lsst.afw.table.SourceCatalog`
233 Reference catalog in afw format.
234 filterList : `list` [`str`]
235 List of camera physicalFilter names to apply color terms.
239 refCat : `numpy.ndarray`
242 if self.config.doReferenceSelection:
243 goodSources = self.referenceSelector.selectSources(refCat)
244 selected = goodSources.selected
246 selected = np.ones(len(refCat), dtype=bool)
248 npRefCat = np.zeros(np.sum(selected), dtype=[(
'ra',
'f8'),
250 (
'refMag',
'f4', (len(filterList), )),
251 (
'refMagErr',
'f4', (len(filterList), ))])
253 if npRefCat.size == 0:
260 npRefCat[
'ra'] = np.rad2deg(refCat[
'coord_ra'][selected])
261 npRefCat[
'dec'] = np.rad2deg(refCat[
'coord_dec'][selected])
264 npRefCat[
'refMag'][:, :] = 99.0
265 npRefCat[
'refMagErr'][:, :] = 99.0
267 if self.config.doApplyColorTerms:
271 if fluxField
is None:
275 self.log.debug(
"Applying color terms for filterName='%s'", filterName)
277 colorterm = self.config.colorterms.getColorterm(filterName, refCatName, doRaise=
True)
279 refMag, refMagErr = colorterm.getCorrectedMagnitudes(refCat)
285 good, = np.where((np.nan_to_num(refMag[selected], nan=99.0) < 90.0)
286 & (np.nan_to_num(refMagErr[selected], nan=99.0) < 90.0)
287 & (np.nan_to_num(refMagErr[selected]) > 0.0))
289 npRefCat[
'refMag'][good, i] = refMag[selected][good]
290 npRefCat[
'refMagErr'][good, i] = refMagErr[selected][good]
296 good, = np.where((np.nan_to_num(refCat[fluxField][selected]) > 0.0)
297 & (np.nan_to_num(refCat[fluxField+
'Err'][selected]) > 0.0))
298 refMag = (refCat[fluxField][selected][good]*units.nJy).to_value(units.ABmag)
299 refMagErr = abMagErrFromFluxErr(refCat[fluxField+
'Err'][selected][good],
300 refCat[fluxField][selected][good])
301 npRefCat[
'refMag'][good, i] = refMag
302 npRefCat[
'refMagErr'][good, i] = refMagErr
307 """Determine the flux field names for a reference catalog.
309 This method sets self._fluxFields, self._referenceFilter.
313 center : `lsst.geom.SpherePoint`
314 The center around which to load test sources.
315 filterList : `list` [`str`]
316 List of camera physicalFilter names.
320 foundReferenceFilter =
False
325 configTemp = LoadReferenceObjectsConfig()
326 configIntersection = {k: getattr(self.
refObjLoader.config, k)
328 if (k
in configTemp.keys()
and k !=
"connections")}
330 configIntersection[
'requireProperMotion'] =
False
331 configTemp.update(**configIntersection)
335 for filterName
in filterList:
336 if self.config.refObjLoader.anyFilterMapsToThis
is not None:
337 refFilterName = self.config.refObjLoader.anyFilterMapsToThis
339 refFilterName = self.config.refObjLoader.filterMap.get(filterName)
340 if refFilterName
is None:
344 0.05*lsst.geom.degrees,
346 foundReferenceFilter =
True
349 except RuntimeError
as err:
352 if 'not find flux' in err.args[0]:
361 if not foundReferenceFilter:
362 raise RuntimeError(
"Could not find any valid flux field(s) %s" %
363 (
", ".join(filterList)))
370 for filterName
in filterList:
373 if self.config.refObjLoader.anyFilterMapsToThis
is not None:
374 refFilterName = self.config.refObjLoader.anyFilterMapsToThis
376 refFilterName = self.config.refObjLoader.filterMap.get(filterName)
378 if refFilterName
is not None:
380 fluxField = getRefFluxField(results.refCat.schema, filterName=refFilterName)
385 if fluxField
is None:
386 self.log.warning(
'No reference flux field for camera filter %s', filterName)