22 from __future__
import absolute_import, division, print_function
24 __all__ = [
'RefMatchConfig',
'RefMatchTask']
26 from lsst.afw.image.utils
import getDistortedWcs
27 import lsst.afw.geom
as afwGeom
28 import lsst.afw.math
as afwMath
29 import lsst.pex.config
as pexConfig
30 import lsst.pipe.base
as pipeBase
31 from .matchOptimisticB
import MatchOptimisticBTask
32 from .display
import displayAstrometry
33 from .
import makeMatchStatistics
34 from .createMatchMetadata
import createMatchMetadata
38 matcher = pexConfig.ConfigurableField(
39 target=MatchOptimisticBTask,
40 doc=
"reference object/source matcher",
42 matchDistanceSigma = pexConfig.RangeField(
43 doc=
"the maximum match distance is set to " 44 " mean_match_distance + matchDistanceSigma*std_dev_match_distance; " +
45 "ignored if not fitting a WCS",
61 """!Match an input source catalog with objects from a reference catalog 65 ConfigClass = RefMatchConfig
66 _DefaultName =
"calibrationBaseClass" 68 def __init__(self, refObjLoader, schema=None, **kwargs):
69 """!Construct a RefMatchTask 71 @param[in] refObjLoader A reference object loader object 72 @param[in] schema ignored; available for compatibility with an older astrometry task 73 @param[in] kwargs additional keyword arguments for pipe_base Task.\_\_init\_\_ 75 pipeBase.Task.__init__(self, **kwargs)
77 self.makeSubtask(
"matcher")
81 """!Load reference objects overlapping an exposure and match to sources detected on that exposure 83 @param[in] exposure exposure that the sources overlap 84 @param[in] sourceCat catalog of sources detected on the exposure (an lsst.afw.table.SourceCatalog) 86 @return an lsst.pipe.base.Struct with these fields: 87 - refCat reference object catalog of objects that overlap the exposure (with some margin) 88 (an lsst::afw::table::SimpleCatalog) 89 - matches a list of lsst.afw.table.ReferenceMatch 90 - matchMeta metadata needed to unpersist matches (an lsst.daf.base.PropertyList) 92 @note ignores config.matchDistanceSigma 95 debug = lsstDebug.Info(__name__)
103 filterName=expMd.filterName,
107 matchRes = self.matcher.matchObjectsToSources(
108 refCat=loadRes.refCat,
111 refFluxField=loadRes.fluxField,
112 match_tolerance=
None,
117 "Found %d matches with scatter = %0.3f +- %0.3f arcsec; " %
118 (len(matchRes.matches), distStats.distMean.asArcseconds(), distStats.distStdDev.asArcseconds())
122 frame = int(debug.frame)
124 refCat=loadRes.refCat,
126 matches=matchRes.matches,
133 return pipeBase.Struct(
134 refCat=loadRes.refCat,
135 matches=matchRes.matches,
139 def _computeMatchStatsOnSky(self, matchList):
140 """Compute on-sky radial distance statistics for a match list 142 @param[in] matchList list of matches between reference object and sources; 143 the distance field is the only field read and it must be set to distance in radians 145 @return a pipe_base Struct containing these fields: 146 - distMean clipped mean of on-sky radial separation 147 - distStdDev clipped standard deviation of on-sky radial separation 148 - maxMatchDist distMean + self.config.matchDistanceSigma*distStdDev 151 distMean = distStatsInRadians.getValue(afwMath.MEANCLIP)*afwGeom.radians
152 distStdDev = distStatsInRadians.getValue(afwMath.STDEVCLIP)*afwGeom.radians
153 return pipeBase.Struct(
155 distStdDev=distStdDev,
156 maxMatchDist=distMean + self.config.matchDistanceSigma*distStdDev,
159 def _getExposureMetadata(self, exposure):
160 """!Extract metadata from an exposure 162 @return an lsst.pipe.base.Struct containing the following exposure metadata: 163 - bbox: parent bounding box 164 - wcs: WCS (an lsst.afw.image.Wcs) 165 - calib calibration (an lsst.afw.image.Calib), or None if unknown 166 - filterName: name of filter, or None if unknown 168 exposureInfo = exposure.getInfo()
169 filterName = exposureInfo.getFilter().getName()
or None 170 if filterName ==
"_unknown_":
172 return pipeBase.Struct(
173 bbox=exposure.getBBox(),
174 wcs=getDistortedWcs(exposureInfo, log=self.log),
175 calib=exposureInfo.getCalib()
if exposureInfo.hasCalib()
else None,
176 filterName=filterName,
def _computeMatchStatsOnSky(self, matchList)
def __init__(self, refObjLoader, schema=None, kwargs)
Construct a RefMatchTask.
def _getExposureMetadata(self, exposure)
Extract metadata from an exposure.
Match an input source catalog with objects from a reference catalog.
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
def loadAndMatch(self, exposure, sourceCat)
Load reference objects overlapping an exposure and match to sources detected on that exposure...