23 __all__ = [
'RefMatchConfig',
'RefMatchTask']
31 import lsst.pipe.base
as pipeBase
32 from lsst.meas.algorithms
import ScienceSourceSelectorTask, ReferenceSourceSelectorTask
33 from .matchOptimisticB
import MatchOptimisticBTask
34 from .display
import displayAstrometry
35 from .
import makeMatchStatistics
39 matcher = pexConfig.ConfigurableField(
40 target=MatchOptimisticBTask,
41 doc=
"reference object/source matcher",
43 matchDistanceSigma = pexConfig.RangeField(
44 doc=
"the maximum match distance is set to " 45 " mean_match_distance + matchDistanceSigma*std_dev_match_distance; " 46 "ignored if not fitting a WCS",
51 sourceSelection = pexConfig.ConfigurableField(target=ScienceSourceSelectorTask,
52 doc=
"Selection of science sources")
53 referenceSelection = pexConfig.ConfigurableField(target=ReferenceSourceSelectorTask,
54 doc=
"Selection of reference sources")
58 """Match an input source catalog with objects from a reference catalog. 62 refObjLoader : `lsst.meas.algorithms.ReferenceLoader` 63 A reference object loader object 64 schema : `lsst.afw.table.Schema` 65 ignored; available for compatibility with an older astrometry task 67 additional keyword arguments for pipe_base `lsst.pipe.base.Task` 69 ConfigClass = RefMatchConfig
70 _DefaultName =
"calibrationBaseClass" 72 def __init__(self, refObjLoader, schema=None, **kwargs):
73 pipeBase.Task.__init__(self, **kwargs)
75 self.makeSubtask(
"matcher")
76 self.makeSubtask(
"sourceSelection")
77 self.makeSubtask(
"referenceSelection")
81 """Load reference objects overlapping an exposure and match to sources 82 detected on that exposure. 86 exposure : `lsst.afw.image.Exposure` 87 exposure that the sources overlap 88 sourceCat : `lsst.afw.table.SourceCatalog.` 89 catalog of sources detected on the exposure 93 result : `lsst.pipe.base.Struct` 94 Result struct with Components: 96 - ``refCat`` : reference object catalog of objects that overlap the 97 exposure (`lsst.afw.table.SimpleCatalog`) 98 - ``matches`` : Matched sources and references 99 (`list` of `lsst.afw.table.ReferenceMatch`) 100 - ``matchMeta`` : metadata needed to unpersist matches 101 (`lsst.daf.base.PropertyList`) 105 ignores config.matchDistanceSigma 112 sourceSelection = self.sourceSelection.run(sourceCat)
117 filterName=expMd.filterName,
121 refSelection = self.referenceSelection.run(loadRes.refCat)
126 filterName=expMd.filterName,
130 matchRes = self.matcher.matchObjectsToSources(
131 refCat=refSelection.sourceCat,
132 sourceCat=sourceSelection.sourceCat,
134 refFluxField=loadRes.fluxField,
135 match_tolerance=
None,
140 "Found %d matches with scatter = %0.3f +- %0.3f arcsec; " %
141 (len(matchRes.matches), distStats.distMean.asArcseconds(), distStats.distStdDev.asArcseconds())
145 frame = int(debug.frame)
147 refCat=refSelection.sourceCat,
148 sourceCat=sourceSelection.sourceCat,
149 matches=matchRes.matches,
156 return pipeBase.Struct(
157 refCat=loadRes.refCat,
158 refSelection=refSelection,
159 sourceSelection=sourceSelection,
160 matches=matchRes.matches,
164 def _computeMatchStatsOnSky(self, matchList):
165 """Compute on-sky radial distance statistics for a match list 169 matchList : `list` of `lsst.afw.table.ReferenceMatch` 170 list of matches between reference object and sources; 171 the distance field is the only field read and it must be set to distance in radians 175 result : `lsst.pipe.base.Struct` 176 Result struct with components: 178 - ``distMean`` : clipped mean of on-sky radial separation (`float`) 179 - ``distStdDev`` : clipped standard deviation of on-sky radial 181 - ``maxMatchDist`` : distMean + self.config.matchDistanceSigma * 185 distMean = distStatsInRadians.getValue(afwMath.MEANCLIP)*lsst.geom.radians
186 distStdDev = distStatsInRadians.getValue(afwMath.STDEVCLIP)*lsst.geom.radians
187 return pipeBase.Struct(
189 distStdDev=distStdDev,
190 maxMatchDist=distMean + self.config.matchDistanceSigma * distStdDev,
193 def _getExposureMetadata(self, exposure):
194 """Extract metadata from an exposure. 198 exposure : `lsst.afw.image.Exposure` 202 result : `lsst.pipe.base.Struct` 203 Result struct with components: 205 - ``bbox`` : parent bounding box (`lsst.geom.Box2I`) 206 - ``wcs`` : exposure WCS (`lsst.afw.geom.SkyWcs`) 207 - ``calib`` : calibration (`lsst.afw.image.Calib`) 208 - ``filterName`` : name of filter (`str`) 209 - ``epoch`` : date of exposure (`astropy.time.Time`) 212 exposureInfo = exposure.getInfo()
213 filterName = exposureInfo.getFilter().getName()
or None 214 if filterName ==
"_unknown_":
217 if exposure.getInfo().hasVisitInfo():
218 epochTaiMjd = exposure.getInfo().getVisitInfo().getDate().get(system=DateTime.MJD,
220 epoch = astropy.time.Time(epochTaiMjd, scale=
"tai", format=
"mjd")
222 return pipeBase.Struct(
223 bbox=exposure.getBBox(),
224 wcs=exposureInfo.getWcs(),
225 calib=exposureInfo.getCalib()
if exposureInfo.hasCalib()
else None,
226 filterName=filterName,
def _computeMatchStatsOnSky(self, matchList)
def __init__(self, refObjLoader, schema=None, kwargs)
def _getExposureMetadata(self, exposure)
def displayAstrometry(refCat=None, sourceCat=None, distortedCentroidKey=None, bbox=None, exposure=None, matches=None, frame=1, title="", pause=True)
def loadAndMatch(self, exposure, sourceCat)